MAK RTIspy API Documentation for HLA 4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLAvariableArray.h
Go to the documentation of this file.
1 #pragma once
2 /***********************************************************************
3  The IEEE hereby grants a general, royalty-free license to copy, distribute,
4  display and make derivative works from this material, for all purposes,
5  provided that any use of the material contains the following
6  attribution: "Reprinted with permission from IEEE 1516.1(TM)-2025".
7  Should you require additional information, contact the Manager, Standards
8  Intellectual Property, IEEE Standards Association (stds-ipr@ieee.org).
9 ***********************************************************************/
10 
13 #include <RTI/SpecificConfig.h>
14 
15 namespace rti1516_2025
16 {
17  // Forward Declarations
18  class VariableLengthData;
19  class HLAvariableArrayImplementation;
20 
21  // Interface for the HLAvariableArray complex data element
23  {
24  public:
25 
26  // Constructor which accepts a prototype element
27  // that specifies the type of elements to be stored in the array.
28  // A clone of the given element works as a seed.
29  explicit HLAvariableArray (
30  const DataElement& prototype );
31 
32  // Copy Constructor
34  HLAvariableArray const & rhs);
35 
36  // Destructor
37  ~HLAvariableArray () override;
38 
39  // Return a new copy of the DataElement
40  std::unique_ptr<DataElement> clone () const override;
41 
42  // Encode this element into a new VariableLengthData
44  VariableLengthData encode () const override;
45 
46  // Encode this element into an existing VariableLengthData
48  void encode (
49  VariableLengthData& inData) const override;
50 
51  // Encode this element and append it to a buffer
53  void encodeInto (
54  std::vector<Octet>& buffer) const override;
55 
56  // Decode this element from the RTI's VariableLengthData.
58  HLAvariableArray& decode (
59  VariableLengthData const & inData) override;
60 
61  // Decode this element starting at the index in the provided buffer
63  size_t decodeFrom (
64  std::vector<Octet> const & buffer,
65  size_t index) override;
66 
67  // Return the size in bytes of this element's encoding.
69  size_t getEncodedLength () const override;
70 
71  // Return the octet boundary of this element.
72  unsigned int getOctetBoundary () const override;
73 
74  // Return the number of elements in this variable array.
75  virtual size_t size () const;
76 
77  // Return true if given element is same type as this; otherwise, false.
78  bool isSameTypeAs(
79  DataElement const& inData ) const override;
80 
81  // Return true if given element matches prototype of array.
82  virtual bool hasPrototypeSameTypeAs(DataElement const& dataElement ) const;
83 
84  // Adds a copy of the given element instance to this array
85  // Element must match prototype.
87  virtual HLAvariableArray& addElement (
88  const DataElement& dataElement);
89 
90  // Adds the given element instance to this variable array
91  // Element must match prototype.
92  // Caller is responsible for ensuring that the external memory is
93  // valid for the lifetime of this object or until the indexed element
94  // acquires new memory through the set method.
95  // Null pointer results in an exception.
97  virtual HLAvariableArray& addElementPointer (
98  DataElement* dataElement);
99 
100  // Sets the indexed element to a copy of the given element instance.
101  // Element must match prototype.
102  // If indexed element uses external memory, the memory will be modified.
104  virtual HLAvariableArray& set (
105  size_t index,
106  const DataElement& dataElement);
107 
108  // Sets the indexed element to the given element instance.
109  // Element must match prototype.
110  // Null pointer results in an exception.
111  // Caller is responsible for ensuring that the external memory is
112  // valid for the lifetime of this object or until the indexed element
113  // acquires new memory through this call.
115  virtual HLAvariableArray& setElementPointer (
116  size_t index,
117  DataElement* dataElement);
118 
119  // Return a const reference to the element instance at the specified index.
120  // Must use set to change element.
122  virtual const DataElement& get (
123  size_t index) const;
124 
125  // Return a const reference to the element instance at the specified index.
126  // Must use set to change element.
128  virtual DataElement const& operator [](size_t index) const;
129  private:
130 
131  // Default Constructor not allowed
132  HLAvariableArray ();
133 
134  // Assignment Operator not allowed
135  HLAvariableArray& operator=(
136  HLAvariableArray const & rhs);
137 
138  protected:
139 
140  HLAvariableArrayImplementation* _impl;
141  };
142 
143  template<class T> class HLAvariableArrayT : public rti1516_2025::HLAvariableArray
144  {
145  public:
146  // Constructor
148  {
149  }
150 
151  // Copy Constructor
152  // Copied elements use internal memory
154  HLAvariableArrayT<T> const & rhs) :
155  HLAvariableArray(rhs)
156  {
157  }
158 
159  // Destructor
160  ~HLAvariableArrayT() override = default;
161 
162  // Return a new copy of the array
163  std::unique_ptr<DataElement> clone() const override
164  {
165  return std::make_unique<HLAvariableArrayT>(*this);
166  }
167 
168  // Return true if given element is same type as this; otherwise, false.
170  DataElement const& inData) const override
171  {
172  return typeid(*this) == typeid(inData);
173  }
174 
175  // Adds a copy of the given element instance to this array
177  const DataElement& dataElement) override
178  {
179  HLAvariableArray::addElement(dataElement);
180  return *this;
181  }
182 
183  // Adds the given element instance to this variable array
184  // Caller is responsible for ensuring that the external memory is
185  // valid for the lifetime of this object or until the indexed element
186  // acquires new memory through the set method.
187  // Null pointer results in an exception.
189  DataElement* dataElement) override
190  {
192  return *this;
193  }
194 
195  // Sets the element at the given index to a copy of the given element instance
196  // If indexed element uses external memory, the memory will be modified.
197  virtual HLAvariableArrayT<T>& set(size_t index,
198  const T& dataElement)
199  {
200  HLAvariableArray::set(index, dataElement);
201  return *this;
202  }
203 
204  // Sets the element at the given index to the given element instance
205  // Null pointer results in an exception.
206  // Caller is responsible for ensuring that the external memory is
207  // valid for the lifetime of this object or until the indexed element
208  // acquires new memory through this call.
210  T* dataElement)
211  {
212  HLAvariableArray::setElementPointer(index, dataElement);
213  return *this;
214  }
215 
216  // Return a reference to the element instance at the specified index.
217  // Access of indexed element that has not been set will set that index
218  // with a default constructed element and return it.
219  // Must use set to change element.
220  const T& get(
221  size_t index) const override
222  {
223  return dynamic_cast<const T &>(HLAvariableArray::get(index));
224  }
225 
226  // Return a const reference to the element instance at the specified index.
227  // Access of indexed element that has not been set will set that index
228  // with a default constructed element and return it.
229  // Must use set to change element.
230  T const& operator [](size_t index) const override
231  {
232  return dynamic_cast<T const &>(HLAvariableArray::operator[](index));
233  }
234 
235  // Assignment Operator not allowed
237  HLAvariableArrayT<T> const & rhs) = delete;
238  };
239 
240 }
241 
242 
243 
virtual HLAvariableArray & set(size_t index, const DataElement &dataElement)
virtual HLAvariableArray & setElementPointer(size_t index, DataElement *dataElement)
#define RTI_EXPORT
Definition: SpecificConfig.h:45
std::unique_ptr< DataElement > clone() const override
Definition: HLAvariableArray.h:163
virtual const DataElement & get(size_t index) const
virtual HLAvariableArrayT< T > & set(size_t index, const T &dataElement)
Definition: HLAvariableArray.h:197
bool isSameTypeAs(DataElement const &inData) const override
Definition: HLAvariableArray.h:169
Definition: DataElement.h:23
virtual HLAvariableArray & addElement(const DataElement &dataElement)
HLAvariableArrayT< T > & operator=(HLAvariableArrayT< T > const &rhs)=delete
HLAvariableArrayT(HLAvariableArrayT< T > const &rhs)
Definition: HLAvariableArray.h:153
virtual DataElement const & operator[](size_t index) const
T const & operator[](size_t index) const override
Definition: HLAvariableArray.h:230
~HLAvariableArrayT() override=default
Definition: HLAvariableArray.h:143
HLAvariableArrayImplementation * _impl
Definition: HLAvariableArray.h:140
virtual HLAvariableArray & addElementPointer(DataElement *dataElement)
This file contains definitions that are used to isolate platform-specific elements of the API...
virtual HLAvariableArrayT< T > & setElementPointer(size_t index, T *dataElement)
Definition: HLAvariableArray.h:209
HLAvariableArrayT< T > & addElementPointer(DataElement *dataElement) override
Definition: HLAvariableArray.h:188
HLAvariableArrayT()
Definition: HLAvariableArray.h:147
Definition: VariableLengthData.h:28
Definition: HLAvariableArray.h:22
HLAvariableArrayT< T > & addElement(const DataElement &dataElement) override
Definition: HLAvariableArray.h:176

Document ID: Generated on Wed Jul 8 16:20:32 EDT 2026 from SVN revision 291616
Copyright © 2005-2025 MAK Technologies Inc. All Rights Reserved (www.mak.com)