Documentation of serialization, utils/eoTimer and eoPopEvalFunc.

This commit is contained in:
Benjamin Bouvier 2012-07-12 13:56:54 +02:00
commit 60fff427fe
18 changed files with 853 additions and 415 deletions

View file

@ -1,38 +1,58 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# include "Array.h"
namespace eoserial
{
std::ostream& Array::print( std::ostream& out ) const
{
out << "[";
bool first = true;
for (ArrayChildren::const_iterator it = begin(),
end = this->end();
it != end;
++it)
std::ostream& Array::print( std::ostream& out ) const
{
if ( first )
out << "[";
bool first = true;
for (ArrayChildren::const_iterator it = begin(),
end = this->end();
it != end;
++it)
{
first = false;
} else {
out << ", ";
if ( first )
{
first = false;
} else {
out << ", ";
}
(*it)->print( out );
}
(*it)->print( out );
out << "]\n";
return out;
}
out << "]\n";
return out;
}
Array::~Array()
{
for (ArrayChildren::iterator it = begin(),
end = this->end();
it != end;
++it)
Array::~Array()
{
delete *it;
for (ArrayChildren::iterator it = begin(),
end = this->end();
it != end;
++it)
{
delete *it;
}
}
}
} // namespace eoserial

View file

@ -1,148 +1,169 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_ARRAY_H__
# define __EOSERIAL_ARRAY_H__
# include <vector>
# include <iostream>
# include "Entity.h"
# include "Serializable.h"
# include "Object.h"
# include "String.h"
namespace eoserial
{
// Forward declaration for below declarations.
class Array;
/*
* Declarations of functions present in Utils.h
* These are put here to avoid instead of including the file Utils.h, which would
* cause a circular inclusion.
*/
template< class T >
void unpack( const Array & array, unsigned int index, T & value );
void unpackObject( const Array & array, unsigned int index, Persistent & value );
template< class Container, template<class> class UnpackAlgorithm >
void unpackArray( const Array & array, unsigned int index, Container & container );
/**
* @brief Represents a JSON array.
*
* Wrapper for an array, so as to be used as a JSON object.
*/
class Array : public eoserial::Entity, public std::vector< eoserial::Entity* >
{
protected:
typedef std::vector< eoserial::Entity* > ArrayChildren;
public:
/**
* @brief Adds the serializable object as a JSON object.
* @param obj Object which implemnets JsonSerializable.
*/
void push_back( const eoserial::Printable* obj )
{
ArrayChildren::push_back( obj->pack() );
}
/**
* @brief Proxy for vector::push_back.
*/
void push_back( eoserial::Entity* json )
{
ArrayChildren::push_back( json );
}
/**
* @brief Prints the JSON array into the given stream.
* @param out The stream
*/
virtual std::ostream& print( std::ostream& out ) const;
/**
* @brief Dtor
*/
~Array();
// Forward declaration for below declarations.
class Array;
/*
* The following parts allows the user to automatically deserialize an eoserial::Array into a
* standard container, by giving the algorithm which will be used to deserialize contained entities.
* Declarations of functions present in Utils.h
* These are put here to avoid instead of including the file Utils.h, which would
* cause a circular inclusion.
*/
template< class T >
void unpack( const Array & array, unsigned int index, T & value );
void unpackObject( const Array & array, unsigned int index, Persistent & value );
template< class Container, template<class> class UnpackAlgorithm >
void unpackArray( const Array & array, unsigned int index, Container & container );
/**
* @brief Functor which determines how to retrieve the real value contained in a eoserial::Entity at
* a given place.
* @brief Represents a JSON array.
*
* It will be applied for each contained variable in the array.
* Wrapper for an array, so as to be used as a JSON object.
*
* @ingroup Serialization
*/
template<class Container>
struct BaseAlgorithm
class Array : public eoserial::Entity, public std::vector< eoserial::Entity* >
{
/**
* @brief Main operator.
*
* @param array The eoserial::Array from which we're reading.
* @param i The index of the contained value.
* @param container The standard (STL) container in which we'll push back the read value.
*/
virtual void operator()( const eoserial::Array& array, unsigned int i, Container & container ) const = 0;
protected:
typedef std::vector< eoserial::Entity* > ArrayChildren;
public:
/**
* @brief Adds the serializable object as a JSON object.
* @param obj Object which implemnets JsonSerializable.
*/
void push_back( const eoserial::Printable* obj )
{
ArrayChildren::push_back( obj->pack() );
}
/**
* @brief Proxy for vector::push_back.
*/
void push_back( eoserial::Entity* json )
{
ArrayChildren::push_back( json );
}
/**
* @brief Prints the JSON array into the given stream.
* @param out The stream
*/
virtual std::ostream& print( std::ostream& out ) const;
/**
* @brief Dtor
*/
~Array();
/*
* The following parts allows the user to automatically deserialize an eoserial::Array into a
* standard container, by giving the algorithm which will be used to deserialize contained entities.
*/
/**
* @brief Functor which determines how to retrieve the real value contained in a eoserial::Entity at
* a given place.
*
* It will be applied for each contained variable in the array.
*/
template<class Container>
struct BaseAlgorithm
{
/**
* @brief Main operator.
*
* @param array The eoserial::Array from which we're reading.
* @param i The index of the contained value.
* @param container The standard (STL) container in which we'll push back the read value.
*/
virtual void operator()( const eoserial::Array& array, unsigned int i, Container & container ) const = 0;
};
/**
* @brief BaseAlgorithm for retrieving primitive variables.
*
* This one should be used to retrieve primitive (and types which implement operator>>) variables, for instance
* int, double, std::string, etc...
*/
template<typename C>
struct UnpackAlgorithm : public BaseAlgorithm<C>
{
void operator()( const eoserial::Array& array, unsigned int i, C & container ) const
{
typename C::value_type t;
unpack( array, i, t );
container.push_back( t );
}
};
/**
* @brief BaseAlgorithm for retrieving eoserial::Persistent objects.
*
* This one should be used to retrieve objects which implement eoserial::Persistent.
*/
template<typename C>
struct UnpackObjectAlgorithm : public BaseAlgorithm<C>
{
void operator()( const eoserial::Array& array, unsigned int i, C & container ) const
{
typename C::value_type t;
unpackObject( array, i, t );
container.push_back( t );
}
};
/**
* @brief General algorithm for array deserialization.
*
* Applies the BaseAlgorithm to each contained variable in the eoserial::Array.
*/
template<class Container, template<class T> class UnpackAlgorithm>
inline void deserialize( Container & array )
{
UnpackAlgorithm< Container > algo;
for( unsigned int i = 0, size = this->size();
i < size;
++i)
{
algo( *this, i, array );
}
}
};
/**
* @brief BaseAlgorithm for retrieving primitive variables.
*
* This one should be used to retrieve primitive (and types which implement operator>>) variables, for instance
* int, double, std::string, etc...
*/
template<typename C>
struct UnpackAlgorithm : public BaseAlgorithm<C>
{
void operator()( const eoserial::Array& array, unsigned int i, C & container ) const
{
typename C::value_type t;
unpack( array, i, t );
container.push_back( t );
}
};
/**
* @brief BaseAlgorithm for retrieving eoserial::Persistent objects.
*
* This one should be used to retrieve objects which implement eoserial::Persistent.
*/
template<typename C>
struct UnpackObjectAlgorithm : public BaseAlgorithm<C>
{
void operator()( const eoserial::Array& array, unsigned int i, C & container ) const
{
typename C::value_type t;
unpackObject( array, i, t );
container.push_back( t );
}
};
/**
* @brief General algorithm for array deserialization.
*
* Applies the BaseAlgorithm to each contained variable in the eoserial::Array.
*/
template<class Container, template<class T> class UnpackAlgorithm>
inline void deserialize( Container & array )
{
UnpackAlgorithm< Container > algo;
for( unsigned int i = 0, size = this->size();
i < size;
++i)
{
algo( *this, i, array );
}
}
};
} // namespace eoserial
# endif // __EOSERIAL_ARRAY_H__

