VR-Link API Documentation for HLA 1516
hStateEncoder.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 DtHlaStateEncoder_H_
10 #define DtHlaStateEncoder_H_
11 
12 #if DtHLA
13 
14 
15 #include <vlutil/vlMachineTypes.h>
16 
17 #include "rtiNamespace.h"
18 #include "rtiCompatibility.h"
19 #include <map>
20 
24 class DT_DLL_VL DtStateMsg;
25 
30 {
31 public:
32 
35  DtObjClassDesc* classDesc);
36 
38  virtual ~DtHlaStateEncoder();
39 
42 
44  DtHlaStateEncoder& operator=(const DtHlaStateEncoder& orig);
45 
49  typedef void (*DtAttributeEncoder)(
50  const DtStateRepository& stateRep,
52  RTI::AttributeHandle handle);
53 
55  typedef bool (*DtAttributeChecker)(
56  const DtStateRepository& stateRep,
57  const DtStateRepository& asSeenByRemote);
58 
64  DtAttributeEncoder addEncoder(RTI::AttributeHandle hand,
65  DtAttributeEncoder func);
66  DtAttributeEncoder removeEncoder(RTI::AttributeHandle hand);
67 
74  DtAttributeEncoder addEncoder(char* name,
75  DtAttributeEncoder func, bool complain = true);
76  DtAttributeEncoder removeEncoder(char* name, bool complain = true);
77 
83  DtAttributeChecker addChecker(RTI::AttributeHandle hand,
84  DtAttributeChecker func);
85  DtAttributeChecker removeChecker(RTI::AttributeHandle hand);
86 
93  DtAttributeChecker addChecker(char* name,
94  DtAttributeChecker func, bool complain = true);
95  DtAttributeChecker removeChecker(char* name, bool complain = true);
96 
98  virtual DtAttributeEncoder encoder(const RTI::AttributeHandle &handle) ;
99 
101  virtual DtAttributeChecker checker(const RTI::AttributeHandle &handle) ;
102 
110  virtual void encode(const DtStateRepository& stateRep,
111  const DtStateRepository& asSeenByRemote,
112  const RTI::AttributeHandleSet& neededAttrs,
113  const RTI::AttributeHandleSet& includeThese,
114  DtStateMsg* msg);
115 
117  virtual RTI::ObjectClassHandle objectClassHandle();
118 
123  virtual DtHlaStateEncoder* clone(DtObjClassDesc* classDesc) const;
124 
126  virtual DtHlaStateEncoder* clone() const;
127 
128 public:
129 
133  static bool trueChecker(const DtStateRepository& stateRep,
134  const DtStateRepository& asSeenByRemote);
135 
139  static bool falseChecker(const DtStateRepository& stateRep,
140  const DtStateRepository& asSeenByRemote);
141 
142 protected:
143 
146  RTI::ObjectClassHandle myHandle;
147 
150  std::map<RTI::AttributeHandle,DtAttributeEncoder> myEncoderList;
151  std::map<RTI::AttributeHandle,DtAttributeChecker> myCheckerList;
152 
153 
156  std::map<RTI::AttributeHandle,bool> myReportedWarning;
157 };
158 
159 inline RTI::ObjectClassHandle DtHlaStateEncoder::objectClassHandle()
160 {
161  return myHandle;
162 }
163 
165  DtHlaStateEncoder::encoder(const RTI::AttributeHandle &hand)
166 {
167  return myEncoderList[hand];
168 };
169 
171  DtHlaStateEncoder::checker(const RTI::AttributeHandle &hand)
172 {
173  return myCheckerList[hand];
174 };
175 
178 #define DtADD_ATTR_ENCODER(attrName) \
179  addEncoder((char *)#attrName, (DtAttributeEncoder) encode##attrName)
180 
182 #define DtADD_ATTR_ENCODER_QUIET(attrName) \
183  addEncoder((char *)#attrName, (DtAttributeEncoder) encode##attrName, false)
184 
188 #define DtADD_ATTR_CHECKER(attrName) \
189  addChecker((char *)#attrName, (DtAttributeChecker) need##attrName)
190 
192 #define DtADD_ATTR_CHECKER_QUIET(attrName) \
193  addChecker((char *)#attrName, (DtAttributeChecker) need##attrName, false)
194 
198 #define DtDECLARE_ATTR_ENCODER(stateRepClass, attrName) \
199  static void encode##attrName(const stateRepClass& rep, \
200  RTI::AttributeHandleValuePairSet* attrs, \
201  RTI::AttributeHandle attrHandle)
202 
205 #define DtDECLARE_ATTR_CHECKER(stateRepClass, attrName) \
206  static bool need##attrName(const stateRepClass& stateRep, \
207  const stateRepClass& asSeenByRemote)
208 
214 #define DtDEFINE_SIMPLE_ATTR_ENCODER( \
215  encClass, stateRepClass, attrName, netType, inspector) \
216 void encClass::encode##attrName(const stateRepClass& rep, \
217  RTI::AttributeHandleValuePairSet* attrs, \
218  RTI::AttributeHandle attrHandle) \
219 { \
220  netType netVal; \
221  netVal = rep.inspector(); \
222  attrs->add(attrHandle, (char*) &netVal, sizeof(netType)); \
223 }
224 
225 #define DtDEFINE_SIMPLE_GLOBAL_OBJECT_DESIGNATOR_ATTR_ENCODER( \
226  encClass, stateRepClass, attrName, inspector) \
227 void encClass::encode##attrName(const stateRepClass& rep, \
228  RTI::AttributeHandleValuePairSet* attrs, \
229  RTI::AttributeHandle attrHandle) \
230 { \
231  DtGlobalObjectDesignator netVal = rep.inspector(); \
232  attrs->add(attrHandle, (char*) netVal.string(), netVal.length()+1); \
233 }
234 
240 #define DtDEFINE_SIMPLE_ATTR_CHECKER( \
241  encClass, stateRepClass, attrName, inspector) \
242 bool encClass::need##attrName(const stateRepClass& stateRep, \
243  const stateRepClass& asSeenByRemote) \
244 { \
245  return (bool) !(stateRep.inspector() == asSeenByRemote.inspector()); \
246 }
247 
248 #endif
249 #endif
250 

Document ID: Generated on Wed Aug 14 15:35:11 EDT 2013 from SVN revision 130445
Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)