cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros
cmnDataFunctionsMacros.h File Reference

Go to the source code of this file.

Macros

#define _cmnDataFunctionsMacros_h
 
#define CMN_DATA_COPY_USING_ASSIGN(_type)
 
#define CMN_DATA_SERIALIZE_DESCRIPTION(_type, _description)
 
#define CMN_DATA_SERIALIZE_BINARY_BYTE_SIZE_USING_SIZEOF(_type)
 
#define CMN_DATA_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR(_type)
 
#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_NO_BYTE_SWAP(_type)
 
#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_AND_BYTE_SWAP(_type)
 
#define CMN_DATA_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR(_type)
 
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_NO_BYTE_SWAP(_type)
 
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_AND_BYTE_SWAP(_type)
 
#define CMN_DATA_SERIALIZE_TEXT_USING_STREAM_OUT(_type)
 
#define CMN_DATA_DE_SERIALIZE_TEXT_USING_STREAM_IN(_type)
 
#define CMN_DATA_HUMAN_READABLE_USING_STREAM_OUT(_type)
 
#define CMN_DATA_SCALAR_DESCRIPTION(_type, _description)
 
#define CMN_DATA_SCALAR_USING_STATIC_CAST(_type)
 
#define CMN_DATA_SCALAR_NUMBER_IS_ONE(_type)
 
#define CMN_DATA_SCALAR_NUMBER_IS_FIXED_TRUE(_type)
 
#define CMN_DATA_IS_SPECIALIZED_TRUE(_type)   enum {IS_SPECIALIZED = 1};
 
#define CMN_DATA_SPECIALIZE_ALL_NO_BYTE_SWAP(type, description)
 
#define CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP(type, description)
 

Macro Definition Documentation

#define _cmnDataFunctionsMacros_h
#define CMN_DATA_COPY_USING_ASSIGN (   _type)
Value:
static void Copy(_type & data, \
const _type & source) { \
data = source; \
}

Macro to overload the function cmnDataCopy using the assignement operator to copy from source to data. This is a appropriate for data types without any dynamic memory allocations. For types using dynamic memory allocations or large blocks of memory, users should overload the cmnDataCopy function using a more efficient approach (memcpy, ...).

