Utilities  1
Collection of utility classes and functions used by my C++ applications.
 All Classes Namespaces Files Functions Typedefs Enumerations Enumerator Friends Macros
binaryconversion.h
Go to the documentation of this file.
1 #ifndef CONVERSION_UTILITIES_CONVERT_H
2 #define CONVERSION_UTILITIES_CONVERT_H
3 
4 #include "types.h"
5 
6 #include "../application/global.h"
7 
8 #if defined(__BYTE_ORDER__) && defined(__FLOAT_WORD_ORDER__)
9 # if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
10 # define CONVERSION_UTILITIES_BYTE_ORDER_BIG_ENDIAN
11 # elif __BYTE_ORDER__ == __ORDER_PDP_ENDIAN__
12 # define CONVERSION_UTILITIES_BYTE_ORDER_MIDDLE_ENDIAN
13 # elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
14 # define CONVERSION_UTILITIES_BYTE_ORDER_LITTLE_ENDIAN
15 # endif
16 # if __FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__
17 # define CONVERSION_UTILITIES_FLOAT_BYTE_ORDER_BIG_ENDIAN
18 # elif __FLOAT_WORD_ORDER__ == __ORDER_PDP_ENDIAN__
19 # define CONVERSION_UTILITIES_FLOAT_BYTE_ORDER_MIDDLE_ENDIAN
20 # elif __FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__
21 # define CONVERSION_UTILITIES_FLOAT_BYTE_ORDER_LITTLE_ENDIAN
22 # endif
23 #elif defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__x86_64) || defined(__x86_64__) || defined(__amd64) || defined(_M_X64) || defined(__LITTLE_ENDIAN__) || defined(_little_endian__) || defined(_LITTLE_ENDIAN) || defined(_WIN32_WCE) || defined(WINAPI_FAMILY)
24 # define CONVERSION_UTILITIES_BYTE_ORDER_LITTLE_ENDIAN
25 # define CONVERSION_UTILITIES_FLOAT_BYTE_ORDER_LITTLE_ENDIAN
26 #elif defined(__MIPSEB__) || defined(__s390__) || defined(__BIG_ENDIAN__) || defined(_big_endian__) || defined(_BIG_ENDIAN)
27 # define CONVERSION_UTILITIES_BYTE_ORDER_BIG_ENDIAN
28 # define CONVERSION_UTILITIES_FLOAT_BYTE_ORDER_BIG_ENDIAN
29 #else
30 # error "Unable to determine byte order!"
31 #endif
32 
33 namespace ConversionUtilities
34 {
35 
40 enum class ByteOrder
41 {
42  BigEndian,
44 };
45 
46 
47 LIB_EXPORT int16 toInt16(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
48 LIB_EXPORT uint16 toUInt16(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
49 LIB_EXPORT int32 toInt32(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
50 LIB_EXPORT uint32 toUInt24(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
51 LIB_EXPORT uint32 toUInt32(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
52 LIB_EXPORT int64 toInt64(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
53 LIB_EXPORT uint64 toUInt64(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
54 LIB_EXPORT float32 toFloat32(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
55 LIB_EXPORT float64 toFloat64(const char *value, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
57 LIB_EXPORT uint32 toNormalInt(uint32 synchsafeInt);
58 
59 LIB_EXPORT void getBytes(int16 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
60 LIB_EXPORT void getBytes(uint16 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
61 LIB_EXPORT void getBytes(int32 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
62 LIB_EXPORT void getBytes(uint32 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
63 LIB_EXPORT void getBytes(int64 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
64 LIB_EXPORT void getBytes(uint64 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
65 LIB_EXPORT void getBytes(float32 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
66 LIB_EXPORT void getBytes(float64 value, char *outputbuffer, int startIndex = 0, ByteOrder byteOrder = ByteOrder::LittleEndian);
67 
68 }
69 
70 
71 #endif // CONVERSION_UTILITIES_CONVERT_H
void getBytes(int16 value, char *outputbuffer, int startIndex, ByteOrder byteOrder)
Stores the specified 16-bit signed integer value at a specified position in a char array...
ByteOrder
Specifies the byte order/endianness.
std::int64_t int64
signed 64-bit integer
Definition: types.h:29
float64 toFloat64(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 64-bit floating point number converted from eight bytes at a specified position in a char a...
uint32 toNormalInt(uint32 synchsafeInt)
Returns a normal 32-bit integer converted from a 32-bit synchsafe integer.
#define LIB_EXPORT
This macro marks a symbol for shared library export.
Definition: global.h:50
int16 toInt16(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 16-bit signed integer converted from two bytes at a specified position in a char array...
std::uint64_t uint64
unsigned 64-bit integer
Definition: types.h:49
float32 toFloat32(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 32-bit floating point number converted from four bytes at a specified position in a char ar...
uint32 toUInt24(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 32-bit unsigned integer converted from three bytes at a specified position in a char array...
Contains several functions providing conversions between different data types.
std::uint32_t uint32
unsigned 32-bit integer
Definition: types.h:44
uint32 toSynchsafeInt(uint32 normalInt)
Returns a 32-bit synchsafe integer converted from a normal 32-bit integer.
uint64 toUInt64(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a char array...
std::int32_t int32
signed 32-bit integer
Definition: types.h:24
int32 toInt32(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 32-bit signed integer converted from four bytes at a specified position in a char array...
uint32 toUInt32(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 32-bit unsigned integer converted from four bytes at a specified position in a char array...
std::int16_t int16
signed 16-bit integer
Definition: types.h:19
uint16 toUInt16(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 16-bit unsigned integer converted from two bytes at a specified position in a char array...
std::uint16_t uint16
unsigned 16-bit integer
Definition: types.h:39
int64 toInt64(const char *value, int startIndex, ByteOrder byteOrder)
Returns a 64-bit signed integer converted from eight bytes at a specified position in a char array...