View file

@ -1,9 +1,42 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_ENTITY_H__
# define __EOSERIAL_ENTITY_H__
# include <iostream>
# include <sstream>
# include <iostream> // ostream
/**
* @brief Contains all the necessary entities to serialize eo objects into JSON objects.
*
* Allows serialization from user objects into JSON objects, if they implement the interface
* eoserial::Serializable or eoserial::Persistent. The following user objects can be serialized:
* - primitive types (int, std::string, ...), in particular every type that can be written into a
* std::stringstream.
* - objects which implement eoserial::Serializable.
* - array of serializable things (primitive or serializable objects).
*
* @ingroup Utilities
* @defgroup Serialization Serialization helpers
*/
namespace eoserial
{
@ -12,6 +45,8 @@ namespace eoserial
*
* This class represents a JSON entity, which can be JSON objects,
* strings or arrays. It is the base class for the JSON hierarchy.
*
* @ingroup Serialization
*/
class Entity
{

View file

@ -1,40 +1,60 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# include "Object.h"
using namespace eoserial;
namespace eoserial
{
std::ostream& Object::print( std::ostream& out ) const
{
out << '{';
bool first = true;
for(JsonValues::const_iterator it = begin(), end = this->end();
it != end;
++it)
std::ostream& Object::print( std::ostream& out ) const
{
if ( first )
out << '{';
bool first = true;
for(JsonValues::const_iterator it = begin(), end = this->end();
it != end;
++it)
{
first = false;
} else {
out << ", ";
}
if ( first )
{
first = false;
} else {
out << ", ";
}
out << '"' << it->first << "\":"; // key
it->second->print( out ); // value
out << '"' << it->first << "\":"; // key
it->second->print( out ); // value
}
out << "}\n";
return out;
}
Object::~Object()
{
for(JsonValues::iterator it = begin(), end = this->end();
it != end;
++it)
{
delete it->second;
}
out << "}\n";
return out;
}
Object::~Object()
{
for(JsonValues::iterator it = begin(), end = this->end();
it != end;
++it)
{
delete it->second;
}
}
} // namespace eoserial

View file

@ -1,66 +1,87 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_OBJECT_H__
# define __EOSERIAL_OBJECT_H__
# include <map>
# include <string>
# include <sstream>
# include "Entity.h"
# include "Serializable.h"
namespace eoserial
{
/**
* @brief JSON Object
*
* This class represents a JSON object, which is basically a dictionnary
* of keys (strings) and values (JSON entities).
*/
class Object : public eoserial::Entity, public std::map< std::string, eoserial::Entity* >
{
public:
typedef std::map<std::string, eoserial::Entity*> JsonValues;
/**
* @brief Adds a pair into the JSON object.
* @param key The key associated with the eoserial object
* @param eoserial The JSON object as created with framework.
* @brief JSON Object
*
* This class represents a JSON object, which is basically a dictionnary
* of keys (strings) and values (JSON entities).
*
* @ingroup Serialization
*/
void add( const std::string& key, eoserial::Entity* json )
class Object : public eoserial::Entity, public std::map< std::string, eoserial::Entity* >
{
(*this)[ key ] = json;
}
public:
typedef std::map<std::string, eoserial::Entity*> JsonValues;
/**
* @brief Adds a pair into the JSON object.
* @param key The key associated with the eoserial object
* @param obj A JSON-serializable object
*/
void add( const std::string& key, const eoserial::Printable* obj )
{
(*this)[ key ] = obj->pack();
}
/**
* @brief Adds a pair into the JSON object.
* @param key The key associated with the eoserial object
* @param eoserial The JSON object as created with framework.
*/
void add( const std::string& key, eoserial::Entity* json )
{
(*this)[ key ] = json;
}
/**
* @brief Deserializes a Serializable class instance from this JSON object.
* @param obj The object we want to rebuild.
*/
void deserialize( eoserial::Persistent & obj )
{
obj.unpack( this );
}
/**
* @brief Adds a pair into the JSON object.
* @param key The key associated with the eoserial object
* @param obj A JSON-serializable object
*/
void add( const std::string& key, const eoserial::Printable* obj )
{
(*this)[ key ] = obj->pack();
}
/**
* @brief Dtor
*/
~Object();
/**
* @brief Deserializes a Serializable class instance from this JSON object.
* @param obj The object we want to rebuild.
*/
void deserialize( eoserial::Persistent & obj )
{
obj.unpack( this );
}
/**
* @brief Prints the content of a JSON object into a stream.
*/
virtual std::ostream& print( std::ostream& out ) const;
};
/**
* @brief Dtor
*/
~Object();
/**
* @brief Prints the content of a JSON object into a stream.
*/
virtual std::ostream& print( std::ostream& out ) const;
};
} // namespace eoserial
# endif // __EOSERIAL_OBJECT_H__

View file

@ -1,7 +1,25 @@
# include <map>
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# include <string>
# include <sstream>
# include <vector>
# include "Parser.h"

View file

@ -1,3 +1,24 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_PARSER_H__
# define __EOSERIAL_PARSER_H__
@ -6,6 +27,8 @@
# include "Object.h"
/**
* @file Parser.h
*
* This file contains a tiny JSON parser used in DAE. This parser just handles
* a subset of JSON grammar, with the following restrictions :
* - all strings must be surrounded by double quotes.
@ -26,6 +49,8 @@ namespace eoserial
* This parser does just retrieve values and does NOT check the structure of
* the input. This implies that if the input is not correct, the result is undefined
* and can result to a failure on execution.
*
* @ingroup Serialization
*/
class Parser
{

View file

@ -1,43 +1,65 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_SERIALIZABLE_H__
# define __EOSERIAL_SERIALIZABLE_H__
# include <string>
namespace eoserial
{
class Object; // to avoid recursive inclusion with JsonObject
class Object; // to avoid recursive inclusion with JsonObject
/**
* @brief Interface showing that object can be written to a eoserial type
* (currently JSON).
*/
class Printable
{
public:
/**
* @brief Serializes the object to JSON format.
* @return A JSON object created with new.
* @brief Interface showing that object can be written to a eoserial type
* (currently JSON).
*
* @ingroup Serialization
*/
virtual eoserial::Object* pack() const = 0;
};
class Printable
{
public:
/**
* @brief Serializes the object to JSON format.
* @return A JSON object created with new.
*/
virtual eoserial::Object* pack() const = 0;
};
/**
* @brief Interface showing that object can be eoserialized (written and read
* from an input).
*
* Note : Persistent objects should have a default non-arguments constructor.
*/
class Persistent : public Printable
{
public:
/**
* @brief Loads class fields from a JSON object.
* @param json A JSON object. Programmer doesn't have to delete it, it
* is automatically done.
* @brief Interface showing that object can be eoserialized (written and read
* from an input).
*
* Note : Persistent objects should have a default non-arguments constructor.
*
* @ingroup Serialization
*/
virtual void unpack(const eoserial::Object* json) = 0;
};
class Persistent : public Printable
{
public:
/**
* @brief Loads class fields from a JSON object.
* @param json A JSON object. Programmer doesn't have to delete it, it
* is automatically done.
*/
virtual void unpack(const eoserial::Object* json) = 0;
};
} // namespace eoserial

View file

@ -1,3 +1,24 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# include "String.h"
namespace eoserial

View file

@ -1,3 +1,24 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_STRING_H__
# define __EOSERIAL_STRING_H__
@ -9,72 +30,73 @@
namespace eoserial
{
/**
* @brief JSON String
*
* Wrapper for string, so as to be used as a JSON object.
*
* @ingroup Serialization
*/
class String : public eoserial::Entity, public std::string
{
public:
/**
* @brief JSON String
*
* Wrapper for string, so as to be used as a JSON object.
*/
class String : public eoserial::Entity, public std::string
{
public:
/**
* @brief Default ctor.
* @param str The string we want to wrap.
*/
String( const std::string& str ) : std::string( str ) {}
/**
* @brief Default ctor.
* @param str The string we want to wrap.
*/
String( const std::string& str ) : std::string( str ) {}
/**
* @brief Ctor used only when parsing.
*/
String( ) {}
/**
* @brief Ctor used only on parsing.
*/
String( ) {}
/**
* @brief Prints out the string.
*/
virtual std::ostream& print( std::ostream& out ) const;
/**
* @brief Prints out the string.
*/
virtual std::ostream& print( std::ostream& out ) const;
/**
* @brief Deserializes the current String into a given primitive type value.
* @param value The value in which we're writing.
*/
template<class T>
inline void deserialize( T & value );
/**
* @brief Deserializes the current String into a given primitive type value.
* @param value The value in which we're writing.
*/
template<class T>
inline void deserialize( T & value );
protected:
// Copy and reaffectation are forbidden
explicit String( const String& _ );
String& operator=( const String& _ );
};
protected:
// Copy and reaffectation are forbidden
explicit String( const String& _ );
String& operator=( const String& _ );
};
/**
* @brief Casts a eoserial::String into a primitive value, or in a type which at
* least overload operator>>.
*
* @param value A reference to the variable we're writing into.
*
* It's not necessary to specify the variable type, which can be infered by compiler when
* invoking.
*/
template<class T>
inline void String::deserialize( T & value )
{
std::stringstream ss;
ss.precision(std::numeric_limits<double>::digits10 + 1);
ss << *this;
ss >> value;
}
/**
* @brief Casts a eoserial::String into a primitive value, or in a type which at
* least overload operator>>.
*
* @param value A reference to the variable we're writing into.
*
* It's not necessary to specify the variable type, which can be infered by compiler when
* invoking.
*/
template<class T>
inline void String::deserialize( T & value )
{
std::stringstream ss;
ss.precision(std::numeric_limits<double>::digits10 + 1);
ss << *this;
ss >> value;
}
/**
* @brief Specialization for strings, which don't need to be converted through
* a stringstream.
*/
template<>
inline void String::deserialize( std::string & value )
{
value = *this;
}
/**
* @brief Specialization for strings, which don't need to be converted through
* a stringstream.
*/
template<>
inline void String::deserialize( std::string & value )
{
value = *this;
}
} // namespace eoserial

View file

@ -1,3 +1,24 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_UTILS_H__
# define __EOSERIAL_UTILS_H__
@ -7,7 +28,7 @@
namespace eoserial
{
/*****************************
/* ***************************
* DESERIALIZATION FUNCTIONS *
*****************************
These functions are useful for casting eoserial::objects into simple, primitive
@ -54,7 +75,7 @@ namespace eoserial
static_cast<Array*>( array[ index ] )->deserialize< Container, UnpackAlgorithm >( container );
}
/*******************************
/* *****************************
*** SERIALIZATION FUNCTIONS ***
*******************************
These functions are useful for casting classic objects and

View file

@ -1,3 +1,24 @@
/*
(c) Thales group, 2012
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation;
version 2 of the License.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Contact: http://eodev.sourceforge.net
Authors:
Benjamin Bouvier <benjamin.bouvier@gmail.com>
*/
# ifndef __EOSERIAL_HEADERS__
# define __EOSERIAL_HEADERS__