23 #ifndef _cmnDataFormat_h
24 #define _cmnDataFormat_h
35 friend class cmnDataTest;
38 typedef enum {CMN_DATA_32_BITS, CMN_DATA_64_BITS} WordSize;
39 typedef enum {CMN_DATA_LITTLE_ENDIAN, CMN_DATA_BIG_ENDIAN} Endianness;
40 typedef enum {CMN_DATA_SIZE_T_SIZE_32, CMN_DATA_SIZE_T_SIZE_64} SizeTSize;
48 return this->WordSizeMember;
52 return this->EndiannessMember;
56 return this->SizeTSizeMember;
60 WordSize WordSizeMember;
61 Endianness EndiannessMember;
62 SizeTSize SizeTSizeMember;
66 template <
class _elementType,
size_t _sizeInBytes>
71 inline static void Execute(_elementType &
CMN_UNUSED(data))
throw (std::runtime_error) {
72 cmnThrow(
"cmnDataByteSwap: a partial specialization should be called!");
76 template <
class _elementType>
81 inline static void Execute(_elementType &
CMN_UNUSED(data))
throw (std::runtime_error) {
85 template <
class _elementType>
89 inline static void Execute(_elementType & data)
throw (std::runtime_error) {
90 *(
unsigned short *)&(data) = ( ((*(
unsigned short *)&(data) & 0xff) << 8) |
91 (*(
unsigned short *)&(data) >> 8) );
95 template <
class _elementType>
99 inline static void Execute(_elementType & data)
throw (std::runtime_error) {
100 *(
unsigned int *)&(data) = ( ((*(
unsigned int *)&(data) & 0xff000000) >> 24) |
101 ((*(
unsigned int *)&(data) & 0x00ff0000) >> 8) |
102 ((*(
unsigned int *)&(data) & 0x0000ff00) << 8) |
103 ((*(
unsigned int *)&(data) & 0x000000ff) << 24) );
107 template <
class _elementType>
111 inline static void Execute(_elementType & data)
throw (std::runtime_error) {
112 *(
unsigned long long int *)&(data) = ( ((*(
unsigned long long int *)&(data) & 0xff00000000000000ULL) >> 56) |
113 ((*(
unsigned long long int *)&(data) & 0x00ff000000000000ULL) >> 40) |
114 ((*(
unsigned long long int *)&(data) & 0x0000ff0000000000ULL) >> 24) |
115 ((*(
unsigned long long int *)&(data) & 0x000000ff00000000ULL) >> 8) |
116 ((*(
unsigned long long int *)&(data) & 0x00000000ff000000ULL) << 8) |
117 ((*(
unsigned long long int *)&(data) & 0x0000000000ff0000ULL) << 24) |
118 ((*(
unsigned long long int *)&(data) & 0x000000000000ff00ULL) << 40) |
119 ((*(
unsigned long long int *)&(data) & 0x00000000000000ffULL) << 56) );
123 template <
class _elementType>
128 #endif // _cmnDataFormat_h
#define CISST_EXPORT
Definition: cmnExportMacros.h:50
Portability across compilers and operating systems tools.
#define CMN_UNUSED(argument)
Definition: cmnPortability.h:479
Definition: cmnDataFormat.h:67
static void Execute(_elementType &data)
Definition: cmnDataFormat.h:99
Macros to export the symbols of cisstCommon (in a Dll).
static void Execute(_elementType &data)
Definition: cmnDataFormat.h:111
#define cmnThrow(a)
Definition: MinimalCmn.h:4
static void Execute(_elementType &data)
Definition: cmnDataFormat.h:89
Declaration of the template function cmnThrow.