mirror of
https://github.com/USCiLab/cereal.git
synced 2025-10-18 01:45:52 +02:00
added some comments to xml for loadvalue, everything running fine through valgrind now
This commit is contained in:
@@ -238,7 +238,7 @@ namespace cereal
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
itsData.push_back('\0'); // rapidxml will do terrible things without this
|
itsData.push_back('\0'); // rapidxml will do terrible things without the data being null terminated
|
||||||
itsXML.parse<rapidxml::parse_no_data_nodes | rapidxml::parse_declaration_node>( reinterpret_cast<char *>( itsData.data() ) );
|
itsXML.parse<rapidxml::parse_no_data_nodes | rapidxml::parse_declaration_node>( reinterpret_cast<char *>( itsData.data() ) );
|
||||||
}
|
}
|
||||||
catch( rapidxml::parse_error const & e )
|
catch( rapidxml::parse_error const & e )
|
||||||
@@ -284,6 +284,7 @@ namespace cereal
|
|||||||
is >> value;
|
is >> value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as an unsigned long
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
typename std::enable_if<std::is_unsigned<T>::value && !std::is_same<T, bool>::value && sizeof(T) < sizeof(long long), void>::type
|
typename std::enable_if<std::is_unsigned<T>::value && !std::is_same<T, bool>::value && sizeof(T) < sizeof(long long), void>::type
|
||||||
loadValue( T & value )
|
loadValue( T & value )
|
||||||
@@ -291,6 +292,7 @@ namespace cereal
|
|||||||
value = std::stoul( itsNodes.top().node->value() );
|
value = std::stoul( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as an unsigned long long
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
typename std::enable_if<std::is_unsigned<T>::value && !std::is_same<T, bool>::value && sizeof(T) >= sizeof(long long), void>::type
|
typename std::enable_if<std::is_unsigned<T>::value && !std::is_same<T, bool>::value && sizeof(T) >= sizeof(long long), void>::type
|
||||||
loadValue( T & value )
|
loadValue( T & value )
|
||||||
@@ -298,6 +300,7 @@ namespace cereal
|
|||||||
value = std::stoull( itsNodes.top().node->value() );
|
value = std::stoull( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as an int
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
typename std::enable_if<std::is_signed<T>::value && sizeof(T) <= sizeof(int), void>::type
|
typename std::enable_if<std::is_signed<T>::value && sizeof(T) <= sizeof(int), void>::type
|
||||||
loadValue( T & value )
|
loadValue( T & value )
|
||||||
@@ -305,6 +308,7 @@ namespace cereal
|
|||||||
value = std::stoi( itsNodes.top().node->value() );
|
value = std::stoi( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as a long
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
typename std::enable_if<std::is_signed<T>::value && (sizeof(T) > sizeof(int)) && (sizeof(T) <= sizeof(long)), void>::type
|
typename std::enable_if<std::is_signed<T>::value && (sizeof(T) > sizeof(int)) && (sizeof(T) <= sizeof(long)), void>::type
|
||||||
loadValue( T & value )
|
loadValue( T & value )
|
||||||
@@ -312,6 +316,7 @@ namespace cereal
|
|||||||
value = std::stol( itsNodes.top().node->value() );
|
value = std::stol( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as a long long
|
||||||
template <class T> inline
|
template <class T> inline
|
||||||
typename std::enable_if<std::is_signed<T>::value && (sizeof(T) > sizeof(long)) && (sizeof(T) <= sizeof(long long)), void>::type
|
typename std::enable_if<std::is_signed<T>::value && (sizeof(T) > sizeof(long)) && (sizeof(T) <= sizeof(long long)), void>::type
|
||||||
loadValue( T & value )
|
loadValue( T & value )
|
||||||
@@ -319,16 +324,24 @@ namespace cereal
|
|||||||
value = std::stoll( itsNodes.top().node->value() );
|
value = std::stoll( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as a float
|
||||||
void loadValue( float & value )
|
void loadValue( float & value )
|
||||||
{
|
{
|
||||||
value = std::stof( itsNodes.top().node->value() );
|
value = std::stof( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as a double
|
||||||
void loadValue( double & value )
|
void loadValue( double & value )
|
||||||
{
|
{
|
||||||
value = std::stod( itsNodes.top().node->value() );
|
value = std::stod( itsNodes.top().node->value() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Loads a type best represented as a long double
|
||||||
|
void loadValue( long double & value )
|
||||||
|
{
|
||||||
|
value = std::stold( itsNodes.top().node->value() );
|
||||||
|
}
|
||||||
|
|
||||||
//! Loads a string from the current node
|
//! Loads a string from the current node
|
||||||
template<class CharT, class Traits, class Alloc> inline
|
template<class CharT, class Traits, class Alloc> inline
|
||||||
void loadValue( std::basic_string<CharT, Traits, Alloc> & str )
|
void loadValue( std::basic_string<CharT, Traits, Alloc> & str )
|
||||||
|
|||||||
59
sandbox.cpp
59
sandbox.cpp
@@ -288,38 +288,36 @@ int main()
|
|||||||
e_out.t4 = {4};
|
e_out.t4 = {4};
|
||||||
e_out.s = "Hello, World!";
|
e_out.s = "Hello, World!";
|
||||||
|
|
||||||
//Test2 t2 = {22};
|
Test2 t2 = {22};
|
||||||
|
|
||||||
//{
|
|
||||||
// std::ofstream os("out.txt");
|
|
||||||
// cereal::BinaryOutputArchive archive(os);
|
|
||||||
// archive(CEREAL_NVP(e_out));
|
|
||||||
// archive(t2);
|
|
||||||
//}
|
|
||||||
|
|
||||||
//Everything e_in;
|
|
||||||
|
|
||||||
//{
|
|
||||||
// std::ifstream is("out.txt");
|
|
||||||
// cereal::BinaryInputArchive archive(is);
|
|
||||||
// archive(CEREAL_NVP(e_in));
|
|
||||||
// archive(t2);
|
|
||||||
// std::remove("out.txt");
|
|
||||||
//}
|
|
||||||
|
|
||||||
//assert(e_in == e_out);
|
|
||||||
|
|
||||||
//{
|
|
||||||
// cereal::BinaryOutputArchive archive(std::cout);
|
|
||||||
// int xxx[] = {-1, 95, 3};
|
|
||||||
// archive( xxx );
|
|
||||||
|
|
||||||
// cereal::XMLOutputArchive archive2(std::cout);
|
|
||||||
// archive2( xxx );
|
|
||||||
//}
|
|
||||||
|
|
||||||
for( int i = 0; i < 10; ++i )
|
|
||||||
{
|
{
|
||||||
|
std::ofstream os("out.txt");
|
||||||
|
cereal::BinaryOutputArchive archive(os);
|
||||||
|
archive(CEREAL_NVP(e_out));
|
||||||
|
archive(t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
Everything e_in;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ifstream is("out.txt");
|
||||||
|
cereal::BinaryInputArchive archive(is);
|
||||||
|
archive(CEREAL_NVP(e_in));
|
||||||
|
archive(t2);
|
||||||
|
std::remove("out.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(e_in == e_out);
|
||||||
|
|
||||||
|
{
|
||||||
|
cereal::BinaryOutputArchive archive(std::cout);
|
||||||
|
int xxx[] = {-1, 95, 3};
|
||||||
|
archive( xxx );
|
||||||
|
|
||||||
|
cereal::XMLOutputArchive archive2(std::cout);
|
||||||
|
archive2( xxx );
|
||||||
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
std::ofstream os("out.xml");
|
std::ofstream os("out.xml");
|
||||||
cereal::XMLOutputArchive oar( os );
|
cereal::XMLOutputArchive oar( os );
|
||||||
@@ -459,7 +457,6 @@ int main()
|
|||||||
iar( d3 );
|
iar( d3 );
|
||||||
assert( ((Derived*)d3.get())->x == 6 && ((Derived*)d3.get())->y == 5 );
|
assert( ((Derived*)d3.get())->x == 6 && ((Derived*)d3.get())->y == 5 );
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -214,8 +214,6 @@ void test_pod()
|
|||||||
float const o_float = random_value<float>(gen);
|
float const o_float = random_value<float>(gen);
|
||||||
double const o_double = random_value<double>(gen);
|
double const o_double = random_value<double>(gen);
|
||||||
|
|
||||||
std::cerr << i << std::endl;
|
|
||||||
|
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
{
|
{
|
||||||
OArchive oar(os);
|
OArchive oar(os);
|
||||||
|
|||||||
Reference in New Issue
Block a user