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;
195 template <
typename T>
199 for (
unsigned int i = 0; i < _size; i++)
203 template <
typename T>
210 template <
typename T>
211 template <
bool value_initialize>
215 if (size > _allocated_size)
217 if constexpr (value_initialize)
218 _data_ptr.reset(
new T[size]());
220 _data_ptr = std::make_unique<T[]>(size);
221 mooseAssert(_data_ptr,
"Failed to allocate MooseArray memory!");
223 _data = _data_ptr.get();
224 _allocated_size = size;
230 template <
typename T>
234 if (size > _allocated_size)
236 auto new_pointer = std::make_unique<T[]>(size);
237 mooseAssert(new_pointer,
"Failed to allocate MooseArray memory!");
240 for (
unsigned int i = 0; i < _size; i++)
241 new_pointer[i] = _data[i];
243 _data_ptr = std::move(new_pointer);
244 _data = _data_ptr.get();
245 _allocated_size = size;
248 for (
unsigned int i = _size; i < size; i++)
249 _data[i] = default_value;
254 template <
typename T>
261 template <
typename T>
265 mooseAssert(i < _size,
266 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
271 template <
typename T>
275 mooseAssert(i < _size,
276 "Access out of bounds in MooseArray (i: " << i <<
" size: " << _size <<
")");
281 template <
typename T>
291 template <
typename T>
301 template <
typename T>
308 _allocated_size = rhs.size();
311 template <
typename T>
315 unsigned int rhs_size = rhs.size();
319 for (
unsigned int i = 0; i < rhs_size; i++)
325 template <
typename T>
333 for (
unsigned int i = 0; i < _size; i++)
334 _data[i] = rhs.
_data[i];
343 return std::vector<T>(_data, _data + _size);
350 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)