mirror of
https://github.com/boostorg/serialization.git
synced 2026-01-26 07:02:09 +00:00
fixed serialization of optional.hpp to prevent it from calling load_construct ...
This commit is contained in:
@@ -1,4 +1,76 @@
|
||||
#if 0
|
||||
#if 1
|
||||
#include <stdexcept>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/archive/text_oarchive.hpp>
|
||||
#include <boost/archive/text_iarchive.hpp>
|
||||
#include <boost/serialization/optional.hpp>
|
||||
|
||||
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<class Archive>
|
||||
inline void serialize(Archive & ar, Foo& foo, const unsigned int /*version*/)
|
||||
{
|
||||
std::cout << __FUNCTION__ << " called" << std::endl;
|
||||
}
|
||||
|
||||
template<class Archive>
|
||||
inline void save_construct_data(Archive & ar, const Foo* foo, const unsigned int /*version*/)
|
||||
{
|
||||
std::cout << __FUNCTION__ << " called" << std::endl;
|
||||
ar << foo->bar();
|
||||
}
|
||||
|
||||
|
||||
template<class Archive>
|
||||
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<Foo> oldFoo = Foo(10);
|
||||
std::ostringstream outStream;
|
||||
boost::archive::text_oarchive outArchive(outStream);
|
||||
outArchive & oldFoo;
|
||||
|
||||
boost::optional<Foo> 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 <fstream>
|
||||
|
||||
@@ -119,4 +191,4 @@ int main() {
|
||||
oa << boost::serialization::make_nvp( "bob", bob );
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user