Go to the documentation of this file.
16 #ifndef MESH_VARIABLE_ARRAY_H
17 #define MESH_VARIABLE_ARRAY_H
140 bool SetAt(uint16_t index, T value) {
154 bool SetArray(
const T* newData,
const uint16_t newDataLength) {
163 memcpy(
Data, newData, newDataLength *
sizeof(T));
174 bool SetData(
const T* newData, uint16_t startIndex,
const uint16_t newDataLength) {
175 uint16_t maxLength = startIndex + newDataLength;
184 memcpy(
Data + startIndex *
sizeof(T), newData, newDataLength *
sizeof(T));
206 bool FillData(
const T fillItem, uint16_t startIndex, uint16_t count) {
207 uint16_t maxLength = startIndex + count;
215 for (uint16_t i = startIndex; i < maxLength; i++) {
226 void GetData(T* data, uint16_t& dataLength)
const {
228 memcpy(data,
Data, dataLength *
sizeof(T));
245 T* newPayloadPtr = NULL;
248 newPayloadPtr = (T*)malloc(size *
sizeof(T));
252 newPayloadPtr = (T*)realloc(
Data, size *
sizeof(T));
255 if (newPayloadPtr != NULL) {
257 Data = newPayloadPtr;
347 #endif // !MESH_VARIABLE_ARRAY_H
MeshVariableArray< T > & operator=(MeshVariableArray< T > &&mva) noexcept
Move assignment operator.
Definition: meshVariableArray.h:104
bool SetArray(const T *newData, const uint16_t newDataLength)
Sets new data to whole and resizes (expand/shrink) it.
Definition: meshVariableArray.h:154
MeshVariableArray(const uint16_t length)
Create uninitialized array with specified length.
Definition: meshVariableArray.h:47
MeshVariableArray(const MeshVariableArray< T > &mva)
Copy constructor.
Definition: meshVariableArray.h:75
uint16_t Length() const
Length of data.
Definition: meshVariableArray.h:113
uint16_t DataLength
Length of current data.
Definition: meshVariableArray.h:344
bool SetAt(uint16_t index, T value)
Sets item at specified index.
Definition: meshVariableArray.h:140
MeshVariableArray(const T fillItem, const uint16_t length)
Fills whole array with the specified item.
Definition: meshVariableArray.h:67
~MeshVariableArray()
Destructor.
Definition: meshVariableArray.h:89
void GetData(T *data, uint16_t &dataLength) const
Gets data from whole array.
Definition: meshVariableArray.h:226
const T * d_ptr() const
Pointer to data.
Definition: meshVariableArray.h:330
void MoveFrom(T *&dataPtr, uint16_t dataLength)
Moves data from another array to current array.
Definition: meshVariableArray.h:306
bool SetData(const T *newData, uint16_t startIndex, const uint16_t newDataLength)
Sets new data. Array will be expanded if data won't fit.
Definition: meshVariableArray.h:174
T * Data
Pointer to array of data.
Definition: meshVariableArray.h:339
This class safetly handles allocation and deallocation of memory. It can be used in conjunction with ...
Definition: meshVariableArray.h:32
This file contains classes and structures that supports meshNet.
MeshVariableArray< T > & operator=(const MeshVariableArray< T > &mva)
Copy assignment operator.
Definition: meshVariableArray.h:96
void Clear()
Sets array size to 0.
Definition: meshVariableArray.h:270
T * UnsafeDataMove()
Takes pointer to allocated array and removes that pointer from current class.
Definition: meshVariableArray.h:319
bool ResizeArray(uint16_t size, bool doNotCopy=false)
Resizes array.
Definition: meshVariableArray.h:237
bool CopyFrom(const MeshVariableArray< T > &another)
Copyies data from another array to current array.
Definition: meshVariableArray.h:283
MeshVariableArray(const T *newData, const uint16_t newDataLength)
Sets new data to whole and sets its size.
Definition: meshVariableArray.h:57
MeshVariableArray(MeshVariableArray< T > &&mva) noexcept
Move constructor.
Definition: meshVariableArray.h:82
void FillArray(const T fillItem)
Fills whole array with the specified item.
Definition: meshVariableArray.h:192
void MoveFrom(MeshVariableArray< T > &another)
Moves data from another array to current array.
Definition: meshVariableArray.h:293
bool FillData(const T fillItem, uint16_t startIndex, uint16_t count)
Fills specified part of array with the specified item. Array can be expanded when startIndex + count ...
Definition: meshVariableArray.h:206
T operator[](uint16_t i) const
Definition: meshVariableArray.h:117
T GetAt(uint16_t index) const
Reads item at specified index.
Definition: meshVariableArray.h:130
MeshVariableArray()
Constructor.
Definition: meshVariableArray.h:38