VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
registerGenericAttributeClassHLA.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2013 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 
10 #pragma once
11 
12 #ifdef DtHLA
13 
17 #include <vl/stateEncoderFactory.h>
18 
19 namespace makVrfVrlinkExtToolkit
20 {
23  template <typename StateRepType>
24  void setAttributeNameToHandleMap(DtObjClassDesc* desc)
25  {
26  std::map<DtString, RTI::AttributeHandle> attrNamesToHandles;
27 
28  const RTI::AttributeHandleSet& ahs = desc->attrHandleSet();
29 
30  // Loop through all attribute handles. Add any attributes that do not
31  // belong to the base class. Base class attributes will be handled by
32  // the DtAggregateEntityEncoder set/get methods. All other attribute
33  // name-to-handle mappings must be provided to the state rep.
34  DtObjClassDesc* baseClass = desc->baseClass();
35  #if DtHLA_1516
36 
37  RTI::AttributeHandleSet::const_iterator itr = ahs.begin();
38  const RTI::AttributeHandleSet::const_iterator end = ahs.end();
39  for (; itr != end; itr++)
40  {
41  DtString attrName = desc->attributeNameByHandle(*itr);
42  if(!baseClass->hasAttribute(attrName.c_str()))
43  {
44  attrNamesToHandles.insert(std::make_pair(attrName, *itr));
45  }
46  }
47 
48  #else
49 
50  for (RTI::ULong i = 0; i < ahs.size(); i++)
51  {
52  RTI::AttributeHandle hdl = ahs.getHandle(i);
53  DtString attrName = desc->attributeNameByHandle(hdl);
54  if(!baseClass->hasAttribute(attrName.c_str()))
55  {
56  attrNamesToHandles.insert(std::make_pair(attrName, hdl));
57  }
58  }
59 
60  #endif
61 
63  setAttributeNameToHandleMap(attrNamesToHandles);
64  }
65 
66  bool areClassNamesEquivalent(const DtString& name1, const DtString& name2)
67  {
68  const DtString hla13RootName("ObjectRoot.");
69  const DtString hla1516RootName("HLAobjectRoot.");
70 
71  const char* name1Ptr = name1.c_str();
72  const char* name2Ptr = name2.c_str();
73 
74  if (name1.findString(hla13RootName) == 0)
75  {
76  name1Ptr += hla13RootName.size();
77  }
78  else if (name1.findString(hla1516RootName) == 0)
79  {
80  name1Ptr += hla1516RootName.size();
81  }
82 
83  if (name2.findString(hla13RootName) == 0)
84  {
85  name2Ptr += hla13RootName.size();
86  }
87  else if (name2.findString(hla1516RootName) == 0)
88  {
89  name2Ptr += hla1516RootName.size();
90  }
91 
92  return (strcmp(name1Ptr, name2Ptr) == 0);
93  }
94 
101  template <typename StateRepType, typename EncoderType, typename PublisherType, typename ReflectedObjType>
102  void registerGenericAttributeClass(const DtString& fullClassName,
103  const DtString& publisherName,
104  const DtString& reflListName,
105  DtExerciseConn* exConn)
106  {
107  // Store static local copies of each of the strings. This is because the
108  // char* we pass to the VRL registration functions are simply stored directly,
109  // so we need to make sure they persist. Since this is a template function,
110  // these will be unique for these template arguments.
111  static DtString theFullClassName;
112  static DtString thePublisherName;
113  static DtString theReflListName;
114  theFullClassName = fullClassName;
115  thePublisherName = publisherName;
116  theReflListName = reflListName;
117 
118  DtObjClassDesc* classDesc = exConn->fom()->objClassByName(theFullClassName.c_str());
119 
120  if(classDesc)
121  {
122  // Since there is no way to set an unknown attribute checker, we need to
123  // completely replace the state encoder class in order to write a new
124  // encode method to override this.
125  exConn->fomMapper()->stateEncoderFactory()->addEncoder(classDesc->handle(),
127 
128  // Set the generic unknown attribute encoder
129  classDesc->setUnknownAttributeEncoder((DtHlaStateEncoder::DtAttributeEncoder)
131 
132  // Set the generic unknown attribute decoder
133  classDesc->setUnknownAttributeDecoder((DtHlaStateDecoder::DtAttributeDecoder)
135 
136  // Add the new object class to the list of classes supported by the
137  // reflected list
138  std::set<DtString> objClassNames;
139  const std::set<DtString>* currObjClassNames = exConn->fomMapper()->objectClassNames(theReflListName.c_str());
140  if(currObjClassNames)
141  {
142  objClassNames = *currObjClassNames;
143  }
144 
145  // Add class to list of class names. Check to make sure class isn't already present in
146  // another acceptable form (i.e. with or without the root class specified.
147  bool alreadyPresent = false;
148  std::set<DtString>::const_iterator objClassIter = objClassNames.begin();
149  for (; objClassIter != objClassNames.end() && !alreadyPresent; ++objClassIter)
150  {
151  if (areClassNamesEquivalent(theFullClassName, *objClassIter))
152  {
153  alreadyPresent = true;
154  }
155  }
156 
157  if (!alreadyPresent)
158  {
159  objClassNames.insert(theFullClassName);
160  exConn->fomMapper()->setObjectClassNames(theReflListName.c_str(), objClassNames);
161  }
162 
163  // Set the state repository creators
164  PublisherType::setStateRepCreator((typename PublisherType::DtStateRepCreator)
166  ReflectedObjType::setStateRepCreator((typename ReflectedObjType::DtStateRepCreator)
167  DtGenericAttributeStateRepository<StateRepType>::create);
168 
169  // Set the object class to publish
170  exConn->fomMapper()->setObjectClassToChoose(thePublisherName.c_str(), theFullClassName.c_str());
171 
172  // Set the attribute name-handle map in the state rep class
173  setAttributeNameToHandleMap<StateRepType>(classDesc);
174  }
175  }
176 
185  template <typename StateRepType, typename EncoderType, typename PublisherType, typename ReflectedObjType>
186  void registerGenericAttributeClass(const std::vector<DtString>& fullClassNames,
187  const DtString& publisherName,
188  const DtString& reflListName,
189  DtFomMapper::DtObjectClassChooser classChooser,
190  DtExerciseConn* exConn)
191  {
192  static std::vector<DtString> theFullClassNames;
193  static DtString thePublisherName;
194  static DtString theReflListName;
195  theFullClassNames = fullClassNames;
196  thePublisherName = publisherName;
197  theReflListName = reflListName;
198 
199  std::set<DtString> objClassNames;
200 
201  // Get the current list of object classes supported by the reflected list
202  const std::set<DtString>* currObjClassNames = *exConn->fomMapper()->objectClassNames(theReflListName.c_str());
203  if(currObjClassNames)
204  {
205  objClassNames = *currObjClassNames;
206  }
207 
208  // Set the state repository creators
209  PublisherType::setStateRepCreator((typename PublisherType::DtStateRepCreator)StateRepType::create);
210  ReflectedObjType::setStateRepCreator((typename ReflectedObjType::DtStateRepCreator)StateRepType::create);
211 
212  for(int i = 0; i < theFullClassNames.size(); ++i)
213  {
214  DtObjClassDesc* classDesc = exConn->fom()->objClassByName(theFullClassNames[i].c_str());
215 
216  if(classDesc)
217  {
218  // Since there is no way to set an unknown attribute checker, we need to
219  // completely replace the state encoder class in order to write a new
220  // encode method to override this.
221  exConn->fomMapper()->stateEncoderFactory()->addEncoder(classDesc->handle(),
223 
224  // Set the generic unknown attribute encoder
225  classDesc->setUnknownAttributeEncoder((DtHlaStateEncoder::DtAttributeEncoder)
227 
228  // Set the generic unknown attribute decoder
229  classDesc->setUnknownAttributeDecoder((DtHlaStateDecoder::DtAttributeDecoder)
231 
232  // Add class to list of class names. Check to make sure class isn't already present in
233  // another acceptable form (i.e. with or without the root class specified.
234  bool alreadyPresent = false;
235  std::set<DtString>::const_iterator objClassIter = objClassNames.begin();
236  for (; objClassIter != objClassNames.end() && !alreadyPresent; ++objClassIter)
237  {
238  if (areClassNamesEquivalent(theFullClassNames[i], *objClassIter))
239  {
240  alreadyPresent = true;
241  }
242  }
243 
244  if (!alreadyPresent)
245  {
246  objClassNames.insert(theFullClassNames[i]);
247  exConn->fomMapper()->setObjectClassNames(theReflListName.c_str(), objClassNames);
248  }
249 
250  // Set the attribute name-handle map in the state rep class
251  setAttributeNameToHandleMap<StateRepType>(classDesc);
252  }
253 
254  }
255 
256  // Set the reflected list object class names
257  exConn->fomMapper()->setObjectClassNames(theReflListName.c_str(), objClassNames);
258 
259  // Set the object class to publish chooser function
260  exConn->fomMapper()->setObjectClassChooser(thePublisherName.c_str(), classChooser);
261  }
262 }
263 
264 #endif

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)