28#ifndef _cmnDeSerializer_h
29#define _cmnDeSerializer_h
47template <
class _elementType,
bool>
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();
63template <
class _elementType>
69 data.DeSerializeRaw(inputStream);
81template <
class _elementType>
86 impl::DeSerializeRaw(inputStream, data);
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");
117 std::string::size_type
size = 0;
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");
144template <
class _elementType>
148 typename std::vector<_elementType>::size_type
size = 0;
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) {
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)
CISST_THROW(std::runtime_error);
281 std::istream & InputStream;
283 typedef std::map<TypeId, cmnClassServicesBase *> ServicesContainerType;
284 typedef ServicesContainerType::value_type EntryType;
287 typedef ServicesContainerType::iterator
iterator;
289 ServicesContainerType ServicesContainer;
Base class for class services.
Definition cmnClassServicesBase.h:46
const std::string & GetName(void) const
static void DeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:67
Definition cmnDeSerializer.h:49
static void DeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:51
De-serialization utility class.
Definition cmnDeSerializer.h:177
cmnGenericObject * DeSerialize(const bool serializeObject=true)
void DeSerialize(_elementType &object, const bool serializeObject=true)
Definition cmnDeSerializer.h:233
long long int TypeId
Definition cmnDeSerializer.h:184
cmnDeSerializer(std::istream &inputStream)
Base class for high level objects.
Definition cmnGenericObject.h:53
virtual const cmnClassServicesBase * Services(void) const =0
static CISST_EXPORT Type MaxPositiveValue(void)
Assert macros definitions.
Class register definitions and log macros.
#define CMN_DECLARE_SERVICES_INSTANTIATION(className)
Definition cmnClassRegisterMacros.h:199
const int CMN_NO_DYNAMIC_CREATION
Definition cmnClassRegisterMacros.h:325
void cmnDeSerializeSizeRaw(std::istream &inputStream, size_t &data) CISST_THROW(std
Definition cmnDeSerializer.h:96
void cmnDeSerializeRaw(std::istream &inputStream, _elementType &data) CISST_THROW(std
Definition cmnDeSerializer.h:82
Macros to export the symbols of cisstCommon (in a Dll).
#define CISST_EXPORT
Definition cmnExportMacros.h:50
Defines cmnGenericObject.
#define CMN_LOG_ALLOW_DEFAULT
Definition cmnLogLoD.h:76
#define CMN_LOG_CLASS_RUN_ERROR
Definition cmnLogger.h:117
Portability across compilers and operating systems tools.
#define CISST_THROW(exceptionParameter)
Somewhat portable compilation warning message. This works with very recent versions of gcc (4....
Definition cmnPortability.h:559
Declaration of the template function cmnThrow.
Declaration of the class cmnTypeTraits.
void cmnThrow(const _exceptionType &except, cmnLogLevel lod=CMN_LOG_LEVEL_INIT_ERROR)
Definition cmnThrow.h:76
const_iterator end(void) const
Definition vctDynamicConstMatrixBase.h:209
OwnerType::const_iterator const_iterator
Definition vctDynamicConstMatrixBase.h:95
OwnerType::iterator iterator
Definition vctDynamicConstMatrixBase.h:92
size_type size(void) const
Definition vctDynamicConstMatrixBase.h:228