9 #ifndef DtHlaStateDecoder_H_
10 #define DtHlaStateDecoder_H_
51 typedef void (*DtAttributeDecoder) (
53 const RTI::AttributeHandleValuePairSet& avlist,
54 unsigned long pairSetIndex);
61 DtAttributeDecoder addDecoder(RTI::AttributeHandle h,
62 DtAttributeDecoder func);
63 DtAttributeDecoder removeDecoder(RTI::AttributeHandle h);
71 DtAttributeDecoder addDecoder(
char*
attrName,
72 DtAttributeDecoder func,
bool complain =
true);
73 DtAttributeDecoder removeDecoder(
char*
attrName,
bool complain =
true);
76 virtual DtAttributeDecoder decoder(
const RTI::AttributeHandle &handle)
const;
83 virtual RTI::ObjectClassHandle objectClassHandle()
const;
100 static inline char* decodingBuffer(
int length);
103 static char* attributeData(
const RTI::AttributeHandleValuePairSet& attrs,
104 int index, RTI::ULong& length);
111 static char* attributeData(
112 const RTI::AttributeHandleValuePairSet& attrs,
int index, RTI::ULong& length,
113 unsigned int expectedDataSize,
char*
attrName);
117 static DtNetEventId* eventIdAttributeData(
const RTI::AttributeHandleValuePairSet& attrs,
126 virtual void decodeAttribute(
128 const RTI::AttributeHandleValuePairSet& attrs,
129 unsigned long pairSetIndex)
const;
165 AttributeHandleDecoderMap::const_iterator pos =
myDecoderList.find(handle);
179 const RTI::AttributeHandleValuePairSet& attrs,
int index, RTI::ULong& length)
184 dataPtr = attrs.getValuePointer(index, length);
188 length = attrs.getValueLength(index);
192 attrs.getValue(index, dataPtr, length);
199 const RTI::AttributeHandleValuePairSet& attrs,
int index, RTI::ULong& length,
200 unsigned int expectedDataSize,
char*
attrName)
202 char* outDataPtr = 0;
205 outDataPtr = attrs.getValuePointer(index, length);
209 length = attrs.getValueLength(index);
210 if (length > 0 && length >= expectedDataSize)
213 attrs.getValue(index, outDataPtr, length);
217 if (length != expectedDataSize)
219 if (length < expectedDataSize)
221 DtWarn(
"Cannot decode attribute %s.\n"
222 "Size of data (%d) is smaller than expected (%d).\n",
223 attrName, length, expectedDataSize);
229 DtVerbose(
"When decoding attribute %s,\n"
230 "found size of data (%d) is larger than expected (%d).\n",
231 attrName, length, expectedDataSize);
239 const RTI::AttributeHandleValuePairSet& attrs,
int index)
241 RTI::ULong length = 0;
243 length = attrs.getValueLength(index);
247 attrs.getValue(index, dataPtr, length);
256 #define DtADD_ATTR_DECODER(attrName) \
257 addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName);
260 #define DtADD_ATTR_DECODER_QUIET(attrName) \
261 addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName, false);
267 #define DtDECLARE_ATTR_DECODER(stateRepClass, attrName) \
268 static void decode##attrName(stateRepClass* stateRep, \
269 const RTI::AttributeHandleValuePairSet& attrs, int pairSetIndex)
279 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
280 decClass, stateRepClass, attrName, netType, mutator, castExpr) \
281 void decClass::decode##attrName( \
282 stateRepClass* stateRep, \
283 const RTI::AttributeHandleValuePairSet& attrs, \
286 RTI::ULong length = 0; \
287 netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
290 stateRep->mutator(castExpr *netValPtr); \
301 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_SET( \
302 decClass, stateRepClass, attrName, netType, castExpr) \
303 DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST( \
304 decClass, stateRepClass, attrName, netType, set##attrName, castExpr)
312 #define DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
313 decClass, stateRepClass, attrName, netType, mutator) \
314 void decClass::decode##attrName( \
315 stateRepClass* stateRep, \
316 const RTI::AttributeHandleValuePairSet& attrs, \
319 RTI::ULong length = 0; \
320 netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
323 stateRep->mutator(*netValPtr); \
333 #define DtDEFINE_SIMPLE_ATTR_DECODER_SET( \
334 decClass, stateRepClass, attrName, netType) \
335 DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR( \
336 decClass, stateRepClass, attrName, netType, set##attrName)
346 #define DtDEFINE_SIMPLE_ATTR_DECODER_WITH_CAST_AND_PARAM( \
347 decClass, stateRepClass, attrName, netType, mutator, param, castExpr) \
348 void decClass::decode##attrName( \
349 stateRepClass* stateRep, \
350 const RTI::AttributeHandleValuePairSet& attrs, \
353 RTI::ULong length = 0; \
354 netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
357 stateRep->mutator(param, castExpr *netValPtr); \
361 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_DECODER( \
362 decClass, stateRepClass, attrName, mutator) \
363 void decClass::decode##attrName( \
364 stateRepClass* stateRep, \
365 const RTI::AttributeHandleValuePairSet& attrs, \
368 RTI::ULong length = 0; \
369 DtGlobalObjectDesignator objName = (char*) attrs.getValuePointer(pairSetIndex, length); \
370 stateRep->mutator(objName); \
377 #define DtDEFINE_SIMPLE_ATTR_DECODER_BUFF(decClass, stateRepClass, \
379 void decClass::decode##attrName( \
380 stateRepClass* stateRep, \
381 const RTI::AttributeHandleValuePairSet& attrs, \
384 RTI::ULong length = 0; \
385 char* buff = attributeData(attrs, index, length); \
388 stateRep->mutator(buff, length); \
393 #define DtDEFINE_SIMPLE_ATTR_DECODER( \
394 decClass, stateRepClass, attrName, netType, mutator) \
395 DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR(decClass, stateRepClass, \
396 attrName, netType, mutator)