Object serialization seems to work

This commit is contained in:
Randolph Voorhies
2013-07-08 15:14:56 -07:00
parent f0216012be
commit 4631cac259
3 changed files with 20 additions and 1 deletions

View File

@@ -196,6 +196,7 @@ namespace cereal
void loadValue(unsigned & val) { val = itsValueStack.top()->value.GetUint(); ++itsValueStack.top(); } void loadValue(unsigned & val) { val = itsValueStack.top()->value.GetUint(); ++itsValueStack.top(); }
void loadValue(int64_t & val) { val = itsValueStack.top()->value.GetInt64(); ++itsValueStack.top(); } void loadValue(int64_t & val) { val = itsValueStack.top()->value.GetInt64(); ++itsValueStack.top(); }
void loadValue(uint64_t & val) { val = itsValueStack.top()->value.GetUint64(); ++itsValueStack.top(); } void loadValue(uint64_t & val) { val = itsValueStack.top()->value.GetUint64(); ++itsValueStack.top(); }
void loadValue(float & val) { val = itsValueStack.top()->value.GetDouble(); ++itsValueStack.top(); }
void loadValue(double & val) { val = itsValueStack.top()->value.GetDouble(); ++itsValueStack.top(); } void loadValue(double & val) { val = itsValueStack.top()->value.GetDouble(); ++itsValueStack.top(); }
void loadValue(std::string & val) { val = itsValueStack.top()->value.GetString(); ++itsValueStack.top(); } void loadValue(std::string & val) { val = itsValueStack.top()->value.GetString(); ++itsValueStack.top(); }
@@ -392,6 +393,13 @@ namespace cereal
{ {
ar.saveValue( str ); ar.saveValue( str );
} }
//! loading string from JSON
template<class CharT, class Traits, class Alloc> inline
void load(JSONInputArchive & ar, std::basic_string<CharT, Traits, Alloc> & str)
{
ar.loadValue( str );
}
} // namespace cereal } // namespace cereal
// register archives for polymorphic support // register archives for polymorphic support

View File

@@ -43,6 +43,7 @@ namespace cereal
} }
//! Serialization for raw pointers //! Serialization for raw pointers
/*! This exists only to throw a static_assert to let users know we don't support raw pointers. */
template <class Archive, class T> inline template <class Archive, class T> inline
void serialize( Archive &, T * & ) void serialize( Archive &, T * & )
{ {
@@ -69,7 +70,7 @@ namespace cereal
} }
} }
//! Serialization for arrays //! Serialization for C style arrays
template <class Archive, class T> inline template <class Archive, class T> inline
typename std::enable_if<std::is_array<T>::value, void>::type typename std::enable_if<std::is_array<T>::value, void>::type
serialize(Archive & ar, T & array) serialize(Archive & ar, T & array)

View File

@@ -225,8 +225,13 @@ int main()
std::ofstream os("file.json"); std::ofstream os("file.json");
cereal::JSONOutputArchive oar( os ); cereal::JSONOutputArchive oar( os );
Fixture f1;
int x = 10; int x = 10;
double y = 99; double y = 99;
oar(CEREAL_NVP(f1));
oar(CEREAL_NVP(x)); oar(CEREAL_NVP(x));
oar(CEREAL_NVP(y)); oar(CEREAL_NVP(y));
} }
@@ -241,12 +246,17 @@ int main()
std::ifstream is("file.json"); std::ifstream is("file.json");
cereal::JSONInputArchive iar( is ); cereal::JSONInputArchive iar( is );
Fixture f1;
int x; int x;
double y; double y;
iar(CEREAL_NVP(f1));
iar(CEREAL_NVP(x)); iar(CEREAL_NVP(x));
iar(CEREAL_NVP(y)); iar(CEREAL_NVP(y));
std::cout << x << " " << y << std::endl; std::cout << x << " " << y << std::endl;
std::cout << f1.f1.a << std::endl;
} }
//{ //{