![]() |
VR-Link API Documentation for DIS
|
00001 /********************************************************************* 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 *********************************************************************/ 00005 00008 00009 #ifndef DtHlaStateDecoder_H_ 00010 #define DtHlaStateDecoder_H_ 00011 00012 #if DtHLA 00013 00014 00015 #include <vlutil/vlMachineTypes.h> 00016 #include <vlpi/bufferMgr.h> 00017 #include "rtiNamespace.h" 00018 #include "rtiCompatibility.h" 00019 #include <map> 00020 00021 class DT_DLL_VL DtExerciseConn; 00022 class DT_DLL_VL DtObjClassDesc; 00023 class DT_DLL_VL DtStateRepository; 00024 class DT_DLL_VL DtStateMsg; 00025 00026 00030 class DT_DLL_VL DtHlaStateDecoder 00031 { 00032 public: 00033 00035 DtHlaStateDecoder( 00036 DtExerciseConn* exConn, 00037 DtObjClassDesc* classDesc); 00038 00040 virtual ~DtHlaStateDecoder(); 00041 00043 DtHlaStateDecoder(const DtHlaStateDecoder& orig); 00044 00046 DtHlaStateDecoder& operator=(const DtHlaStateDecoder& orig); 00047 00049 typedef void (*DtAttributeDecoder) ( 00050 DtStateRepository* stateRep, 00051 const RTI::AttributeHandleValuePairSet& avlist, 00052 unsigned long pairSetIndex); 00053 00059 DtAttributeDecoder addDecoder(RTI::AttributeHandle h, 00060 DtAttributeDecoder func); 00061 DtAttributeDecoder removeDecoder(RTI::AttributeHandle h); 00062 00069 DtAttributeDecoder addDecoder(char* attrName, 00070 DtAttributeDecoder func, bool complain = true); 00071 DtAttributeDecoder removeDecoder(char* attrName, bool complain = true); 00072 00074 virtual DtAttributeDecoder decoder(const RTI::AttributeHandle &handle) const; 00075 00077 virtual void decode(const DtStateMsg& msg, 00078 DtStateRepository* stateRep) const ; 00079 00081 virtual RTI::ObjectClassHandle objectClassHandle() const; 00082 00084 virtual DtHlaStateDecoder* clone() const; 00085 00090 virtual DtHlaStateDecoder* clone(DtObjClassDesc* classDesc) const; 00091 00092 public: 00093 00098 static inline char* decodingBuffer(int length); 00099 00100 protected: 00101 00104 virtual void decodeAttribute( 00105 DtStateRepository* stateRep, 00106 const RTI::AttributeHandleValuePairSet& attrs, 00107 unsigned long pairSetIndex) const; 00108 00109 virtual void copyDecFuncs( const DtHlaStateDecoder& orig); 00110 protected: 00111 00112 typedef std::map<RTI::AttributeHandle, DtAttributeDecoder> AttributeHandleDecoderMap; 00113 typedef std::map<RTI::AttributeHandle, bool> AttributeHandleBoolMap; 00114 00115 protected: 00116 00117 DtExerciseConn* myExConn; 00118 DtObjClassDesc* myClassDesc; 00119 RTI::ObjectClassHandle myHandle; 00120 00121 00124 AttributeHandleDecoderMap myDecoderList; 00125 00126 private: 00127 00131 mutable AttributeHandleBoolMap myMutableReportedWarning; 00132 00133 }; 00134 00135 inline RTI::ObjectClassHandle DtHlaStateDecoder::objectClassHandle() const 00136 { 00137 return myHandle; 00138 } 00139 00140 inline DtHlaStateDecoder::DtAttributeDecoder 00141 DtHlaStateDecoder::decoder(const RTI::AttributeHandle &handle) const 00142 { 00143 AttributeHandleDecoderMap::const_iterator pos = myDecoderList.find(handle); 00144 if (pos != myDecoderList.end()) 00145 { 00146 return pos->second; 00147 } 00148 return 0; 00149 }; 00150 00151 inline char* DtHlaStateDecoder::decodingBuffer(int length) 00152 { 00153 return DtDecodingBuffer(length); 00154 } 00155 00158 #define DtADD_ATTR_DECODER(attrName) \ 00159 addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName); 00160 00162 #define DtADD_ATTR_DECODER_QUIET(attrName) \ 00163 addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName, false); 00164 00168 00169 #define DtDECLARE_ATTR_DECODER(stateRepClass, attrName) \ 00170 static void decode##attrName(stateRepClass* stateRep, \ 00171 const RTI::AttributeHandleValuePairSet& attrs, int pairSetIndex) 00172 00173 00174 00180 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \ 00181 decClass, stateRepClass, attrName, netType, mutator, castExpr) \ 00182 void decClass::decode##attrName( \ 00183 stateRepClass* stateRep, \ 00184 const RTI::AttributeHandleValuePairSet& attrs, \ 00185 int pairSetIndex) \ 00186 { \ 00187 RTI::ULong length = attrs.getValueLength(pairSetIndex); \ 00188 netType netVal; \ 00189 if (length > sizeof(netType)) \ 00190 { \ 00191 DtWarn("Size of value decoded from RTI update for attribute %s (%d)\n", \ 00192 #attrName, length); \ 00193 DtWarn(" is larger than size of %s (%d)\n", #netType, sizeof(netType)); \ 00194 return; \ 00195 } \ 00196 attrs.getValue(pairSetIndex, (char*) &netVal, length); \ 00197 stateRep->mutator(castExpr netVal); \ 00198 } 00199 00200 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_DECODER( \ 00201 decClass, stateRepClass, attrName, mutator) \ 00202 void decClass::decode##attrName( \ 00203 stateRepClass* stateRep, \ 00204 const RTI::AttributeHandleValuePairSet& attrs, \ 00205 int pairSetIndex) \ 00206 { \ 00207 RTI::ULong length = 0; \ 00208 DtGlobalObjectDesignator objName = (char*) attrs.getValuePointer(pairSetIndex, length); \ 00209 stateRep->mutator(objName); \ 00210 } 00211 00212 #define DtDEFINE_SIMPLE_ATTR_DECODER( \ 00213 decClass, stateRepClass, attrName, netType, mutator) \ 00214 DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST(decClass, stateRepClass, \ 00215 attrName, netType, mutator, (netType)) 00216 00217 #endif 00218 #endif 00219