VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
hlaStateDecoder.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 1992-2010 VT MAK
3 ** All rights reserved.
4 *********************************************************************/
5 
8 
9 #ifndef DtHlaStateDecoder_H_
10 #define DtHlaStateDecoder_H_
11 
12 #if DtHLA
13 
14 
15 #include <vlutil/vlMachineTypes.h>
16 #include <vlutil/vlPrint.h>
17 #include <vlpi/bufferMgr.h>
18 #include "rtiNamespace.h"
19 #include "rtiCompatibility.h"
20 #include <map>
21 
23 class DT_DLL_VL DtObjClassDesc;
25 class DT_DLL_VL DtStateMsg;
27 
28 
32 class DT_DLL_VL DtHlaStateDecoder
33 {
34 public:
35 
37  DtHlaStateDecoder(
38  DtExerciseConn* exConn,
39  DtObjClassDesc* classDesc);
40 
42  virtual ~DtHlaStateDecoder();
43 
45  DtHlaStateDecoder(const DtHlaStateDecoder& orig);
46 
48  DtHlaStateDecoder& operator=(const DtHlaStateDecoder& orig);
49 
51  typedef void (*DtAttributeDecoder) (
52  DtStateRepository* stateRep,
53  const RTI::AttributeHandleValuePairSet& avlist,
54  unsigned long pairSetIndex);
55 
61  DtAttributeDecoder addDecoder(RTI::AttributeHandle h,
62  DtAttributeDecoder func);
63  DtAttributeDecoder removeDecoder(RTI::AttributeHandle h);
64 
71  DtAttributeDecoder addDecoder(char* attrName,
72  DtAttributeDecoder func, bool complain = true);
73  DtAttributeDecoder removeDecoder(char* attrName, bool complain = true);
74 
76  virtual DtAttributeDecoder decoder(const RTI::AttributeHandle &handle) const;
77 
79  virtual void decode(const DtStateMsg& msg,
80  DtStateRepository* stateRep) const ;
81 
83  virtual RTI::ObjectClassHandle objectClassHandle() const;
84 
86  virtual DtHlaStateDecoder* clone() const;
87 
92  virtual DtHlaStateDecoder* clone(DtObjClassDesc* classDesc) const;
93 
94 public:
95 
100  static inline char* decodingBuffer(int length);
101 
103  static char* attributeData(const RTI::AttributeHandleValuePairSet& attrs,
104  int index, RTI::ULong& length);
105 
111  static char* attributeData(
112  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length,
113  unsigned int expectedDataSize, char* attrName);
114 
117  static DtNetEventId* eventIdAttributeData(const RTI::AttributeHandleValuePairSet& attrs,
118  int index);
119 
120  static bool theUseGetValuePointer;
121 
122 protected:
123 
126  virtual void decodeAttribute(
127  DtStateRepository* stateRep,
128  const RTI::AttributeHandleValuePairSet& attrs,
129  unsigned long pairSetIndex) const;
130 
131  virtual void copyDecFuncs( const DtHlaStateDecoder& orig);
132 protected:
133 
134  typedef std::map<RTI::AttributeHandle, DtAttributeDecoder> AttributeHandleDecoderMap;
135  typedef std::map<RTI::AttributeHandle, bool> AttributeHandleBoolMap;
136 
137 protected:
138 
139  DtExerciseConn* myExConn;
140  DtObjClassDesc* myClassDesc;
141  RTI::ObjectClassHandle myHandle;
142 
143 
146  AttributeHandleDecoderMap myDecoderList;
147 
148 private:
149 
153  mutable AttributeHandleBoolMap myMutableReportedWarning;
154 
155 };
156 
157 inline RTI::ObjectClassHandle DtHlaStateDecoder::objectClassHandle() const
158 {
159  return myHandle;
160 }
161 
162 inline DtHlaStateDecoder::DtAttributeDecoder
163 DtHlaStateDecoder::decoder(const RTI::AttributeHandle &handle) const
164 {
165  AttributeHandleDecoderMap::const_iterator pos = myDecoderList.find(handle);
166  if (pos != myDecoderList.end())
167  {
168  return pos->second;
169  }
170  return 0;
171 };
172 
173 inline char* DtHlaStateDecoder::decodingBuffer(int length)
174 {
175  return DtDecodingBuffer(length);
176 }
177 
178 inline char* DtHlaStateDecoder::attributeData(
179  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length)
180 {
181  char* dataPtr = 0;
182  if (theUseGetValuePointer)
183  {
184  dataPtr = attrs.getValuePointer(index, length);
185  }
186  else
187  {
188  length = attrs.getValueLength(index);
189  if (length > 0)
190  {
191  dataPtr = decodingBuffer(length);
192  attrs.getValue(index, dataPtr, length);
193  }
194  }
195  return dataPtr;
196 }
197 
198 inline char* DtHlaStateDecoder::attributeData(
199  const RTI::AttributeHandleValuePairSet& attrs, int index, RTI::ULong& length,
200  unsigned int expectedDataSize, char* attrName)
201 {
202  char* outDataPtr = 0;
203  if (theUseGetValuePointer)
204  {
205  outDataPtr = attrs.getValuePointer(index, length);
206  }
207  else
208  {
209  length = attrs.getValueLength(index);
210  if (length > 0 && length >= expectedDataSize)
211  {
212  outDataPtr = decodingBuffer(length);
213  attrs.getValue(index, outDataPtr, length);
214  }
215  }
216 
217  if (length != expectedDataSize)
218  {
219  if (length < expectedDataSize)
220  {
221  DtWarn("Cannot decode attribute %s.\n"
222  "Size of data (%d) is smaller than expected (%d).\n",
223  attrName, length, expectedDataSize);
224  length = 0;
225  outDataPtr = 0;
226  }
227  else if (length > expectedDataSize && DtNotifyLevel >= DtNlVerbose)
228  {
229  DtVerbose("When decoding attribute %s,\n"
230  "found size of data (%d) is larger than expected (%d).\n",
231  attrName, length, expectedDataSize);
232  }
233  }
234 
235  return outDataPtr;
236 }
237 
238 inline DtNetEventId* DtHlaStateDecoder::eventIdAttributeData(
239  const RTI::AttributeHandleValuePairSet& attrs, int index)
240 {
241  RTI::ULong length = 0;
242  char* dataPtr = 0;
243  length = attrs.getValueLength(index);
244  if (length > 0)
245  {
246  dataPtr = decodingBuffer(length+1);
247  attrs.getValue(index, dataPtr, length);
248  dataPtr[length] = 0;
249  }
250 
251  return (DtNetEventId*)dataPtr;
252 }
253 
256 #define DtADD_ATTR_DECODER(attrName) \
257  addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName);
258 
260 #define DtADD_ATTR_DECODER_QUIET(attrName) \
261  addDecoder((char *)#attrName, (DtAttributeDecoder) decode##attrName, false);
262 
266 
267 #define DtDECLARE_ATTR_DECODER(stateRepClass, attrName) \
268  static void decode##attrName(stateRepClass* stateRep, \
269  const RTI::AttributeHandleValuePairSet& attrs, int pairSetIndex)
270 
271 
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, \
284  int index) \
285 { \
286  RTI::ULong length = 0; \
287  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
288  if (netValPtr) \
289  { \
290  stateRep->mutator(castExpr *netValPtr); \
291  } \
292 }
293 
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)
305 
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, \
317  int index) \
318 { \
319  RTI::ULong length = 0; \
320  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
321  if (netValPtr) \
322  { \
323  stateRep->mutator(*netValPtr); \
324  } \
325 }
326 
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)
337 
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, \
351  int index) \
352 { \
353  RTI::ULong length = 0; \
354  netType* netValPtr = (netType*)attributeData(attrs, index, length, sizeof(netType), #attrName); \
355  if (netValPtr) \
356  { \
357  stateRep->mutator(param, castExpr *netValPtr); \
358  } \
359 }
360 
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, \
366  int pairSetIndex) \
367 { \
368  RTI::ULong length = 0; \
369  DtGlobalObjectDesignator objName = (char*) attrs.getValuePointer(pairSetIndex, length); \
370  stateRep->mutator(objName); \
371 }
372 
377 #define DtDEFINE_SIMPLE_ATTR_DECODER_BUFF(decClass, stateRepClass, \
378  attrName, mutator) \
379 void decClass::decode##attrName( \
380  stateRepClass* stateRep, \
381  const RTI::AttributeHandleValuePairSet& attrs, \
382  int index) \
383 { \
384  RTI::ULong length = 0; \
385  char* buff = attributeData(attrs, index, length); \
386  if (length > 0) \
387  { \
388  stateRep->mutator(buff, length); \
389  } \
390 }
391 
393 #define DtDEFINE_SIMPLE_ATTR_DECODER( \
394  decClass, stateRepClass, attrName, netType, mutator) \
395  DtDEFINE_SIMPLE_ATTR_DECODER_MUTATOR(decClass, stateRepClass, \
396  attrName, netType, mutator)
397 
398 #endif
399 #endif
400 

Document ID: Generated on Fri May 15 06:36:13 EDT 2015 from SVN revision 153263
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)