1 | /*! |
---|
2 | * @file converter.h |
---|
3 | * Is able to convert int to byte-array and vice versa |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _CONVERTER |
---|
7 | #define _CONVERTER |
---|
8 | |
---|
9 | /* include this file, it contains some default definitions */ |
---|
10 | #include "netdefs.h" |
---|
11 | |
---|
12 | |
---|
13 | /* include base_object.h since all classes are derived from this one */ |
---|
14 | #include "base_object.h" |
---|
15 | |
---|
16 | /* The size of an int in byte */ |
---|
17 | #define INTSIZE 4 |
---|
18 | /* The size of a float in byte */ |
---|
19 | #define FLOATSIZE 4 |
---|
20 | |
---|
21 | /*! |
---|
22 | * a class that can convert int to byte-array and vice versa |
---|
23 | */ |
---|
24 | class Converter : public BaseObject |
---|
25 | { |
---|
26 | public: |
---|
27 | static byte* intToByteArray(int x); |
---|
28 | static int byteArrayToInt(const byte* a); |
---|
29 | |
---|
30 | static int intToByteArray(int x, byte* a, int length); |
---|
31 | static int byteArrayToInt(const byte* a, int* x); |
---|
32 | |
---|
33 | static int floatToByteArray(float x, byte* a, int length); |
---|
34 | static int byteArrayToFloat(const byte* a, float* x); |
---|
35 | |
---|
36 | static int stringToByteArray(const char* s, byte* a, int length, int maxLength); |
---|
37 | static int byteArrayToString(const byte* a, char* s, int maxLength); |
---|
38 | static int byteArrayToStringM(const byte* a, char*& s ); |
---|
39 | |
---|
40 | //Test |
---|
41 | static char* floatToBinString(float x); |
---|
42 | |
---|
43 | static byte* floatToByteArray(float x); |
---|
44 | static float byteArrayToFloat(byte* a); |
---|
45 | |
---|
46 | static int _floatToByteArray(float x, byte* a, int length); |
---|
47 | static int _byteArrayToFloat(const byte* a, float* x); |
---|
48 | |
---|
49 | |
---|
50 | static void debug(); |
---|
51 | static void floatTest(float x); |
---|
52 | static void ArrayfloatTest(float x); |
---|
53 | static float getDenormConst(); |
---|
54 | |
---|
55 | |
---|
56 | private: |
---|
57 | Converter(); |
---|
58 | ~Converter(); |
---|
59 | }; |
---|
60 | |
---|
61 | #undef byte |
---|
62 | |
---|
63 | #endif /*_CONVERTER*/ |
---|