diff --git a/CMake/CMakeLists.txt b/CMake/CMakeLists.txt index 91d95edb..b45b5dbb 100644 --- a/CMake/CMakeLists.txt +++ b/CMake/CMakeLists.txt @@ -109,6 +109,7 @@ endif() set(Boost_DEBUG true) set(Boost_DETAILED_FAILURE_MSG true) +set(Boost_FOUND true) find_package(Boost REQUIRED COMPONENTS system filesystem) @@ -122,8 +123,8 @@ if(Boost_FOUND) message(STATUS "Boost libraries prefix is ${Boost_LIB_PREFIX}") message(STATUS "Boost component libraries to be linked are ${Boost_LIBRARIES}") message(STATUS "Boost version found is ${Boost_VERSION}") - include_directories("../include" "${Boost_INCLUDE_DIRS}") - link_directories("${Boost_LIBRARY_DIRS}") + #include_directories("../include" "${Boost_INCLUDE_DIRS}") + #link_directories("${Boost_LIBRARY_DIRS}") else() message(STATUS "Boost NOT Found!") endif() diff --git a/include/boost/serialization/optional.hpp b/include/boost/serialization/optional.hpp index 4024cf5e..0e79ea7f 100644 --- a/include/boost/serialization/optional.hpp +++ b/include/boost/serialization/optional.hpp @@ -19,6 +19,8 @@ #include #include +#include + #include #include #include @@ -63,6 +65,7 @@ void load( ){ bool tflag; ar >> boost::serialization::make_nvp("initialized", tflag); + t.reset(); if (tflag){ boost::serialization::item_version_type item_version(0); boost::archive::library_version_type library_version( @@ -70,14 +73,11 @@ void load( ); if(boost::archive::library_version_type(3) < library_version){ // item_version is handled as an attribute so it doesnt need an NVP - ar >> BOOST_SERIALIZATION_NVP(item_version); + ar >> BOOST_SERIALIZATION_NVP(item_version); } - detail::stack_construct aux(ar, item_version); - ar >> boost::serialization::make_nvp("value", aux.reference()); - t.reset(aux.reference()); - } - else { - t.reset(); + detail::stack_allocate t_new; + ar >> boost::serialization::make_nvp("value", t_new.reference()); + t = boost::move(t_new.reference()); } } diff --git a/test/test_z.cpp b/test/test_z.cpp index bd8aa346..02611375 100644 --- a/test/test_z.cpp +++ b/test/test_z.cpp @@ -1,4 +1,76 @@ -#if 0 +#if 1 +#include +#include +#include + +#include +#include +#include +#include + +struct Foo +{ + Foo(int aBar) : + mBar(aBar) + { + if (mBar > 10) + { + throw std::logic_error("too big bar"); + } + } + int bar() const + { + return mBar; + } +private: + int mBar; +}; + + +namespace boost { +namespace serialization { + +template +inline void serialize(Archive & ar, Foo& foo, const unsigned int /*version*/) +{ + std::cout << __FUNCTION__ << " called" << std::endl; +} + +template +inline void save_construct_data(Archive & ar, const Foo* foo, const unsigned int /*version*/) +{ + std::cout << __FUNCTION__ << " called" << std::endl; + ar << foo->bar(); +} + + +template +inline void load_construct_data(Archive & ar, Foo* foo, const unsigned int /*version*/) +{ + std::cout << __FUNCTION__ << " called" << std::endl; + int bar; + ar >> bar; + ::new(foo) Foo(bar); +} + +} // serialization +} // boost + + +int main() +{ + boost::optional oldFoo = Foo(10); + std::ostringstream outStream; + boost::archive::text_oarchive outArchive(outStream); + outArchive & oldFoo; + + boost::optional newFoo; + std::istringstream inStream(outStream.str()); + boost::archive::text_iarchive inArchive(inStream); + inArchive & newFoo; +} + +#elif 0 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 // test_optional.cpp @@ -63,7 +135,7 @@ int test_main( int /* argc */, char* /* argv */[] ) // EOF -#elseif 0 +#elif 0 #include @@ -119,4 +191,4 @@ int main() { oa << boost::serialization::make_nvp( "bob", bob ); } -#endif \ No newline at end of file +#endif