51 for (
unsigned int i = 0; i <
_size; i++)
101 template <
bool value_initialize = false>
202 for (
unsigned int i = 0; i < _size; i++)
214template <
bool value_initialize>
218 if (size > _allocated_size)
220 if constexpr (value_initialize)
221 _data_ptr.reset(
new T[size]());
223 _data_ptr = std::make_unique<T[]>(size);
224 mooseAssert(_data_ptr,
"Failed to allocate MooseArray memory!");
226 _data = _data_ptr.get();
227 _allocated_size = size;
237 if (size > _allocated_size)
239 auto new_pointer = std::make_unique<T[]>(size);
240 mooseAssert(new_pointer,
"Failed to allocate MooseArray memory!");
243 for (
unsigned int i = 0; i < _size; i++)
244 new_pointer[i] = _data[i];
246 _data_ptr = std::move(new_pointer);
247 _data = _data_ptr.get();
248 _allocated_size = size;
251 for (
unsigned int i = _size; i < size; i++)
252 _data[i] = default_value;
268 mooseAssert(i < _size,
269 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
278 mooseAssert(i < _size,
279 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
289 std::swap(_data, rhs.
_data);
290 std::swap(_size, rhs.
_size);
311 _allocated_size = rhs.size();
318 unsigned int rhs_size = rhs.
size();
322 for (
unsigned int i = 0; i < rhs_size; i++)
336 for (
unsigned int i = 0; i < _size; i++)
337 _data[i] = rhs.
_data[i];
346 return std::vector<T>(_data, _data + _size);
353 for (
unsigned int i = 0; i < a.size(); i++)
void freeDoubleMooseArray(MooseArray< MooseArray< T > > &a)
void shallowCopy(std::vector< T > &rhs)
Doesn't actually make a copy of the data.
void swap(MooseArray &rhs)
Swap memory in this object with the 'rhs' object.
void setAllValues(const T &value)
Sets all values of the array to the passed in value.
MooseArray< T > & operator=(const MooseArray< T > &rhs)
Actual operator=... really does make a copy of the data.
unsigned int _size
The current number of elements the array can hold.
MooseArray< T > & operator=(const std::vector< T > &rhs)
Actual operator=... really does make a copy of the data.
MooseArray()
Default constructor.
const T * data() const
Reference to first element of array.
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
void resize(unsigned int size)
Change the number of elements the array can store.
T & operator[](const unsigned int i)
Get element i out of the array.
void clear()
Change the number of elements the array can store to zero.
MooseArray(const MooseArray &rhs)
std::vector< T > stdVector() const
Extremely inefficient way to produce a std::vector from a MooseArray!
const T & operator[](const unsigned int i) const
Get element i out of the array.
MooseArray(const unsigned int size, const T &default_value)
unsigned int size() const
The number of elements that can currently be stored in the array.
void shallowCopy(const MooseArray &rhs)
Doesn't actually make a copy of the data.
MooseArray(const unsigned int size)
unsigned int _allocated_size
Number of allocated memory positions for storage.
void release()
Manually deallocates the data pointer.
void resize(unsigned int size, const T &default_value)
Change the number of elements the array can store.