VR-Vantage
Loading...
Searching...
No Matches
DtMessage.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2021 MAK Technologies, Inc.
3** All rights reserved.
4******************************************************************************/
5
8#ifndef DtMessage_H_
9#define DtMessage_H_
10
11#include <vrvUtil/vrvUtil.h>
12#include <vector>
13#include <sstream>
14#include <ostream>
15
16#include <tbb/tbb_allocator.h>
17
20
21namespace makVrv
22{
23
24 class DtUnicode;
25
31{
32public:
33
34 typedef unsigned char Byte;
35 typedef std::vector<Byte, tbb::tbb_allocator<Byte> > ByteBuffer;
36
37 static const int theHeaderSize = (sizeof(unsigned short) + sizeof(char)) * 2;
38
39 //Helper Macro to pack the size of a type into a unique id.
40 #define packSizeOf(type) ((sizeof(type)-1)<<4)
41
42 //Helper Macro to unpack the size of a datatype.
43 #define unpackSizeOf(dataType) (((dataType)>>4)+1)
44
45 //Simple data types are encoded as 1 bit 0, 3 bit size, 4 bit id
46 //Complex data types are encoded as 8bit id, w/ MSBit = 1 (ie >= 128)
48 {
50 Char = 1 | packSizeOf(char),
51 UnsignedChar = 2 | packSizeOf(unsigned char),
52 Short = 3 | packSizeOf(short),
53 UnsignedShort = 4 | packSizeOf(unsigned short),
54 Int = 5 | packSizeOf(int),
55 UnsignedInt = 6 | packSizeOf(unsigned int),
56 Float = 7 | packSizeOf(float),
57 LongLong = 8 | packSizeOf(long long),
58 UnsignedLongLong = 9 | packSizeOf(unsigned long long),
59 Double = 10 | packSizeOf(double),
60 Bool = 11 | packSizeOf(bool),
61 Long = 12 | packSizeOf(long),
62 UnsignedLong = 13 | packSizeOf(unsigned long),
63 String = 128,
68 };
69
70 //Data Format:
72 //
75 //
79
83 DtMessage(unsigned short classId = 0,unsigned short functionId = 0);
84
89 DtMessage(const Byte* buffer,size_t size);
90
94 DtMessage(const DtMessage& orig);
95
98
100 void printDebugMessageContents(std::ostream&);
101
103 const char* dataTypeName(unsigned char dataType);
104
106 unsigned short classId() const;
107
109 unsigned short functionId() const;
110
112 const Byte* data() const;
113
115 size_t size() const;
116
119
122 void resetRead();
123
127 void serializeHeader(unsigned short classId, unsigned short functionId);
128
131 bool serializeWriteOut() const;
132
135 void setSerializeWriteOut(bool writeOut);
136
138
140 DtMessage& operator >> (bool& b);
141 DtMessage& operator >> (char& c);
142 DtMessage& operator >> (unsigned char& c);
143 DtMessage& operator >> (short& i);
144 DtMessage& operator >> (unsigned short& i);
145 DtMessage& operator >> (int& i);
146 DtMessage& operator >> (unsigned int& i);
147 DtMessage& operator >> (long long& i);
148 DtMessage& operator >> (unsigned long long& i);
149 DtMessage& operator >> (float& f);
150 DtMessage& operator >> (double& f);
151 DtMessage& operator >> (long& i);
152 DtMessage& operator >> (unsigned long& i);
153 DtMessage& operator >> (std::string& s);
154 DtMessage& operator >> (DtUnicode& s);
155 DtMessage& operator >> (ByteBuffer& rawData);
156
158 DtMessage& operator >> (std::pair<void*,int>& rawData);
160
162
165 DtMessage& operator << (unsigned char c);
167 DtMessage& operator << (unsigned short i);
169 DtMessage& operator << (unsigned int i);
170 DtMessage& operator << (long long i);
171 DtMessage& operator << (unsigned long long i);
175 DtMessage& operator << (unsigned long i);
176 DtMessage& operator << (const std::string& s);
178 DtMessage& operator << (const char* str);
180 DtMessage& operator << (const std::pair<void*, int>& rawData);
181
183
185 void addOnlyData(DtMessage& message);
186
188 void addData(unsigned int dataType,const void* data,int dataSize);
189
191 bool canReadData() const;
192
195 unsigned char nextDataType() const;
196
201 unsigned int nextDataSize() const;
202
205 const void* nextDataPointer() const;
206
209
212 void advanceRead(size_t bytes);
213
217 void getData(int dataType,void* output);
218
220
221
223 {
224 }
225
226 template <typename T1>
227 void addMultiple(T1 t1)
228 {
229 *this << t1;
230 }
231
232 template <typename T1,typename T2>
233 void addMultiple(T1 t1,T2 t2)
234 {
235 *this << t1 << t2;
236 }
237
238 template <typename T1,typename T2,typename T3>
239 void addMultiple(T1 t1,T2 t2,T3 t3)
240 {
241 *this << t1 << t2 << t3;
242 }
243
244 template <typename T1,typename T2,typename T3,typename T4>
245 void addMultiple(T1 t1,T2 t2,T3 t3,T4 t4)
246 {
247 *this << t1 << t2 << t3 << t4;
248 }
249
250 template <typename T1,typename T2,typename T3,typename T4,typename T5>
251 void addMultiple(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5)
252 {
253 *this << t1 << t2 << t3 << t4 << t5;
254 }
255
256 template <typename T1,typename T2,typename T3,typename T4,typename T5,
257 typename T6>
258 void addMultiple(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6)
259 {
260 *this << t1 << t2 << t3 << t4 << t5 << t6;
261 }
262
263 template <typename T1,typename T2,typename T3,typename T4,typename T5,
264 typename T6,typename T7>
265 void addMultiple(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7)
266 {
267 *this << t1 << t2 << t3 << t4 << t5 << t6 << t7;
268 }
269
270 template <typename T1,typename T2,typename T3,typename T4,typename T5,
271 typename T6,typename T7,typename T8>
272 void addMultiple(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8)
273 {
274 *this << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
275 }
276
278 {
279 }
280
281 template <typename T1>
282 void readMultiple(T1& t1)
283 {
284 *this >> t1;
285 }
286
287 template <typename T1,typename T2>
288 void readMultiple(T1& t1,T2& t2)
289 {
290 *this >> t1 >> t2;
291 }
292
293 template <typename T1,typename T2,typename T3>
294 void readMultiple(T1& t1,T2& t2,T3& t3)
295 {
296 *this >> t1 >> t2 >> t3;
297 }
298
299 template <typename T1,typename T2,typename T3,typename T4>
300 void readMultiple(T1& t1,T2& t2,T3& t3,T4& t4)
301 {
302 *this >> t1 >> t2 >> t3 >> t4;
303 }
304
305 template <typename T1,typename T2,typename T3,typename T4,typename T5>
306 void readMultiple(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5)
307 {
308 *this >> t1 >> t2 >> t3 >> t4 >> t5;
309 }
310
311 template <typename T1,typename T2,typename T3,typename T4,typename T5,
312 typename T6>
313 void readMultiple(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6)
314 {
315 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6;
316 }
317
318 template <typename T1,typename T2,typename T3,typename T4,typename T5,
319 typename T6,typename T7>
320 void readMultiple(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6,T7& t7)
321 {
322 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7;
323 }
324
325 template <typename T1,typename T2,typename T3,typename T4,typename T5,
326 typename T6,typename T7,typename T8>
327 void readMultiple(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6,T7& t7,T8& t8)
328 {
329 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8;
330 }
331
332
333 template <typename T1>
334 void serialize(T1& t1)
335 {
337 *this >> t1;
338 else
339 *this << t1;
340 }
341
342 template <typename T1,typename T2>
343 void serialize(T1& t1,T2& t2)
344 {
346 *this >> t1 >> t2;
347 else
348 *this << t1 << t2;
349 }
350
351 template <typename T1,typename T2,typename T3>
352 void serialize(T1& t1,T2& t2,T3& t3)
353 {
355 *this >> t1 >> t2 >> t3;
356 else
357 *this << t1 << t2 << t3;
358 }
359
360 template <typename T1,typename T2,typename T3,typename T4>
361 void serialize(T1& t1,T2& t2,T3& t3,T4& t4)
362 {
364 *this >> t1 >> t2 >> t3 >> t4;
365 else
366 *this << t1 << t2 << t3 << t4;
367 }
368
369 template <typename T1,typename T2,typename T3,typename T4,typename T5>
370 void serialize(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5)
371 {
373 *this >> t1 >> t2 >> t3 >> t4 >> t5;
374 else
375 *this << t1 << t2 << t3 << t4 << t5;
376 }
377
378 template <typename T1,typename T2,typename T3,typename T4,typename T5,
379 typename T6>
380 void serialize(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6)
381 {
383 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6;
384 else
385 *this << t1 << t2 << t3 << t4 << t5 << t6;
386 }
387
388 template <typename T1,typename T2,typename T3,typename T4,typename T5,
389 typename T6,typename T7>
390 void serialize(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6,T7& t7)
391 {
393 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7;
394 else
395 *this << t1 << t2 << t3 << t4 << t5 << t6 << t7;
396 }
397
398 template <typename T1,typename T2,typename T3,typename T4,typename T5,
399 typename T6,typename T7,typename T8>
400 void serialize(T1& t1,T2& t2,T3& t3,T4& t4,T5& t5,T6& t6,T7& t7,T8& t8)
401 {
403 *this >> t1 >> t2 >> t3 >> t4 >> t5 >> t6 >> t7 >> t8;
404 else
405 *this << t1 << t2 << t3 << t4 << t5 << t6 << t7 << t8;
406 }
407
408 //Allows serialize any serialize via archive classes.
409 template <typename T>
411 {
415 class FastStringBuf : public std::stringbuf
416 {
417 public:
418 const char* c_str() const { return pbase();}
419 size_t outputSize() const
420 {
421 return pptr() - pbase();
422 }
423 };
424
425 std::pair<void*,int> configMemory;
426 //Are we writing to the configuration.
428 {
429 //Yank out a binary chunk from the message.
430 serialize(configMemory);
431 //Create an input string stream.
432 std::istringstream memoryStream;
433 //Set the stream to the message data.
434 memoryStream.str(std::string((char*)configMemory.first,configMemory.second));
435 //Create an archive to read the stream.
436 portable_binary_iarchive ia(memoryStream);
437 //Serialize out from the stream.
438 //t.serialize(ia,0);
439 ia & t;
440 //Clean up the message memory.
441 delete[] (char*)configMemory.first;
442 }
443 else
444 {
445
446 //Create a fast buffer.
447 FastStringBuf fastBuffer;
448 //Create a output stream for it.
449 std::ostream memoryStream(&fastBuffer);
450 //Create an archive to write to it.
451 portable_binary_oarchive oa(memoryStream);
452 //Write the object to the archive.
453 oa & t;
454 //t.serialize(oa,boost::serialization::version<T>::value);
455 //Grab the written data.
456 configMemory.first = (void*) fastBuffer.c_str();
457 configMemory.second = fastBuffer.outputSize();
458 //Put that data into this message.
459 serialize(configMemory);
460 }
461 }
462
463protected:
464
466 void setClassId(unsigned short classId);
467
469 void setFunctionId(unsigned short functionId);
470
472 ByteBuffer::const_iterator myReadIter;
474
475};
476
477}
478
479#endif
#define packSizeOf(type)
Definition DtMessage.h:40
std::ostream & operator<<(std::ostream &str, const vrvControlToolkit::DtVdcVector2D &vec)
void readMultiple()
Definition DtMessage.h:277
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5)
Definition DtMessage.h:370
const Byte * data() const
Get a pointer to the start of the data.
void printDebugMessageContents(std::ostream &)
Print the message contents for debugging.
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6)
Definition DtMessage.h:313
DataType
Definition DtMessage.h:48
@ FixedArray
Definition DtMessage.h:64
@ UnicodeString
Definition DtMessage.h:65
@ User_Last
Definition DtMessage.h:67
@ UnsignedChar
Definition DtMessage.h:51
@ Char
Definition DtMessage.h:50
@ Long
Definition DtMessage.h:61
@ Short
Definition DtMessage.h:52
@ UnsignedLong
Definition DtMessage.h:62
@ Int
Definition DtMessage.h:54
@ LongLong
Definition DtMessage.h:57
@ Bool
Definition DtMessage.h:60
@ UnsignedShort
Definition DtMessage.h:53
@ Float
Definition DtMessage.h:56
@ Unknown
Definition DtMessage.h:49
@ Double
Definition DtMessage.h:59
@ User_Start
Definition DtMessage.h:66
@ UnsignedInt
Definition DtMessage.h:55
@ UnsignedLongLong
Definition DtMessage.h:58
@ String
Definition DtMessage.h:63
void setClassId(unsigned short classId)
Set the class id.
unsigned short functionId() const
Get the function id.
const char * dataTypeName(unsigned char dataType)
Get the name of a data type in English.
bool mySerializeWriteOutFlag
Definition DtMessage.h:473
static const int theHeaderSize
Definition DtMessage.h:37
ByteBuffer::const_iterator myReadIter
Definition DtMessage.h:472
void serialize(T1 &t1, T2 &t2)
Definition DtMessage.h:343
unsigned char Byte
Definition DtMessage.h:34
void serialize(T1 &t1, T2 &t2, T3 &t3)
Definition DtMessage.h:352
bool serializeWriteOut() const
Is this message set to write out data during serialization or read in data.
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4)
Definition DtMessage.h:300
unsigned short classId() const
Get the class id.
ByteBuffer myBuffer
Definition DtMessage.h:471
void emptyMessage()
Empty the message. This does NOT dealloc memory.
DtMessage(const DtMessage &orig)
CTOR. Note that the internal read pointer is also copied, in addition to the data.
unsigned char nextDataType() const
Get the type of the next data in the message.
void readMultiple(T1 &t1)
Definition DtMessage.h:282
void setFunctionId(unsigned short functionId)
Set the function id.
void serializeHeader(unsigned short classId, unsigned short functionId)
If the message is set to write out, this will verify that the input class id and the function id matc...
void addData(unsigned int dataType, const void *data, int dataSize)
Low level add data call.
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
Definition DtMessage.h:265
void serialize(T1 &t1)
Definition DtMessage.h:334
void getData(int dataType, void *output)
Read the next parameter into the output. It is assumed that output has sufficient space,...
void setSerializeWriteOut(bool writeOut)
Set whether the message will write out data during serialization or read in data.
void skipToNextData()
Move the read pointer to the next data element in the message.
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7)
Definition DtMessage.h:320
void addOnlyData(DtMessage &message)
Adds only the data from the message (no header).
void readMultiple(T1 &t1, T2 &t2)
Definition DtMessage.h:288
const void * nextDataPointer() const
Get a pointer to the next chunk of data. Do not modify the data in this pointer.
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4)
Definition DtMessage.h:245
void addMultiple()
Helper functions for doing multiple adds and reads.
Definition DtMessage.h:222
void serializeViaArchive(T &t)
Definition DtMessage.h:410
void resetRead()
Reset the internal reader to the beginning of data. This does not include the internal message header...
bool canReadData() const
Get if there is more data that can be read.
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
Definition DtMessage.h:400
std::vector< Byte, tbb::tbb_allocator< Byte > > ByteBuffer
Definition DtMessage.h:35
DtMessage(const Byte *buffer, size_t size)
Construct a message from a raw buffer, the raw buffer MUST have come from another IGI message,...
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5)
Definition DtMessage.h:306
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
Definition DtMessage.h:251
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6)
Definition DtMessage.h:380
DtMessage(unsigned short classId=0, unsigned short functionId=0)
Byte 0: DataType Id.
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
Definition DtMessage.h:272
void addMultiple(T1 t1, T2 t2, T3 t3)
Definition DtMessage.h:239
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7)
Definition DtMessage.h:390
void addMultiple(T1 t1, T2 t2)
Definition DtMessage.h:233
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
Definition DtMessage.h:258
size_t size() const
Get the current size of the message in bytes.
unsigned int nextDataSize() const
Get the data size of the next parameter to be read. NOTE! the reader pointer must be pointing to the ...
void addMultiple(T1 t1)
Definition DtMessage.h:227
void advanceRead(size_t bytes)
Move the read pointer forward a number of bytes.
void readMultiple(T1 &t1, T2 &t2, T3 &t3)
Definition DtMessage.h:294
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
Definition DtMessage.h:327
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4)
Definition DtMessage.h:361
Definition DtUnicode.h:34
Definition portable_binary_iarchive.hpp:86
Definition portable_binary_oarchive.hpp:86
Contains DtCreateSensorFieldOfViewCommand and DtCreateSensorFieldOfViewCommandCreator class declarati...
Definition DtGridLinesSettingsRecord.h:16
Contains DLL export macros.
#define DT_DLL_VRVUTIL
Definition vrvUtil.h:34