eoserial: support char + std::list
This commit is contained in:
parent
dc0f995ff4
commit
f7e2a6ea7f
1 changed files with 34 additions and 7 deletions
|
|
@ -88,6 +88,7 @@ Authors:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
# include <vector>
|
# include <vector>
|
||||||
|
# include <list>
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <stdexcept> // std::runtime_error
|
# include <stdexcept> // std::runtime_error
|
||||||
# include <type_traits> // std::is_convertible (C++11)
|
# include <type_traits> // std::is_convertible (C++11)
|
||||||
|
|
@ -157,6 +158,7 @@ namespace eoserial
|
||||||
MKSIMPLE(long)
|
MKSIMPLE(long)
|
||||||
MKSIMPLE(float)
|
MKSIMPLE(float)
|
||||||
MKSIMPLE(double)
|
MKSIMPLE(double)
|
||||||
|
MKSIMPLE(char)
|
||||||
MKSIMPLE(std::string)
|
MKSIMPLE(std::string)
|
||||||
# undef MKSIMPLE
|
# undef MKSIMPLE
|
||||||
|
|
||||||
|
|
@ -173,6 +175,7 @@ namespace eoserial
|
||||||
DSSIMPLE(long);
|
DSSIMPLE(long);
|
||||||
DSSIMPLE(float);
|
DSSIMPLE(float);
|
||||||
DSSIMPLE(double);
|
DSSIMPLE(double);
|
||||||
|
DSSIMPLE(char);
|
||||||
DSSIMPLE(std::string);
|
DSSIMPLE(std::string);
|
||||||
# undef DSSIMPLE
|
# undef DSSIMPLE
|
||||||
|
|
||||||
|
|
@ -182,11 +185,11 @@ namespace eoserial
|
||||||
value.unpack( static_cast<const eoserial::Object*>( json ) );
|
value.unpack( static_cast<const eoserial::Object*>( json ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class V>
|
template<class Container>
|
||||||
eoserial::Entity* makeSimple( const std::vector<V> & v )
|
eoserial::Entity* makeSimpleIterable( const Container & c )
|
||||||
{
|
{
|
||||||
eoserial::Array* array = new eoserial::Array;
|
eoserial::Array* array = new eoserial::Array;
|
||||||
for( auto it = v.begin(), end = v.end();
|
for( auto it = c.begin(), end = c.end();
|
||||||
it != end;
|
it != end;
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
|
|
@ -195,23 +198,47 @@ namespace eoserial
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class V>
|
||||||
|
eoserial::Entity* makeSimple( const std::vector<V> & v )
|
||||||
|
{
|
||||||
|
return makeSimpleIterable( v );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class V>
|
||||||
|
eoserial::Entity* makeSimple( const std::list<V> & l )
|
||||||
|
{
|
||||||
|
return makeSimpleIterable( l );
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void deserializeBase( const eoserial::Entity* json, T & value );
|
void deserializeBase( const eoserial::Entity* json, T & value );
|
||||||
|
|
||||||
template< class T >
|
template< class Container >
|
||||||
void deserializeSimple( const eoserial::Entity* json, std::vector<T> & v )
|
void deserializeSimplePushBack( const eoserial::Entity* json, Container & c )
|
||||||
{
|
{
|
||||||
const eoserial::Array* sArray = static_cast<const eoserial::Array*>(json);
|
const eoserial::Array* sArray = static_cast<const eoserial::Array*>(json);
|
||||||
for( auto it = sArray->begin(), end = sArray->end();
|
for( auto it = sArray->begin(), end = sArray->end();
|
||||||
it != end;
|
it != end;
|
||||||
++it )
|
++it )
|
||||||
{
|
{
|
||||||
T single;
|
typename Container::value_type single;
|
||||||
eoserial::deserializeBase( *it, single );
|
eoserial::deserializeBase( *it, single );
|
||||||
v.push_back( single );
|
c.push_back( single );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
void deserializeSimple( const eoserial::Entity* json, std::vector<T> & v )
|
||||||
|
{
|
||||||
|
deserializeSimplePushBack( json, v );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< class T >
|
||||||
|
void deserializeSimple( const eoserial::Entity* json, std::list<T> & v )
|
||||||
|
{
|
||||||
|
deserializeSimplePushBack( json, v );
|
||||||
|
}
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
void deserializeBase( const eoserial::Entity* json, T & value )
|
void deserializeBase( const eoserial::Entity* json, T & value )
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue