51 for (
unsigned int i = 0; i <
_size; i++)
101 template <
bool value_initialize = false>
117 void resize(
unsigned int size,
const T & default_value);
123 unsigned int size()
const;
133 const T &
operator[](
const unsigned int i)
const;
198 template <
typename T>
202 for (
unsigned int i = 0; i < _size; i++)
206 template <
typename T>
213 template <
typename T>
214 template <
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;
233 template <
typename T>
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;
257 template <
typename T>
264 template <
typename T>
268 mooseAssert(i < _size,
269 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
274 template <
typename T>
278 mooseAssert(i < _size,
279 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
284 template <
typename T>
294 template <
typename T>
304 template <
typename T>
311 _allocated_size = rhs.size();
314 template <
typename T>
318 unsigned int rhs_size = rhs.size();
322 for (
unsigned int i = 0; i < rhs_size; i++)
328 template <
typename T>
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++)
MooseArray(const unsigned int size, const T &default_value)
MooseArray()
Default constructor.
void swap(std::vector< T > &data, const std::size_t idx0, const std::size_t idx1, const libMesh::Parallel::Communicator &comm)
Swap function for serial or distributed vector of data.
const T * data() const
Reference to first element of array.
void swap(MooseArray &rhs)
Swap memory in this object with the 'rhs' object.
void shallowCopy(const MooseArray &rhs)
Doesn't actually make a copy of the data.
void setAllValues(const T &value)
Sets all values of the array to the passed in value.
void freeDoubleMooseArray(MooseArray< MooseArray< T >> &a)
MooseArray< T > & operator=(const std::vector< T > &rhs)
Actual operator=...
unsigned int _size
The current number of elements the array can hold.
unsigned int size() const
The number of elements that can currently be stored in the array.
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
unsigned int _allocated_size
Number of allocated memory positions for storage.
std::vector< T > stdVector() const
Extremely inefficient way to produce a std::vector from a MooseArray!
MooseArray(const MooseArray &rhs)
std::unique_ptr< T[]> _data_ptr
Smart pointer storage.
void release()
Manually deallocates the data pointer.
void resize(unsigned int size)
Change the number of elements the array can store.
void clear()
Change the number of elements the array can store to zero.
T & operator[](const unsigned int i)
Get element i out of the array.
MooseArray(const unsigned int size)