MAK RTIspy API Documentation for HLA 1516
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rtiTemplateMsgParams.h
Go to the documentation of this file.
1 /*********************************************************************
2 ** Copyright (c) 2011 MaK Technologies, Inc.
3 ** All rights reserved.
4 *********************************************************************/
5 
22 
23 #ifndef DtRtiTemplateMsgParams_H_
24 #define DtRtiTemplateMsgParams_H_
25 
26 //#include "rtiTemplateMsg.h"
27 #include <vlutil/vlNetTypes.h>
28 #include <vlutil/vlPrint.h>
29 #include <assert.h>
30 
33 {
34 public:
36 
38  void setPrevParam(DtRtiBaseMsgParam* prevParam) {
39  myPrevParam = prevParam;
40  setOctetBoundary(prevParam->octetBoundary()); }
41 
43  virtual void* endPtr() = 0;
44  virtual const void* endPtr() const = 0;
45 
47  void* beginPtr() {
48  void* p = myPrevParam->endPtr();
49  //DtWarn << std::hex << p << std::dec << std::endl;
50  return p; }
51  const void* beginPtr() const {
52  const void* p = myPrevParam->endPtr();
53  //DtWarn << std::hex << p << std::dec << std::endl;
54  return p; }
55 
57  virtual unsigned minSize() = 0;
58 
60  virtual void print() const = 0;
61 
63  virtual const char* name() const { return myName; }
64 
66  unsigned octetBoundary() const { return myOctetBoundary; }
67 
71  virtual void setOctetBoundary(unsigned prevBoundary) = 0;
72 
75  virtual unsigned elementSize() = 0;
76 
77 protected:
78  DtRtiBaseMsgParam(const char* paramName)
79  : myPrevParam(0),
80  myOctetBoundary(0),
81  myName(paramName) {}
82 
85 
87  unsigned myOctetBoundary;
88 
90  const char* myName;
91 };
92 
94 template<typename ParamType, typename NetParamType>
96 {
97 public:
98  DtRtiMsgParam(const char* paramName) : DtRtiBaseMsgParam(paramName) {}
100 
102  void setParam(ParamType val)
103  {
104  NetParamType* ptr = paramPtr();
105  *ptr = val;
106  }
107 
109  void setParamRef(const ParamType& val)
110  {
111  NetParamType* ptr = paramPtr();
112  *ptr = val;
113  }
114 
116  ParamType param() const
117  {
118  return static_cast<ParamType>(*paramPtr());
119  }
120 
122  void getParam(ParamType& val) const
123  {
124  val = static_cast<ParamType>(*paramPtr());
125  }
126 
128  void* endPtr()
129  {
130  return (reinterpret_cast<char*>(paramPtr()) + sizeof(NetParamType));
131  }
132 
133  const void* endPtr() const
134  {
135  return (reinterpret_cast<const char*>(paramPtr()) + sizeof(NetParamType));
136  }
137 
139  unsigned minSize() { return sizeof(NetParamType); }
140 
143  unsigned elementSize() { return sizeof(NetParamType); }
144 
146  void print() const
147  {
148  MAKRti::DtVerbose << name() << ": " << param() << std::endl;
149  }
150 
154  void setOctetBoundary(unsigned prevBoundary)
155  {
156  myOctetBoundary = (prevBoundary + minSize()) % 8;
157 
158  // Check that our message is assembled properly
159  assert(prevBoundary == 0 || (prevBoundary % minSize()) == 0);
160  }
161 
162 protected:
164 
166  NetParamType* paramPtr() { return reinterpret_cast<NetParamType*>(beginPtr()); }
167  const NetParamType* paramPtr() const { return reinterpret_cast<const NetParamType*>(beginPtr()); }
168 
169 };
170 
171 
172 
173 // PARAMETER DECLARATION MACROS
174 // These macros declare parameters and their accessor methods within a message.
175 // In your class definition, simply use one of the type-specific macros
176 // below (e.g. DtDECLARE_UNSIGNED_PARAMETER_METHODS,
177 // DtDECLARE_BOOL_PARAMETER_METHODS, etc.)
178 
179 // Declares the generic set and get methods for a parameter. Should not be used
180 // directly. Use one of the more type specific versions below, which will also
181 // define the parameter itself.
182 // ParamName = the name of the parameter
183 // ParamType = the input type of the set and the return type of the get
184 #define DtDECLARE_PARAMETER_METHODS(ParamName, ParamType) \
185  public: \
186  static const char* ParamName##Name; \
187  void set##ParamName(ParamType val); \
188  ParamType get##ParamName() const;
189 
190 // Declares the generic set and get methods for a parameter which is passed by
191 // reference. Should not be used directly. Use one of the more type specific
192 // versions below, which will also define the parameter itself.
193 // ParamName = the name of the parameter
194 // ParamType = the input type of the set and the return type of the get
195 #define DtDECLARE_BY_REF_PARAMETER_METHODS(ParamName, ParamType) \
196  public: \
197  static const char* ParamName##Name; \
198  void set##ParamName(const ParamType& val); \
199  ParamType get##ParamName() const; \
200  void get##ParamName(ParamType& val) const;
201 
202 // Defines a new unsigned integer parameter in a message and declares its
203 // get and set methods.
204 // ParamName = the name of the parameter
205 // BitSize = the storage size in the message (in bits, obviously)
206 #define DtDECLARE_UNSIGNED_PARAMETER_METHODS(ParamName, BitSize) \
207  DtDECLARE_PARAMETER_METHODS(ParamName, MAKRti::DtU##BitSize) \
208  protected: \
209  typedef DtRtiMsgParam<MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize> ParamName##Type; \
210  ParamName##Type* my##ParamName;
211 
212 // Defines a new boolean parameter in a message and declares its
213 // get and set methods. Bool parameters will be stored as 8 bit
214 // unsigned integers.
215 // ParamName = the name of the parameter
216 #define DtDECLARE_BOOL_PARAMETER_METHODS(ParamName) \
217  DtDECLARE_PARAMETER_METHODS(ParamName, bool) \
218  protected: \
219  typedef DtRtiMsgParam<MAKRti::DtU8, MAKRti::DtNetU8> ParamName##Type; \
220  ParamName##Type* my##ParamName;
221 
222 // Defines a new integer parameter in a message and declares its
223 // get and set methods.
224 // ParamName = the name of the parameter
225 // BitSize = the storage size in the message (in bits, obviously)
226 #define DtDECLARE_INT_PARAMETER_METHODS(ParamName, BitSize) \
227  DtDECLARE_PARAMETER_METHODS(ParamName, MAKRti::DtInt##BitSize) \
228  protected: \
229  typedef DtRtiMsgParam<MAKRti::DtInt##BitSize, MAKRti::DtNetInt##BitSize> ParamName##Type; \
230  ParamName##Type* my##ParamName;
231 
232 // Defines a new enumeration parameter in a message and declares its
233 // get and set methods.
234 // ParamName = the name of the parameter
235 // EnumType = the type of the enumeration for the input to set and the return of get
236 // BitSize = the storage size in the message (in bits, obviously)
237 #define DtDECLARE_ENUMERATION_PARAMETER_METHODS(ParamName, EnumType, BitSize) \
238  DtDECLARE_PARAMETER_METHODS(ParamName, EnumType) \
239  protected: \
240  typedef DtRtiMsgParam<MAKRti::DtU##BitSize, MAKRti::DtNetU##BitSize> ParamName##Type; \
241  ParamName##Type* my##ParamName;
242 
243 // Defines a new float parameter in a message and declares its
244 // get and set methods.
245 // ParamName = the name of the parameter
246 // BitSize = the storage size in the message (in bits, obviously)
247 #define DtDECLARE_FLOAT_PARAMETER_METHODS(ParamName, BitSize) \
248  DtDECLARE_PARAMETER_METHODS(ParamName, MAKRti::DtFloat##BitSize) \
249  protected: \
250  typedef DtRtiMsgParam<MAKRti::DtFloat##BitSize, MAKRti::DtNetFloat##BitSize> ParamName##Type; \
251  ParamName##Type* my##ParamName;
252 
253 
254 
255 
256 // PARAMETER DEFINITION MACROS
257 // These macros define the accessor methods for a message parameter.
258 // In your .cxx file, simply use one of the type-specific macros
259 // below (e.g. DtDEFINE_UNSIGNED_PARAMETER_METHODS,
260 // DtDEFINE_BOOL_PARAMETER_METHODS, etc.). The macro should match the
261 // type used in the DtDECLARE macro in your class definition.
262 
263 // Defines the set and get methods for a general parameter. Should not be used
264 // directly. Use one of the more type specific versions below.
265 // ClassName = the name of the message class
266 // ParamName = the name of the parameter
267 // ParamType = the input type of the set and the return type of the get
268 #define DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, ParamType) \
269  const char* ClassName::ParamName##Name = #ParamName; \
270  void ClassName::set##ParamName(ParamType val) \
271  { \
272  my##ParamName->setParam(val); \
273  } \
274  ParamType ClassName::get##ParamName() const \
275  { \
276  return static_cast<ParamType>(my##ParamName->param()); \
277  }
278 
279 // Defines the generic set and get methods for a parameter which is passed by
280 // reference. Should not be used directly. Use one of the more type specific
281 // versions below.
282 // ClassName = the name of the message class
283 // ParamName = the name of the parameter
284 // ParamType = the input type of the set and the return type of the get
285 #define DtDEFINE_BY_REF_PARAMETER_METHODS(ClassName, ParamName, ParamType) \
286  const char* ClassName::ParamName##Name = #ParamName; \
287  void ClassName::set##ParamName(const ParamType& val) \
288  { \
289  my##ParamName->setParamRef(val); \
290  } \
291  ParamType ClassName::get##ParamName() const \
292  { \
293  return my##ParamName->param(); \
294  } \
295  void ClassName::get##ParamName(ParamType& val) const \
296  { \
297  my##ParamName->getParam(val); \
298  }
299 
300 // Defines the set and get methods for parameters which are to be stored as
301 // an unsigned integer of some size.
302 // ClassName = the name of the message class
303 // ParamName = the name of the parameter
304 // BitSize = the storage size in the message (in bits, obviously)
305 #define DtDEFINE_UNSIGNED_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
306  DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, DtU##BitSize)
307 
308 // Defines the set and get methods for parameters which are to be stored as
309 // a bool.
310 // ClassName = the name of the message class
311 // ParamName = the name of the parameter
312 #define DtDEFINE_BOOL_PARAMETER_METHODS(ClassName, ParamName) \
313  DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, bool)
314 
315 // Defines the set and get methods for parameters which are to be stored as
316 // an integer of some size.
317 // ClassName = the name of the message class
318 // ParamName = the name of the parameter
319 // BitSize = the storage size in the message (in bits, obviously)
320 #define DtDEFINE_INT_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
321  DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, DtInt##BitSize)
322 
323 // Defines the set and get methods for parameters which are to be stored as
324 // an enumeration.
325 // ClassName = the name of the message class
326 // ParamName = the name of the parameter
327 // EnumType = the type of the enumeration for the input to set and the return of get
328 #define DtDEFINE_ENUMERATION_PARAMETER_METHODS(ClassName, ParamName, EnumType)\
329  DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, EnumType)
330 
331 // Defines the set and get methods for parameters which are to be stored as
332 // a floats of some size.
333 // ClassName = the name of the message class
334 // ParamName = the name of the parameter
335 // BitSize = the storage size in the message (in bits, obviously)
336 #define DtDEFINE_FLOAT_PARAMETER_METHODS(ClassName, ParamName, BitSize) \
337  DtDEFINE_PARAMETER_METHODS(ClassName, ParamName, DtFloat##BitSize)
338 
339 
340 // PARAMETER ADDITION MACROS
341 // These macros should be used within the addAllParameters() function of your
342 // new message class. The order parameters are added matters! You must order
343 // them in a way to ensure proper alignment. If you don't, the parameter
344 // classes will try to help you out by asserting in debug builds.
345 
346 // Adds a basic parameter to the message.
347 // ParamName = the name of the parameter
348 #define DtADD_PARAMETER(ParamName) \
349  addParameter(my##ParamName = new ParamName##Type(ParamName##Name));
350 
351 #endif
352 
const char * myName
The parameter name.
Definition: rtiTemplateMsgParams.h:90
virtual unsigned elementSize()=0
Returns the size of single element in this parameter.
unsigned octetBoundary() const
Returns the octet boundary of the parameter in the message.
Definition: rtiTemplateMsgParams.h:66
DtRtiBaseMsgParam(const char *paramName)
Definition: rtiTemplateMsgParams.h:78
void setParam(ParamType val)
Sets the value of the parameter.
Definition: rtiTemplateMsgParams.h:102
virtual void * endPtr()=0
Returns a pointer to location just after this parameter in the message.
void * beginPtr()
Returns a pointer to the start of this parameter in the message.
Definition: rtiTemplateMsgParams.h:47
void * endPtr()
Returns a pointer to location just after this parameter in the message.
Definition: rtiTemplateMsgParams.h:128
unsigned myOctetBoundary
Octet boundary of this parameter.
Definition: rtiTemplateMsgParams.h:87
const NetParamType * paramPtr() const
Definition: rtiTemplateMsgParams.h:167
unsigned minSize()
Returns the minimum size of this parameter.
Definition: rtiTemplateMsgParams.h:139
~DtRtiBaseMsgParam()
Definition: rtiTemplateMsgParams.h:35
ParamType param() const
Gets the value of the parameter.
Definition: rtiTemplateMsgParams.h:116
unsigned elementSize()
Returns the size of single element in this parameter.
Definition: rtiTemplateMsgParams.h:143
void print() const
Prints the parameter.
Definition: rtiTemplateMsgParams.h:146
The template for an RTI message parameter.
Definition: rtiTemplateMsgParams.h:95
NetParamType * paramPtr()
Returns a pointer to location of this parameter in the message.
Definition: rtiTemplateMsgParams.h:166
The base class for all templated RTI message parameters.
Definition: rtiTemplateMsgParams.h:32
void setParamRef(const ParamType &val)
Sets the value of the parameter by reference.
Definition: rtiTemplateMsgParams.h:109
const void * beginPtr() const
Definition: rtiTemplateMsgParams.h:51
const void * endPtr() const
Definition: rtiTemplateMsgParams.h:133
virtual void print() const =0
Prints the parameter.
virtual void setOctetBoundary(unsigned prevBoundary)=0
Sets the octet boundary of the parameter in the message based on the boundary of this parameter and t...
void getParam(ParamType &val) const
Gets the value of the parameter by reference.
Definition: rtiTemplateMsgParams.h:122
void setPrevParam(DtRtiBaseMsgParam *prevParam)
Sets the pointer to the previous parameter in the message.
Definition: rtiTemplateMsgParams.h:38
~DtRtiMsgParam()
Definition: rtiTemplateMsgParams.h:99
DtRtiMsgParam(const char *paramName)
Definition: rtiTemplateMsgParams.h:98
void setOctetBoundary(unsigned prevBoundary)
Sets the octet boundary of the parameter in the message based on the boundary of this parameter and t...
Definition: rtiTemplateMsgParams.h:154
virtual const char * name() const
Returns the parameter name.
Definition: rtiTemplateMsgParams.h:63
DtRtiBaseMsgParam * myPrevParam
Pointer to the previous parameter in this message.
Definition: rtiTemplateMsgParams.h:84
virtual unsigned minSize()=0
Returns the minimum size of this parameter.

Document ID: Generated on Sun Jul 20 16:15:30 EDT 2025 from SVN revision 277985
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)