mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
Object serialization seems to work
This commit is contained in:
@@ -196,6 +196,7 @@ namespace cereal
|
||||
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(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(std::string & val) { val = itsValueStack.top()->value.GetString(); ++itsValueStack.top(); }
|
||||
|
||||
@@ -392,6 +393,13 @@ namespace cereal
|
||||
{
|
||||
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
|
||||
|
||||
// register archives for polymorphic support
|
||||
|
||||
@@ -43,6 +43,7 @@ namespace cereal
|
||||
}
|
||||
|
||||
//! 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
|
||||
void serialize( Archive &, T * & )
|
||||
{
|
||||
@@ -69,7 +70,7 @@ namespace cereal
|
||||
}
|
||||
}
|
||||
|
||||
//! Serialization for arrays
|
||||
//! Serialization for C style arrays
|
||||
template <class Archive, class T> inline
|
||||
typename std::enable_if<std::is_array<T>::value, void>::type
|
||||
serialize(Archive & ar, T & array)
|
||||
|
||||
@@ -225,8 +225,13 @@ int main()
|
||||
std::ofstream os("file.json");
|
||||
cereal::JSONOutputArchive oar( os );
|
||||
|
||||
Fixture f1;
|
||||
|
||||
int x = 10;
|
||||
double y = 99;
|
||||
|
||||
oar(CEREAL_NVP(f1));
|
||||
|
||||
oar(CEREAL_NVP(x));
|
||||
oar(CEREAL_NVP(y));
|
||||
}
|
||||
@@ -241,12 +246,17 @@ int main()
|
||||
std::ifstream is("file.json");
|
||||
cereal::JSONInputArchive iar( is );
|
||||
|
||||
Fixture f1;
|
||||
|
||||
int x;
|
||||
double y;
|
||||
iar(CEREAL_NVP(f1));
|
||||
iar(CEREAL_NVP(x));
|
||||
iar(CEREAL_NVP(y));
|
||||
|
||||
std::cout << x << " " << y << std::endl;
|
||||
|
||||
std::cout << f1.f1.a << std::endl;
|
||||
}
|
||||
|
||||
//{
|
||||
|
||||
Reference in New Issue
Block a user