28 #ifndef _cmnDeSerializer_h
29 #define _cmnDeSerializer_h
47 template <
class _elementType,
bool>
51 static void DeSerializeRaw(std::istream & inputStream, _elementType & data)
throw (std::runtime_error)
53 inputStream.read(reinterpret_cast<char *>(&data),
sizeof(_elementType));
54 if (inputStream.fail()) {
55 std::string message(
"cmnDeSerializeRaw(_elementType): Error occured with std::istream::read, _elementType = ");
56 message +=
typeid(_elementType).name();
63 template <
class _elementType>
67 static void DeSerializeRaw(std::istream & inputStream, _elementType & data)
throw (std::runtime_error)
69 data.DeSerializeRaw(inputStream);
81 template <
class _elementType>
83 throw (std::runtime_error)
86 impl::DeSerializeRaw(inputStream, data);
97 throw (std::runtime_error)
99 unsigned long long int dataToRead;
102 data =
static_cast<size_t>(dataToRead);
104 cmnThrow(
"cmnDeSerializeSizeRaw: received size greater than maximum supported on this configuration");
115 throw (std::runtime_error)
128 std::string::value_type *buffer =
new std::string::value_type[size];
129 inputStream.read(static_cast<char *>(buffer), size *
sizeof(std::string::value_type));
130 data.assign(buffer, size);
132 if (inputStream.fail()) {
133 cmnThrow(
"cmnDeSerializeRaw(std::string): Error occured with std::istream::read");
144 template <
class _elementType>
146 throw (std::runtime_error)
151 for (
size_t i = 0; i < size; i++) {
153 if (inputStream.fail()) {
154 cmnThrow(
"cmnDeSerializeRaw(std::vector<_elementType>): Error occured with std::istream::read");
232 template <
class _elementType>
233 inline void DeSerialize(_elementType &
object,
const bool serializeObject =
true) {
238 this->DeSerializeServices();
240 if (serializeObject) {
241 this->DeSerialize(
object);
244 const const_iterator end = ServicesContainer.end();
245 const const_iterator iterator = ServicesContainer.find(typeId);
246 if (iterator == end) {
247 cmnThrow(
"DeSerialize: Can't find corresponding class information");
250 if (servicesPointerLocal !=
object.
Services()) {
252 << servicesPointerLocal->
GetName() <<
", object class = " <<
object.Services()->GetName()
254 cmnThrow(
"DeSerialize: Object types don't match");
256 if (serializeObject) {
257 object.DeSerializeRaw(this->InputStream);
279 void DeSerializeServices(
void) throw(std::runtime_error);
281 std::istream & InputStream;
284 typedef ServicesContainerType::value_type EntryType;
286 typedef ServicesContainerType::const_iterator const_iterator;
287 typedef ServicesContainerType::iterator iterator;
289 ServicesContainerType ServicesContainer;
297 #endif // _cmnDeSerialize_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Assert macros definitions.
Portability across compilers and operating systems tools.
static void DeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:51
void cmnDeSerializeSizeRaw(std::istream &inputStream, size_t &data)
Definition: cmnDeSerializer.h:96
Definition: cmnDeSerializer.h:48
const std::string & GetName(void) const
size_t size_type
Definition: vctContainerTraits.h:35
Base class for high level objects.
Definition: cmnGenericObject.h:51
Class register definitions and log macros.
virtual const cmnClassServicesBase * Services(void) const =0
Macros to export the symbols of cisstCommon (in a Dll).
Declaration of the class cmnTypeTraits.
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:82
Defines cmnGenericObject.
De-serialization utility class.This class allows to deserialize objects previously serialized using c...
Definition: cmnDeSerializer.h:177
void DeSerialize(_elementType &object, const bool serializeObject=true)
Definition: cmnDeSerializer.h:233
#define CMN_DECLARE_SERVICES(hasDynamicCreation, lod)
Definition: cmnClassRegisterMacros.h:116
#define cmnThrow(a)
Definition: MinimalCmn.h:4
long long int TypeId
Definition: cmnDeSerializer.h:184
#define CMN_LOG_CLASS_RUN_ERROR
Definition: cmnLogger.h:117
Base class for class services.
Definition: cmnClassServicesBase.h:45
Declaration of the template function cmnThrow.
A collection of useful information about the C++ basic types, represented in a generic programming wa...
Definition: cmnTypeTraits.h:155
const int CMN_NO_DYNAMIC_CREATION
Definition: cmnClassRegisterMacros.h:328
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition: cmnClassRegisterMacros.h:202
#define CMN_LOG_ALLOW_DEFAULT
Definition: cmnLogLoD.h:76
static void DeSerializeRaw(std::istream &inputStream, _elementType &data)
Definition: cmnDeSerializer.h:67