VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
18 class portable_binary_iarchive;
19 class portable_binary_oarchive;
20 
21 namespace makVrv
22 {
23 
24  class DtUnicode;
25 
31 {
32 public:
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)
47  enum DataType
48  {
49  Unknown = 0,
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,
64  FixedArray = 129,
65  UnicodeString = 130,
66  User_Start = 150,
67  User_Last = 255
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 
97  ~DtMessage();
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 
118  void emptyMessage();
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  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);
155  DtMessage& operator >> (ByteBuffer& rawData);
156 
158  DtMessage& operator >> (std::pair<void*,int>& rawData);
160 
162  DtMessage& operator << (bool b);
164  DtMessage& operator << (char c);
165  DtMessage& operator << (unsigned char c);
166  DtMessage& operator << (short i);
167  DtMessage& operator << (unsigned short i);
168  DtMessage& operator << (int i);
169  DtMessage& operator << (unsigned int i);
170  DtMessage& operator << (long long i);
171  DtMessage& operator << (unsigned long long i);
172  DtMessage& operator << (float f);
173  DtMessage& operator << (double f);
174  DtMessage& operator << (long i);
175  DtMessage& operator << (unsigned long i);
176  DtMessage& operator << (const std::string& s);
177  DtMessage& operator << (const DtUnicode& s);
178  DtMessage& operator << (const char* str);
179  DtMessage& operator << (const ByteBuffer& rawData);
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 
208  void skipToNextData();
209 
212  void advanceRead(size_t bytes);
213 
217  void getData(int dataType,void* output);
218 
220 
222  void addMultiple()
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  {
336  if(mySerializeWriteOutFlag)
337  *this >> t1;
338  else
339  *this << t1;
340  }
341 
342  template <typename T1,typename T2>
343  void serialize(T1& t1,T2& t2)
344  {
345  if(mySerializeWriteOutFlag)
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  {
354  if(mySerializeWriteOutFlag)
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  {
363  if(mySerializeWriteOutFlag)
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  {
372  if(mySerializeWriteOutFlag)
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  {
382  if(mySerializeWriteOutFlag)
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  {
392  if(mySerializeWriteOutFlag)
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  {
402  if(mySerializeWriteOutFlag)
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.
427  if(serializeWriteOut())
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 
463 protected:
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
DataType
Definition: DtMessage.h:47
A unicode string. DtUnicode stores a UTF-16 encoded unicode string. Code Point, a Unicode character...
Definition: DtUnicode.h:33
void serialize(T1 &t1)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:334
#define DT_DLL_VRVUTIL
Definition: vrvUtil.h:34
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:265
The IGI Message. Is easily encoded and decoding using stream operators. It also provides validation d...
Definition: DtMessage.h:30
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:327
std::vector< Byte, tbb::tbb_allocator< Byte > > ByteBuffer
Definition: DtMessage.h:35
DT_DLL_VRFGUICORE makVrv::DtMessage & operator<<(DtMessage &msg, const makVrf::DtNetworkMessageAgentInterface &)
voidpf void uLong size
Definition: ioapi.h:39
void readMultiple(T1 &t1)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:282
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:251
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:320
unsigned char Byte
Definition: DtMessage.h:34
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:361
void readMultiple(T1 &t1, T2 &t2)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:288
void addMultiple()
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:222
Contains DLL export macros.
void addMultiple(T1 t1)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:227
UInt8 Bool
Definition: stateDataTypes.h:20
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7, T8 &t8)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:400
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:313
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:306
#define packSizeOf(type)
Definition: DtMessage.h:40
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:258
void addMultiple(T1 t1, T2 t2, T3 t3)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:239
ByteBuffer::const_iterator myReadIter
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:472
void readMultiple()
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:277
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:380
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:272
void addMultiple(T1 t1, T2 t2)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:233
bool mySerializeWriteOutFlag
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:473
void serialize(T1 &t1, T2 &t2)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:343
void serializeViaArchive(T &t)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:410
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5, T6 &t6, T7 &t7)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:390
DT_DLL_VRFGUICORE makVrv::DtMessage & operator>>(DtMessage &msg, makVrf::DtNetworkMessageAgentInterface &)
ByteBuffer myBuffer
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:471
void readMultiple(T1 &t1, T2 &t2, T3 &t3)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:294
void readMultiple(T1 &t1, T2 &t2, T3 &t3, T4 &t4)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:300
void addMultiple(T1 t1, T2 t2, T3 t3, T4 t4)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:245
void serialize(T1 &t1, T2 &t2, T3 &t3)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:352
void serialize(T1 &t1, T2 &t2, T3 &t3, T4 &t4, T5 &t5)
Helper functions for doing multiple adds and reads.
Definition: DtMessage.h:370

Document ID: Generated on Tue Sep 24 19:28:17 EDT 2024 from SVN revision 269799
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)