MAK RTIspy API Documentation for HLA Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rtiTemplateMsgArrayParams.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2011 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 
13 
14 #ifndef DtRtiTemplateMsgArrayParams_H_
15 #define DtRtiTemplateMsgArrayParams_H_
16 
17 #include "rtiTemplateMsgParams.h"
18 #include <vlutil/vlString.h>
19 #include <assert.h>
20 #include <set>
21 #include <vector>
22 #include <list>
23 #include <deque>
24 
25 
26 
29 template<typename ParamType, typename NetParamType>
30 class DtRtiArraySizeMsgParam : public DtRtiMsgParam<ParamType, NetParamType>
31 {
32 public:
33  DtRtiArraySizeMsgParam(const char* paramName) : DtRtiMsgParam<ParamType, NetParamType>(paramName) {}
35 
41  void registerArray(DtRtiBaseMsgParam* arrayParam)
42  {
43  myArrayParams.push_back(arrayParam);
44  }
45 
47  unsigned bytesNeeded(unsigned num) const
48  {
49  unsigned bytes = 0;
50  std::list<DtRtiBaseMsgParam*>::const_iterator pIter = myArrayParams.begin();
51  std::list<DtRtiBaseMsgParam*>::const_iterator pEnd = myArrayParams.end();
52  for(; pIter != pEnd; ++pIter)
53  {
54  bytes += ((*pIter)->elementSize() * num);
55  }
56  return bytes;
57  }
58 
61  const void* firstArrayPtr() const
62  {
63  const void* p = 0;
64  std::list<DtRtiBaseMsgParam*>::const_iterator pIter = myArrayParams.begin();
65  if( pIter != myArrayParams.end())
66  {
67  p = (*pIter)->beginPtr();
68  }
69  return p;
70  }
71  void* firstArrayPtr()
72  {
73  void* p = 0;
74  std::list<DtRtiBaseMsgParam*>::iterator pIter = myArrayParams.begin();
75  if( pIter != myArrayParams.end())
76  {
77  p = (*pIter)->beginPtr();
78  }
79  return p;
80  }
81 
82 protected:
83 
85  std::list<DtRtiBaseMsgParam*> myArrayParams;
86 
87 };
88 
91 template<typename ParamType, typename ConvParamType, typename NetParamType, typename AllocatedMsgParamType>
93 {
94 public:
95  DtRtiArrayMsgParam(const char* paramName, AllocatedMsgParamType* allocatedNum)
96  : DtRtiBaseMsgParam(paramName)
97  , myNumUsed(0)
98  , myAllocatedNumParam(allocatedNum)
100  {
101  myAllocatedNumParam->registerArray(this);
102  }
104 
107  bool addParam(ParamType val)
108  {
109  bool result = false;
110  if(myNumUsed+1 <= myAllocatedNumParam->param())
111  {
112  result = true;
113 
114  NetParamType* ptr = paramPtr() + myNumUsed;
115  *ptr = static_cast<ConvParamType>(val);
116  ++myNumUsed;
117  }
118 
119  return result;
120  }
121 
124  bool setParams(const ParamType* vals, unsigned num)
125  {
126  bool result = false;
127  if(num <= myAllocatedNumParam->param())
128  {
129  result = true;
130 
131  NetParamType* ptr = paramPtr();
132  myNumUsed = num;
133 
134  for(unsigned i = 0; i < num; ++i)
135  {
136  ptr[i] = static_cast<ConvParamType>(vals[i]);
137  }
138  }
139 
140  return result;
141  }
142 
145  template <typename ParamContainerType>
146  bool setParams(const ParamContainerType& container)
147  {
148  bool result = false;
149  if(container.size() <= myAllocatedNumParam->param())
150  {
151  result = true;
152 
153  NetParamType* ptr = paramPtr();
154  myNumUsed = container.size();
155 
156  typename ParamContainerType::const_iterator iter = container.begin();
157  typename ParamContainerType::const_iterator iterEnd = container.end();
158  for(unsigned i = 0; iter != iterEnd; ++iter)
159  {
160  ptr[i++] = static_cast<ConvParamType>(*iter);
161  }
162  }
163 
164  return result;
165  }
166 
169  template <typename ParamContainerType>
170  void getParams(ParamContainerType& container) const
171  {
172  unsigned numItems = myAllocatedNumParam->param();
173  const NetParamType* ptr = paramPtr();
174  for(unsigned i = 0; i < numItems; ++i)
175  {
176  container.insert(container.end(),
177  static_cast<ParamType>(static_cast<ConvParamType>(ptr[i])));
178  }
179  }
180 
183  unsigned getParams(ParamType* buff) const
184  {
185  unsigned numItems = myAllocatedNumParam->param();
186  const NetParamType* ptr = paramPtr();
187  for(unsigned i = 0; i < numItems; ++i)
188  {
189  buff[i] = static_cast<ParamType>(static_cast<ConvParamType>(ptr[i]));
190  }
191 
192  return numItems;
193  }
194 
197  bool getFirstParam(ParamType& val) const
198  {
199  bool itemExists = myAllocatedNumParam->param() > 0;
200  if(itemExists)
201  {
202  const NetParamType* ptr = paramPtr();
203  val = static_cast<ParamType>(static_cast<ConvParamType>(ptr[0]));
205  }
206  return itemExists;
207  }
208 
211  bool getNextParam(ParamType& val) const
212  {
213  bool itemExists = myAllocatedNumParam->param() > myMutableNextParamIndex;
214  if(itemExists)
215  {
216  const NetParamType* ptr = paramPtr();
217  val = static_cast<ParamType>(
218  static_cast<ConvParamType>(ptr[myMutableNextParamIndex++]));
219  }
220  return itemExists;
221  }
222 
224  void* endPtr()
225  {
226  return (paramPtr() + myAllocatedNumParam->param());
227  }
228  const void* endPtr() const
229  {
230  return (paramPtr() + myAllocatedNumParam->param());
231  }
232 
235  unsigned minSize() { return 0; }
236 
238  unsigned elementSize() { return sizeof(NetParamType); }
239 
241  unsigned numItems() const { return myAllocatedNumParam->param(); }
242 
244  void setNumItems(unsigned num) { myAllocatedNumParam->setParam(num); }
245 
247  void print() const
248  {
249  MAKRti::DtVerbose << name() << ": " << std::endl;
250  ParamType val;
251  if(getFirstParam(val))
252  {
253  MAKRti::DtVerbose << " " << val << std::endl;
254  while(getNextParam(val))
255  {
256  MAKRti::DtVerbose << " " << val << std::endl;
257  }
258  }
259  else
260  {
261  MAKRti::DtVerbose << " Empty" << std::endl;
262  }
263  }
264 
268  void setOctetBoundary(unsigned prevBoundary)
269  {
270  myOctetBoundary = sizeof(NetParamType) % 8;
271 
272  // Check that our message is assembled properly
273  assert(prevBoundary == 0 || (prevBoundary % sizeof(NetParamType)) == 0);
274  }
275 
276 protected:
278 
280  NetParamType* paramPtr() { return reinterpret_cast<NetParamType*>(beginPtr()); }
281  const NetParamType* paramPtr() const { return reinterpret_cast<const NetParamType*>(beginPtr()); }
282 
283 protected:
284 
287  AllocatedMsgParamType* myAllocatedNumParam;
288 
290  unsigned myNumUsed;
291 
293  mutable unsigned myMutableNextParamIndex;
294 
295 };
296 
297 
298 
300 template<typename AllocatedMsgParamType>
301 class DtRtiArrayMsgParam<char, char, char, AllocatedMsgParamType> : public DtRtiBaseMsgParam
302 {
303 public:
304  DtRtiArrayMsgParam(const char* paramName, AllocatedMsgParamType* allocatedNumParam)
305  : DtRtiBaseMsgParam(paramName)
306  , myNumUsed(0)
307  , myAllocatedNumParam(allocatedNumParam)
310 
313  bool addParams(const char* str, unsigned size)
314  {
315  bool result = false;
316  bool nullNeeded = false;
317 
318  // Make room for null character
319  if(str[size-1] != '\0')
320  {
321  nullNeeded = true;
322  }
323 
324  if(myNumUsed + size <= myAllocatedNumParam->param())
325  {
326  result = true;
327 
328  char* ptr = paramPtr() + myNumUsed;
329  myNumUsed += size;
330  memcpy(ptr, str, size);
331 
332  if(nullNeeded)
333  {
334  ptr[myNumUsed] = '\0';
335  ++myNumUsed;
336  }
337  }
338 
339  return result;
340  }
341 
344  bool addParams(const MAKRti::DtString& str)
345  {
346  return addParams(str.c_str(), str.size()+1);
347  }
348 
351  bool setParams(const char* str, unsigned size)
352  {
353  myNumUsed = 0;
354  return addParams(str, size);
355  }
356 
359  bool setParams(const MAKRti::DtString& str)
360  {
361  myNumUsed = 0;
362  return addParams(str.c_str(), str.size()+1);
363  }
364 
366  template <typename ParamContainerType>
367  bool setSubStrings(const ParamContainerType& container)
368  {
369  bool result = true;
370  char* curr = paramPtr();
371  myNumUsed = 0;
372  unsigned size = myAllocatedNumParam->param();
373 
374  typename ParamContainerType::const_iterator iter = container.begin();
375  typename ParamContainerType::const_iterator iterEnd = container.end();
376  for(; iter != iterEnd; ++iter)
377  {
378  if(myNumUsed + iter->size() + 1 <= size)
379  {
380  memcpy(curr + myNumUsed, iter->c_str(), iter->size());
381  myNumUsed += iter->size();
382  curr[myNumUsed++] = '\0';
383  }
384  else
385  {
386  result = false;
387  break;
388  }
389  }
390 
391  return result;
392  }
393 
395  void getParams(MAKRti::DtString& str) const
396  {
397  unsigned size = myAllocatedNumParam->param();
398  const char* ptr = paramPtr();
399  str = MAKRti::DtString(ptr, size);
400  }
401 
404  unsigned getParams(char* buff) const
405  {
406  unsigned size = myAllocatedNumParam->param();
407  const char* ptr = paramPtr();
408  memcpy(buff, ptr, size);
409  return size;
410  }
411 
413  template <typename ParamContainerType>
414  void getSubStrings(ParamContainerType& container) const
415  {
416  const char* curr = paramPtr();
417  unsigned size = myAllocatedNumParam->param();
418  while(size)
419  {
420  MAKRti::DtString currStr(curr);
421  size -= currStr.size() + 1;
422  container.insert(container.end(), currStr);
423  curr += currStr.size() + 1;
424  }
425  }
426 
428  void* endPtr()
429  {
430  return (paramPtr() + myAllocatedNumParam->param());
431  }
432  const void* endPtr() const
433  {
434  return (paramPtr() + myAllocatedNumParam->param());
435  }
436 
439  unsigned minSize() { return 0; }
440 
442  unsigned elementSize() { return sizeof(char); }
443 
445  unsigned numItems() const { return myAllocatedNumParam->param(); }
446 
448  void setNumItems(unsigned num) { myAllocatedNumParam->setParam(num); }
449 
451  void print() const
452  {
453  MAKRti::DtString str;
454  getParams(str);
455  MAKRti::DtVerbose << name() << ": " << str << std::endl;
456  }
457 
461  void setOctetBoundary(unsigned prevBoundary)
462  {
463  myOctetBoundary = sizeof(char) % 8;
464 
465  // Check that our message is assembled properly
466  assert(prevBoundary == 0 || (prevBoundary % sizeof(char)) == 0);
467  }
468 
469 protected:
470 
472  char* paramPtr() { return reinterpret_cast<char*>(beginPtr()); }
473  const char* paramPtr() const { return reinterpret_cast<const char*>(beginPtr()); }
474 
475 protected:
476 
478 
481  AllocatedMsgParamType* myAllocatedNumParam;
482 
484  unsigned myNumUsed;
485 
487  mutable unsigned myMutableNextParamIndex;
488 
489 };
490 
491 
493 {
496 };
497 
498 
499 
500 // PARAMETER DECLARATION MACROS
501 // These macros declare parameters and their accessor methods within a message.
502 // In your class definition, simply use one of the type-specific macros
503 // below (e.g. DtDECLARE_UNSIGNED_ARRAY_PARAMETER_METHODS,
504 // DtDECLARE_STRING_PARAMETER_METHODS, etc.). All array parameters will require
505 // the definition of a separate unsigned parameter which will store the size of
506 // the array.
507 
508 // Defines a new unsigned integer parameter to be used as an array size and
509 // declares its get and set methods. It also declares a method to reserve space
510 // for the array (or arrays if this parameter is shared).
511 // ParamName = the name of the parameter
512 // BitSize = the storage size in the message (in bits, obviously)
513 #define DtDECLARE_ARRAY_SIZE_PARAMETER_METHODS(ParamName, BitSize) \
514  DtDECLARE_PARAMETER_METHODS(ParamName, MAKRti::DtU##BitSize) \
515  protected: \
516  typedef DtRtiArraySizeMsgParam<MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize> ParamName##Type; \
517  ParamName##Type* my##ParamName; \
518  public: \
519  void reserveSpaceFor##ParamName(unsigned num);
520 
521 // Declares the generic set and get methods utilizing standard container types
522 // for a parameter which is a variable length array of some data type. Should
523 // not be used directly. Use one of the more type specific versions below,
524 // which will also define the parameter itself.
525 // ParamName = the name of the parameter
526 // CtrType = the type of container to be accepted as input/output (e.g. set)
527 #define DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, CtrType) \
528  public: \
529  void set##ParamName(const CtrType& val, \
530  DtResizeArrayFlag resizeFlag = DtResizeIfNeeded); \
531  void get##ParamName(CtrType&) const;
532 
533 // Declares the generic set and get methods utilizing a standard C array
534 // for a parameter which is a variable length array of some data type. Should
535 // not be used directly. Use one of the more type specific versions below,
536 // which will also define the parameter itself.
537 // ParamName = the name of the parameter
538 // ParamType = the type of each individual item in the array
539 #define DtDECLARE_ARRAY_PARAMETER_POINTER_METHODS(ParamName, ParamType) \
540  public: \
541  void set##ParamName(const ParamType* inputBuff, unsigned numItems, \
542  DtResizeArrayFlag resizeFlag = DtResizeIfNeeded); \
543  unsigned get##ParamName(ParamType* outputBuff) const; /*returns num items*/
544 
545 // Declares the generic set and get methods for a parameter which is a variable
546 // length array of some data type. Should not be used directly. Use one of the
547 // more type specific versions below, which will also define the parameter
548 // itself.
549 // ParamName = the name of the parameter
550 // ParamType = the type of each individual item in the array
551 #define DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, ParamType) \
552  public: \
553  static const char* ParamName##Name; \
554  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::set<ParamType>) \
555  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::vector<ParamType>) \
556  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::deque<ParamType>) \
557  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::list<ParamType>) \
558  DtDECLARE_ARRAY_PARAMETER_POINTER_METHODS(ParamName, ParamType)
559 
560 // Defines a new array of unsigned integers parameter in a message and declares
561 // its get and set methods.
562 // ParamName = the name of the parameter
563 // BitSize = the storage size in the message (in bits, obviously)
564 // CountBitSize = the number of bits in the parameter that holds the item count
565 #define DtDECLARE_UNSIGNED_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
566  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtU##BitSize) \
567  protected: \
568  typedef DtRtiArrayMsgParam<MAKRti::DtU##BitSize, MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize, \
569  DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
570  ParamName##Type* my##ParamName;
571 
572 // Defines a new array of integers parameter in a message and declares
573 // its get and set methods.
574 // ParamName = the name of the parameter
575 // BitSize = the storage size in the message (in bits, obviously)
576 // CountBitSize = the number of bits in the parameter that holds the item count
577 #define DtDECLARE_INT_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
578  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtInt##BitSize) \
579  protected: \
580  typedef DtRtiArrayMsgParam<MAKRti::DtInt##BitSize, MAKRti::DtInt##BitSize, MAKRti::DtNetInt##BitSize,\
581  DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
582  ParamName##Type* my##ParamName;
583 
584 // Defines a new array of booleans parameter in a message and declares
585 // its get and set methods.
586 // ParamName = the name of the parameter
587 // CountBitSize = the number of bits in the parameter that holds the item count
588 #define DtDECLARE_BOOL_ARRAY_PARAMETER_METHODS(ParamName, CountBitSize) \
589  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, bool) \
590  protected: \
591  typedef DtRtiArrayMsgParam<bool, MAKRti::DtU8, MAKRti::DtNetU8, \
592  DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
593  ParamName##Type* my##ParamName;
594 
595 // Defines a new array of enumerations parameter in a message and declares
596 // its get and set methods.
597 // ParamName = the name of the parameter
598 // EnumType = the type of each individual item in the array
599 // BitSize = the storage size in the message (in bits, obviously)
600 // CountBitSize = the number of bits in the parameter that holds the item count
601 #define DtDECLARE_ENUMERATION_ARRAY_PARAMETER_METHODS(ParamName, EnumType, BitSize, CountBitSize)\
602  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, EnumType) \
603  protected: \
604  typedef DtRtiArrayMsgParam<EnumType, MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize, \
605  DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
606  ParamName##Type* my##ParamName;
607 
608 // Defines a new array of floats parameter in a message and declares
609 // its get and set methods.
610 // ParamName = the name of the parameter
611 // BitSize = the storage size in the message (in bits, obviously)
612 // CountBitSize = the number of bits in the parameter that holds the item count
613 #define DtDECLARE_FLOAT_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
614  DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtFloat##BitSize) \
615  protected: \
616  typedef DtRtiArrayMsgParam<MAKRti::DtFloat##BitSize, MAKRti::DtFloat##BitSize, MAKRti::DtNetFloat##BitSize,\
617  DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
618  ParamName##Type* my##ParamName;
619 
620 // Defines a string parameter in a message and declares its get and set methods.
621 // ParamName = the name of the parameter
622 // LengthBitSize = number of bits in the parameter that holds the string length
623 #define DtDECLARE_STRING_PARAMETER_METHODS(ParamName, LengthBitSize) \
624  public: \
625  static const char* ParamName##Name; \
626  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, MAKRti::DtString) \
627  DtDECLARE_ARRAY_PARAMETER_POINTER_METHODS(ParamName, char) \
628  protected: \
629  typedef DtRtiArrayMsgParam<char, char, char, \
630  DtRtiArraySizeMsgParam<MAKRti::DtU##LengthBitSize, MAKRti::DtNetU##LengthBitSize> > ParamName##Type; \
631  ParamName##Type* my##ParamName;
632 
633 // Defines a new array of strings parameter in a message and declares
634 // its get and set methods.
635 // ParamName = the name of the parameter
636 // LengthBitSize = number of bits in the parameter that holds the total length
637 // of all strings
638 #define DtDECLARE_STRING_ARRAY_PARAMETER_METHODS(ParamName, LengthBitSize) \
639  public: \
640  static const char* ParamName##Name; \
641  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::set<MAKRti::DtString>) \
642  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::vector<MAKRti::DtString>) \
643  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::list<MAKRti::DtString>) \
644  DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, std::deque<MAKRti::DtString>) \
645  protected: \
646  typedef DtRtiArrayMsgParam<char, char, char, \
647  DtRtiArraySizeMsgParam<MAKRti::DtU##LengthBitSize, MAKRti::DtNetU##LengthBitSize> > ParamName##Type; \
648  ParamName##Type* my##ParamName;
649 
650 
651 
652 
653 // PARAMETER DEFINITION MACROS
654 // These macros define the accessor methods for a message parameter.
655 // In your .cxx file, simply use one of the type-specific macros
656 // below (e.g. DtDEFINE_UNSIGNED_ARRAY_PARAMETER_METHODS,
657 // DtDEFINE_STRING_ARRAY_PARAMETER_METHODS, etc.). The macro should match the
658 // type used in the DtDECLARE macro in your class definition.
659 
660 // Defines the set and get methods for unsigned integer parameter to be used as
661 // an array size. It also defines a method to reserve space for the array (or
662 // arrays if this parameter is shared).
663 // ClassName = the name of the message class
664 // ParamName = the name of the parameter
665 // BitSize = the storage size in the message (in bits, obviously)
666 #define DtDEFINE_ARRAY_SIZE_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
667  DtDEFINE_UNSIGNED_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
668  void ClassName::reserveSpaceFor##ParamName(unsigned num) \
669  { \
670  void* p = my##ParamName->firstArrayPtr(); \
671  if(p && my##ParamName->param() == 0) \
672  { \
673  unsigned bytes = my##ParamName->bytesNeeded(num); \
674  insertBytes(p, bytes); \
675  my##ParamName->setParam(num); \
676  } \
677  }
678 
679 // Defines the generic set and get methods utilizing a standard container type
680 // for a parameter which is a variable length array of some data type. Should
681 // not be used directly. Use one of the more type specific versions below.
682 // ClassName = the name of the message class
683 // ParamName = the name of the parameter
684 // ParamType = the type of each individual item in the array
685 // BitSize = the storage size of each element in the message (in bits, obviously)
686 // CtrType = the type of container to be accepted as input/output (e.g. set)
687 #define DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, CtrType) \
688  void ClassName::set##ParamName(const CtrType& container, \
689  DtResizeArrayFlag resizeFlag) \
690  { \
691  unsigned currNum = my##ParamName->numItems(); \
692  if(resizeFlag == DtResizeIfNeeded && container.size() != currNum) \
693  { \
694  unsigned currSize = currNum * BitSize/8; \
695  unsigned newSize = container.size() * BitSize/8; \
696  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
697  if(newSize > currSize) \
698  { \
699  insertBytes(begPtr + currSize, newSize - currSize); \
700  } \
701  else if(currSize > newSize) \
702  { \
703  deleteBytes(begPtr + newSize, currSize - newSize); \
704  } \
705  my##ParamName->setNumItems(container.size()); \
706  } \
707  my##ParamName->setParams(container); \
708  } \
709  void ClassName::get##ParamName(CtrType& container) const \
710  { \
711  my##ParamName->getParams(container); \
712  }
713 
714 // Defines the generic set and get methods utilizing a standard C array
715 // for a parameter which is a variable length array of some data type. Should
716 // not be used directly. Use one of the more type specific versions below.
717 // ClassName = the name of the message class
718 // ParamName = the name of the parameter
719 // ParamType = the type of each individual item in the array
720 // BitSize = the storage size of each element in the message (in bits, obviously)
721 #define DtDEFINE_ARRAY_PARAMETER_POINTER_METHODS(ClassName, ParamName, ParamType, BitSize) \
722  void ClassName::set##ParamName(const ParamType* buff, unsigned num, \
723  DtResizeArrayFlag resizeFlag) \
724  { \
725  unsigned currNum = my##ParamName->numItems(); \
726  if(resizeFlag == DtResizeIfNeeded && num != currNum) \
727  { \
728  unsigned currSize = currNum * BitSize/8; \
729  unsigned newSize = num * BitSize/8; \
730  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
731  if(newSize > currSize) \
732  { \
733  insertBytes(begPtr + currSize, newSize - currSize); \
734  } \
735  else if(currSize > newSize) \
736  { \
737  deleteBytes(begPtr + newSize, currSize - newSize); \
738  } \
739  my##ParamName->setNumItems(num); \
740  } \
741  my##ParamName->setParams(buff, num); \
742  } \
743  unsigned ClassName::get##ParamName(ParamType* buff) const \
744  { \
745  return my##ParamName->getParams(buff); \
746  }
747 
748 // Defines the generic set and get methods for a parameter which is a variable
749 // length array of some data type. Should not be used directly. Use one of the
750 // more type specific versions below.
751 // ClassName = the name of the message class
752 // ParamName = the name of the parameter
753 // ParamType = the type of each individual item in the array
754 // BitSize = the storage size of each element in the message (in bits, obviously)
755 #define DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, ParamType, BitSize) \
756  const char* ClassName::ParamName##Name = #ParamName; \
757  DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, std::set<ParamType>) \
758  DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, std::vector<ParamType>) \
759  DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, std::list<ParamType>) \
760  DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, std::deque<ParamType>) \
761  DtDEFINE_ARRAY_PARAMETER_POINTER_METHODS(ClassName, ParamName, ParamType, BitSize)
762 
763 // Defines the set and get methods for an array of unsigned integers.
764 // ClassName = the name of the message class
765 // ParamName = the name of the parameter
766 // BitSize = the storage size of each element in the message (in bits, obviously)
767 #define DtDEFINE_UNSIGNED_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
768  DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtU##BitSize, BitSize)
769 
770 // Defines the set and get methods for an array of integers.
771 // ClassName = the name of the message class
772 // ParamName = the name of the parameter
773 // BitSize = the storage size of each element in the message (in bits, obviously)
774 #define DtDEFINE_INT_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize)\
775  DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtInt##BitSize, BitSize)
776 
777 // Defines the set and get methods for an array of enumerations.
778 // ClassName = the name of the message class
779 // ParamName = the name of the parameter
780 // EnumType = the type of each individual item in the array
781 // BitSize = the storage size of each element in the message (in bits, obviously)
782 #define DtDEFINE_ENUMERATION_ARRAY_PARAMETER_METHODS(ClassName, ParamName, EnumType, BitSize)\
783  DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, EnumType, BitSize)
784 
785 // Defines the set and get methods for an array of booleans.
786 // ClassName = the name of the message class
787 // ParamName = the name of the parameter
788 #define DtDEFINE_BOOL_ARRAY_PARAMETER_METHODS(ClassName, ParamName)\
789  DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, bool, 8)
790 
791 // Defines the set and get methods for an array of floats.
792 // ClassName = the name of the message class
793 // ParamName = the name of the parameter
794 // BitSize = the storage size of each element in the message (in bits, obviously)
795 #define DtDEFINE_FLOAT_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize)\
796  DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtFloat##BitSize, BitSize)
797 
798 // Defines the set and get methods for a string.
799 // ClassName = the name of the message class
800 // ParamName = the name of the parameter
801 #define DtDEFINE_STRING_PARAMETER_METHODS(ClassName, ParamName) \
802  const char* ClassName::ParamName##Name = #ParamName; \
803  void ClassName::set##ParamName(const MAKRti::DtString& container, \
804  DtResizeArrayFlag resizeFlag) \
805  { \
806  unsigned currNum = my##ParamName->numItems(); \
807  if(resizeFlag == DtResizeIfNeeded && container.size() != currNum) \
808  { \
809  unsigned currSize = currNum; \
810  unsigned newSize = container.size() + 1; /* extra needed for '\0' */ \
811  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
812  if(newSize > currSize) \
813  { \
814  insertBytes(begPtr + currSize, newSize - currSize); \
815  } \
816  else if(currSize > newSize) \
817  { \
818  deleteBytes(begPtr + newSize, currSize - newSize); \
819  } \
820  my##ParamName->setNumItems(newSize); \
821  } \
822  my##ParamName->setParams(container); \
823  } \
824  void ClassName::get##ParamName(MAKRti::DtString& container) const \
825  { \
826  my##ParamName->getParams(container); \
827  } \
828  void ClassName::set##ParamName(const char* buff, unsigned num, \
829  DtResizeArrayFlag resizeFlag) \
830  { \
831  unsigned currNum = my##ParamName->numItems(); \
832  if(resizeFlag == DtResizeIfNeeded && num != currNum) \
833  { \
834  unsigned currSize = currNum; \
835  unsigned newSize = num; \
836  if(buff[num-1] != '\0') \
837  { \
838  ++newSize; \
839  } \
840  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
841  if(newSize > currSize) \
842  { \
843  insertBytes(begPtr + currSize, newSize - currSize); \
844  } \
845  else if(currSize > newSize) \
846  { \
847  deleteBytes(begPtr + newSize, currSize - newSize); \
848  } \
849  my##ParamName->setNumItems(newSize); \
850  } \
851  my##ParamName->setParams(buff, num); \
852  } \
853  unsigned ClassName::get##ParamName(char* buff) const \
854  { \
855  return my##ParamName->getParams(buff); \
856  }
857 
858 // Defines the set and get methods for a parameter which is an array of
859 // strings, utilizing a standard container type for input and output. Should
860 // not be used directly. Use DtDEFINE_STRING_ARRAY_PARAMETER_METHODS instead.
861 // ClassName = the name of the message class
862 // ParamName = the name of the parameter
863 // CtrType = the type of a container to be accepted as input/output (e.g. set)
864 #define DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, CtrType)\
865  void ClassName::set##ParamName(const CtrType& strings, \
866  DtResizeArrayFlag resizeFlag) \
867  { \
868  unsigned currSize = my##ParamName->numItems(); \
869  unsigned newSize =0; \
870  CtrType::const_iterator iter = strings.begin(); \
871  CtrType::const_iterator iterEnd = strings.end(); \
872  for(; iter != iterEnd; ++iter) \
873  { \
874  newSize += iter->size() + 1; \
875  } \
876  if(resizeFlag == DtResizeIfNeeded && newSize != currSize) \
877  { \
878  char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
879  if(newSize > currSize) \
880  { \
881  insertBytes(begPtr + currSize, \
882  newSize - currSize); \
883  } \
884  else if(currSize > newSize) \
885  { \
886  deleteBytes(begPtr + newSize, \
887  currSize - newSize); \
888  } \
889  my##ParamName->setNumItems(newSize); \
890  } \
891  my##ParamName->setSubStrings(strings); \
892  } \
893  void ClassName::get##ParamName(CtrType& strings) const \
894  { \
895  my##ParamName->getSubStrings(strings); \
896  }
897 
898 // Defines the set and get methods for a parameter which is an array of
899 // strings.
900 // ClassName = the name of the message class
901 // ParamName = the name of the parameter
902 #define DtDEFINE_STRING_ARRAY_PARAMETER_METHODS(ClassName, ParamName) \
903  const char* ClassName::ParamName##Name = #ParamName; \
904  DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::set<MAKRti::DtString>)\
905  DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::vector<MAKRti::DtString>)\
906  DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::list<MAKRti::DtString>)\
907  DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, std::deque<MAKRti::DtString>)
908 
909 
910 
911 // PARAMETER ADDITION MACROS
912 // These macros should be used within the addAllParameters() function of your
913 // new message class. The order parameters are added matters! You must order
914 // them in a way to ensure proper alignment. If you don't, the parameter
915 // classes will try to help you out by asserting in debug builds.
916 
917 // Adds an array parameter to the message.
918 // ParamName = the name of the parameter
919 // SizeParamName = the name of the parameter which stores the number of items
920 #define DtADD_ARRAY_PARAMETER(ParamName, SizeParamName) \
921  addParameter(my##ParamName = new ParamName##Type(ParamName##Name, my##SizeParamName));
922 
923 #endif

Document ID: Generated on Mon Jul 9 10:30:41 EDT 2018 from SVN revision 190224
Copyright © 2005-2018 VT MÄK Inc. All Rights Reserved (www.mak.com)