-
Notifications
You must be signed in to change notification settings - Fork 16
/
protocolscaling.h
197 lines (144 loc) · 6.55 KB
/
protocolscaling.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef PROTOCOLSCALING_H
#define PROTOCOLSCALING_H
/*!
* \file
* Auto magically generate the plethora of scaling functions
*
* Scaling functions convert all built in in-memory types to different
* to different integer encodings (signed, unsigned, big and little endian,
* and byte lengths from 1 to 8). That's a lot of functions, hence the desire
* to auto-generate them.
*/
#include "protocolfile.h"
#include "protocolsupport.h"
#include <string>
class ProtocolScaling
{
public:
//! Construct the protocol scaling object
ProtocolScaling(ProtocolSupport sup);
//! Perform the generation, writing out the files
bool generate(std::vector<std::string>& fileNameList, std::vector<std::string>& filePathList);
protected:
//! Enumeration for types that can exist in-memory
typedef enum
{
float64inmemory,
uint64inmemory,
int64inmemory,
float32inmemory,
uint32inmemory,
int32inmemory,
uint16inmemory,
int16inmemory,
uint8inmemory,
int8inmemory
}inmemorytypes_t;
//! Enumeration for types that can be scaled to or from encodings
typedef enum
{
longbitencoded,
uint64encoded,
int64encoded,
uint56encoded,
int56encoded,
uint48encoded,
int48encoded,
uint40encoded,
int40encoded,
bitencoded,
uint32encoded,
int32encoded,
uint24encoded,
int24encoded,
uint16encoded,
int16encoded,
uint8encoded,
int8encoded,
}encodedtypes_t;
//! Determine if type is signed
bool isTypeSigned(inmemorytypes_t type) const;
//! Determine if type is signed
bool isTypeSigned(encodedtypes_t type) const;
//! Determine if type is floating point
bool isTypeFloating(inmemorytypes_t type) const;
//! Determine if type is floating point
bool isTypeFloating(encodedtypes_t type) const;
//! Determine if type is bitfield
bool isTypeBitfield(inmemorytypes_t type) const;
//! Determine if type is bitfield
bool isTypeBitfield(encodedtypes_t type) const;
//! Convert type to signed equivalent
inmemorytypes_t convertTypeToSigned(inmemorytypes_t type) const;
//! Convert type to signed equivalent
encodedtypes_t convertTypeToSigned(encodedtypes_t type) const;
//! Convert type to unsigned equivalent
inmemorytypes_t convertTypeToUnsigned(inmemorytypes_t type) const;
//! Convert type to unsigned equivalent
encodedtypes_t convertTypeToUnsigned(encodedtypes_t type) const;
//! Determine the encoded length of type
int typeLength(inmemorytypes_t type) const;
//! Determine the encoded length of type
int typeLength(encodedtypes_t type) const;
//! Create an in-memory type
inmemorytypes_t createInMemoryType(bool issigned, bool isfloat, int length) const;
//! Create an encoded type
encodedtypes_t createEncodedType(bool issigned, int length) const;
//! Return the name in code of this type
std::string typeName(inmemorytypes_t type) const;
//! Return the name in code of this type
std::string typeName(encodedtypes_t type) const;
//! Return the name in function signature of this type
std::string typeSigName(inmemorytypes_t type) const;
//! Return the name in function signature of this type
std::string typeSigName(encodedtypes_t type) const;
//! Determine if type is supported by this protocol
bool isTypeSupported(inmemorytypes_t type) const;
//! Determine if type is supported by this protocol
bool isTypeSupported(encodedtypes_t type) const;
//! Determine if both types are supported by this protocol
bool areTypesSupported(inmemorytypes_t source, encodedtypes_t encoded) const;
//! Generate the encode header file
bool generateEncodeHeader(void);
//! Generate the encode source file
bool generateEncodeSource(void);
//! Generate the one line brief comment for the encode function
std::string briefEncodeComment(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full comment for the encode function
std::string fullEncodeComment(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the encode function signature
std::string encodeSignature(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full encode function
std::string fullEncodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full encode function for integer scaling
std::string fullBitfieldEncodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full encode function for floating point scaling
std::string fullFloatEncodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const ;
//! Generate the full encode function for integer scaling
std::string fullIntegerEncodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the decode header file
bool generateDecodeHeader(void);
//! Generate the decode source file
bool generateDecodeSource(void);
//! Generate the one line brief comment for the decode function
std::string briefDecodeComment(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full comment for the decode function
std::string fullDecodeComment(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the decode function signature
std::string decodeSignature(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full decode function
std::string fullDecodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full decode function for integer scaling
std::string fullBitfieldDecodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Generate the full decode function for floating point scaling
std::string fullFloatDecodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const ;
//! Generate the full decode function for integer scaling
std::string fullIntegerDecodeFunction(inmemorytypes_t source, encodedtypes_t encoded, bool bigendian) const;
//! Header file output object
ProtocolHeaderFile header;
//! Source file output object
ProtocolSourceFile source;
//! Whats supported by the protocol
ProtocolSupport support;
};
#endif // PROTOCOLSCALING_H