14 #ifndef DtRtiTemplateMsgArrayParams_H_
15 #define DtRtiTemplateMsgArrayParams_H_
18 #include <vlutil/vlString.h>
29 template<
typename ParamType,
typename NetParamType>
50 std::list<DtRtiBaseMsgParam*>::const_iterator pIter =
myArrayParams.begin();
51 std::list<DtRtiBaseMsgParam*>::const_iterator pEnd =
myArrayParams.end();
52 for(; pIter != pEnd; ++pIter)
54 bytes += ((*pIter)->elementSize() * num);
64 std::list<DtRtiBaseMsgParam*>::const_iterator pIter =
myArrayParams.begin();
67 p = (*pIter)->beginPtr();
74 std::list<DtRtiBaseMsgParam*>::iterator pIter =
myArrayParams.begin();
77 p = (*pIter)->beginPtr();
91 template<
typename ParamType,
typename ConvParamType,
typename NetParamType,
typename AllocatedMsgParamType>
115 *ptr =
static_cast<ConvParamType
>(val);
127 if(num <= myAllocatedNumParam->param())
134 for(
unsigned i = 0; i < num; ++i)
136 ptr[i] =
static_cast<ConvParamType
>(vals[i]);
145 template <
typename ParamContainerType>
156 typename ParamContainerType::const_iterator iter = container.begin();
157 typename ParamContainerType::const_iterator iterEnd = container.end();
158 for(
unsigned i = 0; iter != iterEnd; ++iter)
160 ptr[i++] =
static_cast<ConvParamType
>(*iter);
169 template <
typename ParamContainerType>
173 const NetParamType* ptr =
paramPtr();
174 for(
unsigned i = 0; i <
numItems; ++i)
176 container.insert(container.end(),
177 static_cast<ParamType
>(
static_cast<ConvParamType
>(ptr[i])));
186 const NetParamType* ptr =
paramPtr();
187 for(
unsigned i = 0; i <
numItems; ++i)
189 buff[i] =
static_cast<ParamType
>(
static_cast<ConvParamType
>(ptr[i]));
202 const NetParamType* ptr =
paramPtr();
203 val =
static_cast<ParamType
>(
static_cast<ConvParamType
>(ptr[0]));
216 const NetParamType* ptr =
paramPtr();
217 val =
static_cast<ParamType
>(
249 MAKRti::DtVerbose <<
name() <<
": " << std::endl;
253 MAKRti::DtVerbose <<
" " << val << std::endl;
256 MAKRti::DtVerbose <<
" " << val << std::endl;
261 MAKRti::DtVerbose <<
" Empty" << std::endl;
273 assert(prevBoundary == 0 || (prevBoundary %
sizeof(NetParamType)) == 0);
281 const NetParamType*
paramPtr()
const {
return reinterpret_cast<const NetParamType*
>(
beginPtr()); }
300 template<
typename AllocatedMsgParamType>
313 bool addParams(
const char* str,
unsigned size)
316 bool nullNeeded =
false;
319 if(str[size-1] !=
'\0')
324 if(
myNumUsed + size <= myAllocatedNumParam->param())
330 memcpy(ptr, str, size);
344 bool addParams(
const MAKRti::DtString& str)
346 return addParams(str.c_str(), str.size()+1);
354 return addParams(str, size);
362 return addParams(str.c_str(), str.size()+1);
366 template <
typename ParamContainerType>
367 bool setSubStrings(
const ParamContainerType& container)
374 typename ParamContainerType::const_iterator iter = container.begin();
375 typename ParamContainerType::const_iterator iterEnd = container.end();
376 for(; iter != iterEnd; ++iter)
380 memcpy(curr +
myNumUsed, iter->c_str(), iter->size());
382 curr[myNumUsed++] =
'\0';
399 str = MAKRti::DtString(ptr, size);
408 memcpy(buff, ptr, size);
413 template <
typename ParamContainerType>
414 void getSubStrings(ParamContainerType& container)
const
420 MAKRti::DtString currStr(curr);
421 size -= currStr.size() + 1;
422 container.insert(container.end(), currStr);
423 curr += currStr.size() + 1;
453 MAKRti::DtString str;
455 MAKRti::DtVerbose <<
name() <<
": " << str << std::endl;
466 assert(prevBoundary == 0 || (prevBoundary %
sizeof(
char)) == 0);
513 #define DtDECLARE_ARRAY_SIZE_PARAMETER_METHODS(ParamName, BitSize) \
514 DtDECLARE_PARAMETER_METHODS(ParamName, MAKRti::DtU##BitSize) \
516 typedef DtRtiArraySizeMsgParam<MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize> ParamName##Type; \
517 ParamName##Type* my##ParamName; \
519 void reserveSpaceFor##ParamName(unsigned num);
527 #define DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, CtrType) \
529 void set##ParamName(const CtrType& val, \
530 DtResizeArrayFlag resizeFlag = DtResizeIfNeeded); \
531 void get##ParamName(CtrType&) const;
539 #define DtDECLARE_ARRAY_PARAMETER_POINTER_METHODS(ParamName, ParamType) \
541 void set##ParamName(const ParamType* inputBuff, unsigned numItems, \
542 DtResizeArrayFlag resizeFlag = DtResizeIfNeeded); \
543 unsigned get##ParamName(ParamType* outputBuff) const;
551 #define DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, ParamType) \
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)
565 #define DtDECLARE_UNSIGNED_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
566 DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtU##BitSize) \
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;
577 #define DtDECLARE_INT_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
578 DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtInt##BitSize) \
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;
588 #define DtDECLARE_BOOL_ARRAY_PARAMETER_METHODS(ParamName, CountBitSize) \
589 DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, bool) \
591 typedef DtRtiArrayMsgParam<bool, MAKRti::DtU8, MAKRti::DtNetU8, \
592 DtRtiArraySizeMsgParam<MAKRti::DtU##CountBitSize, MAKRti::DtNetU##CountBitSize> > ParamName##Type; \
593 ParamName##Type* my##ParamName;
601 #define DtDECLARE_ENUMERATION_ARRAY_PARAMETER_METHODS(ParamName, EnumType, BitSize, CountBitSize)\
602 DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, EnumType) \
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;
613 #define DtDECLARE_FLOAT_ARRAY_PARAMETER_METHODS(ParamName, BitSize, CountBitSize)\
614 DtDECLARE_ARRAY_PARAMETER_METHODS(ParamName, MAKRti::DtFloat##BitSize) \
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;
623 #define DtDECLARE_STRING_PARAMETER_METHODS(ParamName, LengthBitSize) \
625 static const char* ParamName##Name; \
626 DtDECLARE_ARRAY_PARAMETER_CONTAINER_METHODS(ParamName, MAKRti::DtString) \
627 DtDECLARE_ARRAY_PARAMETER_POINTER_METHODS(ParamName, char) \
629 typedef DtRtiArrayMsgParam<char, char, char, \
630 DtRtiArraySizeMsgParam<MAKRti::DtU##LengthBitSize, MAKRti::DtNetU##LengthBitSize> > ParamName##Type; \
631 ParamName##Type* my##ParamName;
638 #define DtDECLARE_STRING_ARRAY_PARAMETER_METHODS(ParamName, LengthBitSize) \
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>) \
646 typedef DtRtiArrayMsgParam<char, char, char, \
647 DtRtiArraySizeMsgParam<MAKRti::DtU##LengthBitSize, MAKRti::DtNetU##LengthBitSize> > ParamName##Type; \
648 ParamName##Type* my##ParamName;
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) \
670 void* p = my##ParamName->firstArrayPtr(); \
671 if(p && my##ParamName->param() == 0) \
673 unsigned bytes = my##ParamName->bytesNeeded(num); \
674 insertBytes(p, bytes); \
675 my##ParamName->setParam(num); \
687 #define DtDEFINE_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, ParamType, BitSize, CtrType) \
688 void ClassName::set##ParamName(const CtrType& container, \
689 DtResizeArrayFlag resizeFlag) \
691 unsigned currNum = my##ParamName->numItems(); \
692 if(resizeFlag == DtResizeIfNeeded && container.size() != currNum) \
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) \
699 insertBytes(begPtr + currSize, newSize - currSize); \
701 else if(currSize > newSize) \
703 deleteBytes(begPtr + newSize, currSize - newSize); \
705 my##ParamName->setNumItems(container.size()); \
707 my##ParamName->setParams(container); \
709 void ClassName::get##ParamName(CtrType& container) const \
711 my##ParamName->getParams(container); \
721 #define DtDEFINE_ARRAY_PARAMETER_POINTER_METHODS(ClassName, ParamName, ParamType, BitSize) \
722 void ClassName::set##ParamName(const ParamType* buff, unsigned num, \
723 DtResizeArrayFlag resizeFlag) \
725 unsigned currNum = my##ParamName->numItems(); \
726 if(resizeFlag == DtResizeIfNeeded && num != currNum) \
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) \
733 insertBytes(begPtr + currSize, newSize - currSize); \
735 else if(currSize > newSize) \
737 deleteBytes(begPtr + newSize, currSize - newSize); \
739 my##ParamName->setNumItems(num); \
741 my##ParamName->setParams(buff, num); \
743 unsigned ClassName::get##ParamName(ParamType* buff) const \
745 return my##ParamName->getParams(buff); \
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)
767 #define DtDEFINE_UNSIGNED_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
768 DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtU##BitSize, BitSize)
774 #define DtDEFINE_INT_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize)\
775 DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtInt##BitSize, BitSize)
782 #define DtDEFINE_ENUMERATION_ARRAY_PARAMETER_METHODS(ClassName, ParamName, EnumType, BitSize)\
783 DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, EnumType, BitSize)
788 #define DtDEFINE_BOOL_ARRAY_PARAMETER_METHODS(ClassName, ParamName)\
789 DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, bool, 8)
795 #define DtDEFINE_FLOAT_ARRAY_PARAMETER_METHODS(ClassName, ParamName, BitSize)\
796 DtDEFINE_ARRAY_PARAMETER_METHODS(ClassName, ParamName, MAKRti::DtFloat##BitSize, BitSize)
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) \
806 unsigned currNum = my##ParamName->numItems(); \
807 if(resizeFlag == DtResizeIfNeeded && container.size() != currNum) \
809 unsigned currSize = currNum; \
810 unsigned newSize = container.size() + 1; \
811 char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
812 if(newSize > currSize) \
814 insertBytes(begPtr + currSize, newSize - currSize); \
816 else if(currSize > newSize) \
818 deleteBytes(begPtr + newSize, currSize - newSize); \
820 my##ParamName->setNumItems(newSize); \
822 my##ParamName->setParams(container); \
824 void ClassName::get##ParamName(MAKRti::DtString& container) const \
826 my##ParamName->getParams(container); \
828 void ClassName::set##ParamName(const char* buff, unsigned num, \
829 DtResizeArrayFlag resizeFlag) \
831 unsigned currNum = my##ParamName->numItems(); \
832 if(resizeFlag == DtResizeIfNeeded && num != currNum) \
834 unsigned currSize = currNum; \
835 unsigned newSize = num; \
836 if(buff[num-1] != '\0') \
840 char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
841 if(newSize > currSize) \
843 insertBytes(begPtr + currSize, newSize - currSize); \
845 else if(currSize > newSize) \
847 deleteBytes(begPtr + newSize, currSize - newSize); \
849 my##ParamName->setNumItems(newSize); \
851 my##ParamName->setParams(buff, num); \
853 unsigned ClassName::get##ParamName(char* buff) const \
855 return my##ParamName->getParams(buff); \
864 #define DtDEFINE_STRING_ARRAY_PARAMETER_CONTAINER_METHODS(ClassName, ParamName, CtrType)\
865 void ClassName::set##ParamName(const CtrType& strings, \
866 DtResizeArrayFlag resizeFlag) \
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) \
874 newSize += iter->size() + 1; \
876 if(resizeFlag == DtResizeIfNeeded && newSize != currSize) \
878 char* begPtr = static_cast<char*>(my##ParamName->beginPtr()); \
879 if(newSize > currSize) \
881 insertBytes(begPtr + currSize, \
882 newSize - currSize); \
884 else if(currSize > newSize) \
886 deleteBytes(begPtr + newSize, \
887 currSize - newSize); \
889 my##ParamName->setNumItems(newSize); \
891 my##ParamName->setSubStrings(strings); \
893 void ClassName::get##ParamName(CtrType& strings) const \
895 my##ParamName->getSubStrings(strings); \
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>)
920 #define DtADD_ARRAY_PARAMETER(ParamName, SizeParamName) \
921 addParameter(my##ParamName = new ParamName##Type(ParamName##Name, my##SizeParamName));