#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_AND_BYTE_SWAP (   _type)
Value:
static size_t DeSerializeBinary(_type & data, const char * buffer, size_t bufferSize, \
const cmnDataFormat & localFormat, \
const cmnDataFormat & remoteFormat) \
{ \
const size_t sizeOfData = cmnData<_type>::SerializeBinaryByteSize(data); \
if (bufferSize < sizeOfData) { \
return 0; \
} \
data = *(reinterpret_cast<const _type *>(buffer)); \
if (remoteFormat.GetEndianness() != localFormat.GetEndianness()) { \
} \
bufferSize -= sizeOfData; \
return sizeOfData; \
}
Definition: cmnDataFormat.h:32
void cmnDataByteSwap(_elementType &data)
Definition: cmnDataFormat.h:124
static size_t SerializeBinaryByteSize(const DataType &data)
#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_NO_BYTE_SWAP (   _type)
Value:
static size_t DeSerializeBinary(_type & data, const char * buffer, size_t bufferSize, \
const cmnDataFormat & CMN_UNUSED(localFormat), \
const cmnDataFormat & CMN_UNUSED(remoteFormat)) \
{ \
const size_t sizeOfData = cmnData<_type>::SerializeBinaryByteSize(data); \
if (bufferSize < sizeOfData) { \
return 0; \
} \
data = *(reinterpret_cast<const _type *>(buffer)); \
bufferSize -= sizeOfData; \
return sizeOfData; \
}
Definition: cmnDataFormat.h:32
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
static size_t SerializeBinaryByteSize(const DataType &data)
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_AND_BYTE_SWAP (   _type)
Value:
static void DeSerializeBinary(_type & data, \
std::istream & inputStream, \
const cmnDataFormat & localFormat, \
const cmnDataFormat & remoteFormat) \
throw (std::runtime_error) \
{ \
inputStream.read(reinterpret_cast<char *>(&data), \
sizeof(_type)); \
if (inputStream.fail()) { \
cmnThrow("cmnData::DeSerializeBinary(" #_type "): error occured with std::istream::read"); \
} \
if (remoteFormat.GetEndianness() != localFormat.GetEndianness()) { \
} \
}
Definition: cmnDataFormat.h:32
void cmnDataByteSwap(_elementType &data)
Definition: cmnDataFormat.h:124
#define cmnThrow(a)
Definition: MinimalCmn.h:4
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_NO_BYTE_SWAP (   _type)
Value:
static void DeSerializeBinary(_type & data, \
std::istream & inputStream, \
const cmnDataFormat & CMN_UNUSED(localFormat), \
const cmnDataFormat & CMN_UNUSED(remoteFormat)) \
throw (std::runtime_error) \
{ \
inputStream.read(reinterpret_cast<char *>(&data), \
sizeof(_type)); \
if (inputStream.fail()) { \
cmnThrow("cmnData::DeSerializeBinary(" #_type "): error occured with std::istream::read"); \
} \
}
Definition: cmnDataFormat.h:32
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
#define cmnThrow(a)
Definition: MinimalCmn.h:4
#define CMN_DATA_DE_SERIALIZE_TEXT_USING_STREAM_IN (   _type)
Value:
static void DeSerializeText(_type & data, \
std::istream & inputStream, \
const char CMN_UNUSED(delimiter) = ',') \
throw (std::runtime_error) \
{ \
inputStream >> data; \
if (inputStream.fail()) { \
cmnThrow("cmnData::DeSerializeText(" #_type "): error occured with std::istream::read"); \
} \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
#define cmnThrow(a)
Definition: MinimalCmn.h:4

Macro to overload the function cmnDataDeSerializeText using the C++ stream in operator.

#define CMN_DATA_HUMAN_READABLE_USING_STREAM_OUT (   _type)
Value:
static std::string HumanReadable(const _type & data) \
{ \
std::stringstream stringStream; \
stringStream << data; \
return stringStream.str(); \
}

Macro to overload the function cmnDataHumanReadble using the C++ stream out operator.

#define CMN_DATA_IS_SPECIALIZED_TRUE (   _type)    enum {IS_SPECIALIZED = 1};
#define CMN_DATA_SCALAR_DESCRIPTION (   _type,
  _description 
)
Value:
static std::string ScalarDescription(const _type & CMN_UNUSED(data), \
const size_t CMN_UNUSED(index), \
const std::string & userDescription = "") \
throw (std::out_of_range) { \
return (userDescription == "" ? "{"#_description"}" : (userDescription + ":{"#_description"}")); \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479

Macro to overload the function cmnDataScalarDescription using the type name itself. For example, for a double it will return the string "double".

#define CMN_DATA_SCALAR_NUMBER_IS_FIXED_TRUE (   _type)
Value:
static bool ScalarNumberIsFixed(const _type & CMN_UNUSED(data)) { \
return true; \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
#define CMN_DATA_SCALAR_NUMBER_IS_ONE (   _type)
Value:
static size_t ScalarNumber(const _type & CMN_UNUSED(data)) { \
return 1; \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479

Macro to overload the function cmnDataScalarNumber, returns 1.

#define CMN_DATA_SCALAR_USING_STATIC_CAST (   _type)
Value:
static double Scalar(const _type & data, const size_t CMN_UNUSED(index)) \
throw (std::out_of_range) { \
return static_cast<double>(data); \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479

Macro to overload the function cmnDataScalar using a static_cast.

#define CMN_DATA_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR (   _type)
Value:
static size_t SerializeBinary(const _type & data, \
char * buffer, size_t bufferSize) \
{ \
const size_t sizeOfData = cmnData<_type>::SerializeBinaryByteSize(data); \
if (bufferSize < sizeOfData) { \
return 0; \
} \
*(reinterpret_cast<_type *>(buffer)) = data; \
bufferSize -= sizeOfData; \
return sizeOfData; \
}
static size_t SerializeBinaryByteSize(const DataType &data)

Macro to overload the function cmnDataSerializeBinary using a cast to char pointer and assuming that sizeof reports the real size of the object to be serialized. Please note that this method will not work with data object relying on dynamic memory allocation (pointers) and might also fail if you are using a struct/class your compiler can pad.

#define CMN_DATA_SERIALIZE_BINARY_BYTE_SIZE_USING_SIZEOF (   _type)
Value:
static size_t SerializeBinaryByteSize(const _type & CMN_UNUSED(data)) \
{ \
return sizeof(_type); \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
#define CMN_DATA_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR (   _type)
Value:
static void SerializeBinary(const _type & data, \
std::ostream & outputStream) \
throw (std::runtime_error) \
{ \
outputStream.write(reinterpret_cast<const char *>(&data), \
sizeof(_type)); \
if (outputStream.fail()) { \
cmnThrow("cmnData::SerializeBinary(" #_type "): error occured with std::ostream::write"); \
} \
}
#define cmnThrow(a)
Definition: MinimalCmn.h:4

Macro to overload the function cmnDataSerializeBinary using a cast to char pointer and assuming that sizeof reports the real size of the object to be serialized. Please note that this method will not work with data object relying on dynamic memory allocation (pointers) and might also fail if you are using a struct/class your compiler can pad.

#define CMN_DATA_SERIALIZE_DESCRIPTION (   _type,
  _description 
)
Value:
static std::string SerializeDescription(const _type & CMN_UNUSED(data), \
const char CMN_UNUSED(delimiter) = ',', \
const std::string & userDescription = "") \
{ \
return (userDescription == "" ? "{"#_description"}" : (userDescription + ":{"#_description"}")); \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479

Macro to overload the function cmnDataSerializeDescription.

#define CMN_DATA_SERIALIZE_TEXT_USING_STREAM_OUT (   _type)
Value:
static void SerializeText(const _type & data, \
std::ostream & outputStream, \
const char CMN_UNUSED(delimiter) = ',') \
throw (std::runtime_error) \
{ \
outputStream << data; \
if (outputStream.fail()) { \
cmnThrow("cmnData::SerializeText(" #_type "): error occured with std::ostream::write"); \
} \
}
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
#define cmnThrow(a)
Definition: MinimalCmn.h:4

Macro to overload the function cmnDataSerializeText using the C++ stream out operator.

#define CMN_DATA_SPECIALIZE_ALL_BYTE_SWAP (   type,
  description 
)
Value:
template <> \
class cmnData<type> { \
public: \
CMN_DATA_SCALAR_DESCRIPTION(type, description) \
};
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_AND_BYTE_SWAP(_type)
Definition: cmnDataFunctionsMacros.h:140
#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_AND_BYTE_SWAP(_type)
Definition: cmnDataFunctionsMacros.h:89
#define CMN_DATA_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR(_type)
Definition: cmnDataFunctionsMacros.h:62
#define CMN_DATA_IS_SPECIALIZED_TRUE(_type)
Definition: cmnDataFunctionsMacros.h:228
#define CMN_DATA_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR(_type)
Definition: cmnDataFunctionsMacros.h:112
#define CMN_DATA_SERIALIZE_DESCRIPTION(_type, _description)
Definition: cmnDataFunctionsMacros.h:41
#define CMN_DATA_SCALAR_NUMBER_IS_FIXED_TRUE(_type)
Definition: cmnDataFunctionsMacros.h:223
#define CMN_DATA_HUMAN_READABLE_USING_STREAM_OUT(_type)
Definition: cmnDataFunctionsMacros.h:190
#define CMN_DATA_DE_SERIALIZE_TEXT_USING_STREAM_IN(_type)
Definition: cmnDataFunctionsMacros.h:175
Definition: cmnDataFunctions.h:53
#define CMN_DATA_SCALAR_NUMBER_IS_ONE(_type)
Definition: cmnDataFunctionsMacros.h:218
#define CMN_DATA_SERIALIZE_BINARY_BYTE_SIZE_USING_SIZEOF(_type)
Definition: cmnDataFunctionsMacros.h:50
#define CMN_DATA_SCALAR_USING_STATIC_CAST(_type)
Definition: cmnDataFunctionsMacros.h:211
#define CMN_DATA_COPY_USING_ASSIGN(_type)
Definition: cmnDataFunctionsMacros.h:33
#define CMN_DATA_SERIALIZE_TEXT_USING_STREAM_OUT(_type)
Definition: cmnDataFunctionsMacros.h:160
#define CMN_DATA_SCALAR_DESCRIPTION(_type, _description)
Definition: cmnDataFunctionsMacros.h:202
#define CMN_DATA_SPECIALIZE_ALL_NO_BYTE_SWAP (   type,
  description 
)
Value:
template <> \
class cmnData<type> { \
public: \
CMN_DATA_SCALAR_DESCRIPTION(type, description) \
};
#define CMN_DATA_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR(_type)
Definition: cmnDataFunctionsMacros.h:62
#define CMN_DATA_IS_SPECIALIZED_TRUE(_type)
Definition: cmnDataFunctionsMacros.h:228
#define CMN_DATA_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR(_type)
Definition: cmnDataFunctionsMacros.h:112
#define CMN_DATA_SERIALIZE_DESCRIPTION(_type, _description)
Definition: cmnDataFunctionsMacros.h:41
#define CMN_DATA_SCALAR_NUMBER_IS_FIXED_TRUE(_type)
Definition: cmnDataFunctionsMacros.h:223
#define CMN_DATA_HUMAN_READABLE_USING_STREAM_OUT(_type)
Definition: cmnDataFunctionsMacros.h:190
#define CMN_DATA_DE_SERIALIZE_BINARY_BUFFER_USING_CAST_TO_CHAR_NO_BYTE_SWAP(_type)
Definition: cmnDataFunctionsMacros.h:75
#define CMN_DATA_DE_SERIALIZE_TEXT_USING_STREAM_IN(_type)
Definition: cmnDataFunctionsMacros.h:175
#define CMN_DATA_DE_SERIALIZE_BINARY_STREAM_USING_CAST_TO_CHAR_NO_BYTE_SWAP(_type)
Definition: cmnDataFunctionsMacros.h:125
Definition: cmnDataFunctions.h:53
#define CMN_DATA_SCALAR_NUMBER_IS_ONE(_type)
Definition: cmnDataFunctionsMacros.h:218
#define CMN_DATA_SERIALIZE_BINARY_BYTE_SIZE_USING_SIZEOF(_type)
Definition: cmnDataFunctionsMacros.h:50
#define CMN_DATA_SCALAR_USING_STATIC_CAST(_type)
Definition: cmnDataFunctionsMacros.h:211
#define CMN_DATA_COPY_USING_ASSIGN(_type)
Definition: cmnDataFunctionsMacros.h:33
#define CMN_DATA_SERIALIZE_TEXT_USING_STREAM_OUT(_type)
Definition: cmnDataFunctionsMacros.h:160
#define CMN_DATA_SCALAR_DESCRIPTION(_type, _description)
Definition: cmnDataFunctionsMacros.h:202