MAK RTIspy API Documentation for HLA 4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HLAfixedArray.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 HLAfixedArrayImplementation;
20 
21  // Interface for the HLAfixedArray complex data element
23  {
24  public:
25  // Constructor which accepts a prototype element and size
26  // that specifies the type and number of elements to be stored in the array.
27  // A clone of the given element works as a prototype.
28  explicit HLAfixedArray (
29  const DataElement& protoType,
30  size_t length );
31 
32  // Copy Constructor
33  // Copied elements use internal memory
35  HLAfixedArray const & rhs);
36 
37  // Destructor
38  ~HLAfixedArray() override;
39 
40  // Return a new copy of the array
41  std::unique_ptr<DataElement> clone () const override;
42 
43  // Encode this element into a new VariableLengthData
45  VariableLengthData encode () const override;
46 
47  // Encode this element into an existing VariableLengthData
49  void encode (
50  VariableLengthData& inData) const override;
51 
52  // Encode this element and append it to a buffer
54  void encodeInto (
55  std::vector<Octet>& buffer) const override;
56 
57  // Decode this element from the RTI's VariableLengthData.
59  HLAfixedArray& decode (
60  VariableLengthData const & inData) override;
61 
62  // Decode this element starting at the index in the provided buffer
64  size_t decodeFrom (
65  std::vector<Octet> const & buffer,
66  size_t index) override;
67 
68  // Return the size in bytes of this element's encoding.
70  size_t getEncodedLength () const override;
71 
72  // Return the octet boundary of this element.
73  unsigned int getOctetBoundary () const override;
74 
75  // Return true if given element is same type as this; otherwise, false.
76  bool isSameTypeAs(
77  DataElement const& inData ) const override;
78 
79  // Return true if given element matches prototype of this array.
80  virtual bool hasPrototypeSameTypeAs(DataElement const& dataElement ) const;
81 
82  // Return the number of elements in this fixed array.
83  virtual size_t size () const;
84 
85  // Sets the element at the given index to a copy of the given element instance
86  // Element must match prototype.
87  // If indexed element uses external memory, the memory will be modified.
89  virtual HLAfixedArray& set (size_t index,
90  const DataElement& dataElement);
91 
92  // Sets the element at the given index to the given element instance
93  // Element must match prototype.
94  // Null pointer results in an exception.
95  // Caller is responsible for ensuring that the external memory is
96  // valid for the lifetime of this object or until the indexed element
97  // acquires new memory through this call.
99  virtual HLAfixedArray& setElementPointer (size_t index,
100  DataElement* dataElement);
101 
102  // Return a reference to the element instance at the specified index.
103  // Access of indexed element that has not been set will set that index
104  // with a clone of prototype and return it.
105  // Must use set to change element.
107  virtual const DataElement& get (
108  size_t index) const;
109 
110  // Return a const reference to the element instance at the specified index.
111  // Access of indexed element that has not been set will set that index
112  // with a clone of prototype and return it.
113  // Must use set to change element.
115  virtual DataElement const& operator [](size_t index) const;
116 
117  private:
118 
119  // Default Constructor not allowed
120  HLAfixedArray ();
121 
122  // Assignment Operator not allowed
123  HLAfixedArray& operator=(
124  HLAfixedArray const & rhs);
125 
126  protected:
127 
128  HLAfixedArrayImplementation* _impl;
129  };
130 
131  template<class T> class HLAfixedArrayT : public rti1516_2025::HLAfixedArray
132  {
133  public:
134  // Constructor which accepts a size that specifies
135  // the number of elements to be stored in the array.
136  explicit HLAfixedArrayT(
137  size_t length) : HLAfixedArray(T(), length)
138  {
139  }
140 
141  // Copy Constructor
142  // Copied elements use internal memory
144  HLAfixedArrayT<T> const & rhs) :
145  HLAfixedArray(rhs)
146  {
147  }
148 
149  // Destructor
150  ~HLAfixedArrayT() override = default;
151 
152  // Return a new copy of the array
153  std::unique_ptr<DataElement> clone() const override
154  {
155  return std::make_unique<HLAfixedArrayT>(*this);
156  }
157 
158  // Return true if given element is same type as this; otherwise, false.
160  DataElement const& inData) const override
161  {
162  return typeid(*this) == typeid(inData);
163  }
164 
165  // Sets the element at the given index to a copy of the given element instance.
166  // If indexed element uses external memory, the memory will be modified.
167  virtual HLAfixedArrayT<T>& set(size_t index,
168  const T& dataElement)
169  {
170  HLAfixedArray::set(index, dataElement);
171  return *this;
172  }
173 
174  // Sets the element at the given index to the given element instance.
175  // Null pointer results in an exception.
176  // Caller is responsible for ensuring that the external memory is
177  // valid for the lifetime of this object or until the indexed element
178  // acquires new memory through this call.
179  virtual HLAfixedArrayT<T>& setElementPointer(size_t index,
180  T* dataElement)
181  {
182  HLAfixedArray::setElementPointer(index, dataElement);
183  return *this;
184  }
185 
186  // Return a reference to the element instance at the specified index.
187  // Access of indexed element that has not been set will set that index
188  // with a default constructed element and return it.
189  // Must use set to change element.
190  const T& get(
191  size_t index) const override
192  {
193  return dynamic_cast<const T &>(HLAfixedArray::get(index));
194  }
195 
196  // Return a const reference to the element instance at the specified index.
197  // Access of indexed element that has not been set will set that index
198  // with a default constructed element and return it.
199  // Must use set to change element.
200  T const& operator [](size_t index) const override
201  {
202  return dynamic_cast<T const &>(HLAfixedArray::operator[](index));
203  }
204 
205  // Assignment Operator not allowed
207  HLAfixedArrayT<T> const& rhs) = delete;
208  };
209 }
210 
211 
212 
#define RTI_EXPORT
Definition: SpecificConfig.h:45
bool isSameTypeAs(DataElement const &inData) const override
Definition: HLAfixedArray.h:159
Definition: HLAfixedArray.h:131
std::unique_ptr< DataElement > clone() const override
Definition: HLAfixedArray.h:153
virtual HLAfixedArrayT< T > & setElementPointer(size_t index, T *dataElement)
Definition: HLAfixedArray.h:179
virtual DataElement const & operator[](size_t index) const
virtual HLAfixedArray & set(size_t index, const DataElement &dataElement)
HLAfixedArrayT(HLAfixedArrayT< T > const &rhs)
Definition: HLAfixedArray.h:143
virtual HLAfixedArray & setElementPointer(size_t index, DataElement *dataElement)
Definition: DataElement.h:23
HLAfixedArrayT< T > & operator=(HLAfixedArrayT< T > const &rhs)=delete
virtual const DataElement & get(size_t index) const
T const & operator[](size_t index) const override
Definition: HLAfixedArray.h:200
HLAfixedArrayImplementation * _impl
Definition: HLAfixedArray.h:128
This file contains definitions that are used to isolate platform-specific elements of the API...
HLAfixedArrayT(size_t length)
Definition: HLAfixedArray.h:136
virtual HLAfixedArrayT< T > & set(size_t index, const T &dataElement)
Definition: HLAfixedArray.h:167
Definition: VariableLengthData.h:28
Definition: HLAfixedArray.h:22
~HLAfixedArrayT() override=default

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)