36 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
37 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
46 #include <boost/multi_array.hpp>
47 #include <boost/shared_ptr.hpp>
54 template<
typename Dim,
typename DataType>
58 template<
typename DataType>
90 explicit Array(
unsigned int dim1Size) :
110 Array(
unsigned int dim1Size,
const DataType& initValue) :
112 m_capacity(dim1Size),
128 Array(
unsigned int dim1Size,
const DataType* data) :
130 m_capacity(dim1Size),
150 m_capacity(rhs.m_capacity),
152 m_count(rhs.m_count),
153 m_offset(rhs.m_offset)
162 m_capacity(rhs.m_capacity),
164 m_count(rhs.m_count),
165 m_offset(rhs.m_offset)
204 const_iterator
begin()
const {
return m_data + m_offset + 1; }
205 const_iterator
end()
const {
return m_data + m_offset + m_size + 1; }
209 ASSERTL1(static_cast<size_type>(i) < m_size, (std::string(
"Element ") +
210 boost::lexical_cast<std::string>(i) + std::string(
" requested in an array of size ") +
211 boost::lexical_cast<std::string>(m_size)));
212 return *(m_data + i + m_offset + 1);
216 const element*
get()
const {
return m_data+m_offset+1; }
219 const element*
data()
const {
return m_data+m_offset+1; }
235 const element* start =
get();
236 const element* end = start + m_size;
238 const element* rhs_start = rhs.
get();
239 const element* rhs_end = rhs_start + rhs.
num_elements();
241 return (rhs_start >= start && rhs_start <= end) ||
242 (rhs_end >= start && rhs_end <= end);
245 template<
typename T1,
typename T2>
297 m_count = (
unsigned int*)storage;
309 result.m_offset += offset;
310 result.m_size = rhs.m_size - offset;
318 template<
typename DataType>
326 typedef typename ArrayType::index
index;
342 Array(
unsigned int dim1Size,
unsigned int dim2Size) :
348 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType& initValue) :
354 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType* data) :
376 const_iterator
begin()
const {
return m_data->begin(); }
377 const_iterator
end()
const {
return m_data->end(); }
378 const_reference
operator[](index i)
const {
return (*m_data)[i]; }
379 const element*
get()
const {
return m_data->data(); }
380 const element*
data()
const {
return m_data->data(); }
382 const size_type*
shape()
const {
return m_data->shape(); }
385 size_type
GetRows()
const {
return m_data->shape()[0]; }
396 template<
typename DataType>
404 typedef typename ArrayType::index
index;
420 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size) :
421 m_data(
CreateStorage<DataType>(dim1Size, dim2Size, dim3Size))
426 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size,
const DataType& initValue) :
427 m_data(
CreateStorage<DataType>(dim1Size, dim2Size, dim3Size))
443 const_iterator
begin()
const {
return m_data->begin(); }
444 const_iterator
end()
const {
return m_data->end(); }
445 const_reference
operator[](index i)
const {
return (*m_data)[i]; }
446 const element*
get()
const {
return m_data->data(); }
447 const element*
data()
const {
return m_data->data(); }
449 const size_type*
shape()
const {
return m_data->shape(); }
476 template<
typename DataType>
492 explicit Array(
unsigned int dim1Size) :
497 Array(
unsigned int dim1Size,
const DataType& initValue) :
498 BaseType(dim1Size, initValue)
502 Array(
unsigned int dim1Size,
const DataType* data) :
503 BaseType(dim1Size, data)
508 BaseType(dim1Size, rhs)
513 BaseType(dim1Size, rhs.data())
523 BaseType(rhs.num_elements(), rhs.data())
529 BaseType::operator=(rhs);
541 using BaseType::begin;
542 iterator
begin() {
return this->m_data + 1 +this->m_offset; }
545 iterator
end() {
return this->m_data + 1 + this->m_offset + this->m_size; }
547 using BaseType::operator[];
550 ASSERTL1(static_cast<size_type>(i) < this->num_elements(), (std::string(
"Element ") +
551 boost::lexical_cast<std::string>(i) + std::string(
" requested in an array of size ") +
552 boost::lexical_cast<std::string>(this->num_elements())));
558 element*
get() {
return this->m_data + 1 +this->m_offset; }
560 using BaseType::data;
561 element*
data() {
return this->m_data + 1 +this->m_offset; }
563 template<
typename T1>
566 template<
typename T1,
typename T3>
579 ASSERTL1(newSize <= this->m_capacity,
"Can't change an array size to something larger than its capacity.");
580 this->m_size = newSize;
588 template<
typename DataType>
605 Array(
unsigned int dim1Size,
unsigned int dim2Size) :
606 BaseType(dim1Size, dim2Size)
610 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType& initValue) :
611 BaseType(dim1Size, dim2Size, initValue)
615 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType* data) :
616 BaseType(dim1Size, dim2Size, data)
627 BaseType::operator=(rhs);
631 using BaseType::begin;
632 iterator
begin() {
return this->m_data->begin(); }
635 iterator
end() {
return this->m_data->end(); }
637 using BaseType::operator[];
641 element*
get() {
return this->m_data->data(); }
643 using BaseType::data;
644 element*
data() {
return this->m_data->data(); }
651 template<
typename DataType>
668 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size) :
669 BaseType(dim1Size, dim2Size, dim3Size)
673 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size,
const DataType& initValue) :
674 BaseType(dim1Size, dim2Size, dim3Size, initValue)
685 BaseType::operator=(rhs);
689 using BaseType::begin;
690 iterator
begin() {
return this->m_data->begin(); }
693 iterator
end() {
return this->m_data->end(); }
695 using BaseType::operator[];
699 element*
get() {
return this->m_data->data(); }
701 using BaseType::data;
702 element*
data() {
return this->m_data->data(); }
709 const Array<OneD, const NekDouble>& rhs,
713 template<
typename T1,
typename T2>
716 if( lhs.num_elements() != rhs.num_elements() )
721 if( lhs.data() == rhs.data() )
726 for(
unsigned int i = 0; i < lhs.num_elements(); ++i)
728 if( lhs[i] != rhs[i] )
737 template<
typename T1,
typename T2>
740 return !(lhs == rhs);
743 template<
typename DataType>
749 template<
typename DataType>
761 template<
typename ConstDataType,
typename DataType>
769 std::copy(source.data(), source.data() + source.num_elements(), dest.
data());
772 template<
typename ConstDataType,
typename DataType>
780 std::copy(source.data(), source.data() + n, dest.
data());
792 template<
typename DataType>
798 template<
typename DataType>
801 return !(lhs == rhs);
807 #endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
const_reference operator[](index i) const
ArrayType::const_iterator const_iterator
#define ASSERTL0(condition, msg)
Array(unsigned int dim1Size, const DataType &initValue)
Creates a 1D array with each element initialized to an initial value.
Array(unsigned int dim1Size, unsigned int dim2Size, unsigned int dim3Size)
Constructs a 3 dimensional array. The elements of the array are not initialized.
Array(const Array< TwoD, DataType > &rhs)
Array(unsigned int dim1Size)
Creates an array of size dim1Size.
const DataType * const_iterator
Array< ThreeD, DataType > & operator=(const Array< ThreeD, DataType > &rhs)
BaseType::element element
static Array< OneD, NekDouble > NullNekDouble1DArray
Array(unsigned int dim1Size, const Array< OneD, DataType > &rhs)
Array(unsigned int dim1Size, unsigned int dim2Size, const DataType &initValue)
Array(const Array< OneD, DataType > &rhs)
size_type num_dimensions() const
Returns 1.
Array< ThreeD, const DataType > & operator=(const Array< ThreeD, const DataType > &rhs)
size_type GetColumns() const
Array(unsigned int dim1Size, unsigned int dim2Size, const DataType &initValue)
Array(const Array< TwoD, const DataType > &rhs)
Array(const Array< ThreeD, DataType > &rhs)
2D array with garbage collection and bounds checking.
Array(unsigned int dim1Size, unsigned int dim2Size, unsigned int dim3Size, const DataType &initValue)
ArrayType::iterator iterator
Array()
Creates an empty array.
ArrayType::const_reference const_reference
Array< TwoD, DataType > & operator=(const Array< TwoD, DataType > &rhs)
ArrayType::size_type size_type
BaseType::iterator iterator
const_iterator begin() const
ArrayType::size_type size_type
ArrayType::element element
void ChangeSize(unsigned int newSize)
bool operator==(const Array< OneD, NekDouble > &lhs, const Array< OneD, NekDouble > &rhs)
ArrayType::reference reference
Array(const Array< OneD, const DataType > &rhs)
BaseType::size_type size_type
boost::shared_ptr< boost::multi_array_ref< DataType, Dim::Value > > CreateStorage(const ExtentListType &extent)
BaseType::element element
size_type GetRows() const
Array(unsigned int dim1Size, const Array< OneD, const DataType > &rhs)
Creates a 1D array that references rhs.
const_iterator end() const
size_type num_elements() const
Returns the array's size.
Array< TwoD, const DataType > & operator=(const Array< TwoD, const DataType > &rhs)
ArrayType::iterator iterator
Array(unsigned int dim1Size)
Array< OneD, const DataType > & operator=(const Array< OneD, const DataType > &rhs)
Creates a reference to rhs.
Array(unsigned int dim1Size, const DataType *data)
Creates a 1D array a copies data into it.
static const NekDouble kNekZeroTol
boost::multi_array_ref< DataType, 2 > ArrayType
size_type num_dimensions() const
AllowWrappingOfConstArrays
static void RawDeallocate(DataType *array, unsigned int NumberOfElements)
Deallocates memory allocated from RawAllocate.
ArrayType::const_reference const_reference
3D array with garbage collection and bounds checking.
BaseType::reference reference
const_iterator end() const
Array(const Array< OneD, const DataType > &rhs)
Creates a reference to rhs.
bool operator!=(const Array< OneD, T1 > &lhs, const Array< OneD, T2 > &rhs)
#define LIB_UTILITIES_EXPORT
bool Overlaps(const Array< OneD, const DataType > &rhs) const
Returns true is this array and rhs overlap.
const_iterator begin() const
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, unsigned int n)
size_type num_elements() const
const size_type * shape() const
Array< OneD, const DataType > BaseType
reference operator[](unsigned int i)
Array< ThreeD, const DataType > BaseType
BaseType::iterator iterator
Array(unsigned int dim1Size, unsigned int dim2Size)
Array(unsigned int dim1Size, unsigned int dim2Size, const DataType *data)
Array< OneD, DataType > operator+(const Array< OneD, DataType > &lhs, unsigned int offset)
const_iterator end() const
static Array< OneD, DataType > CreateWithOffset(const Array< OneD, DataType > &rhs, unsigned int offset)
void CopyArray(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest)
ArrayType::element element
const_iterator begin() const
BaseType::size_type size_type
ArrayType::reference reference
Array(const Array< ThreeD, const DataType > &rhs)
const element * data() const
BaseType::reference reference
Array(unsigned int dim1Size, unsigned int dim2Size, unsigned int dim3Size, const DataType &initValue)
size_type capacity() const
BaseType::size_type size_type
boost::shared_ptr< ArrayType > m_data
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs typedef NekMatrix< LhsDataType, StandardMatrixTag >::iterator iterator
Array(unsigned int dim1Size, const Array< OneD, const DataType > &rhs)
Array(unsigned int dim1Size, const DataType *data)
const DataType & const_reference
Array(unsigned int dim1Size, unsigned int dim2Size, unsigned int dim3Size)
boost::shared_ptr< ArrayType > m_data
Array(unsigned int dim1Size, unsigned int dim2Size)
Constructs a 3 dimensional array. The elements of the array are not initialized.
const_reference operator[](index i) const
Array(unsigned int dim1Size, const DataType &initValue)
ArrayType::const_iterator const_iterator
void CreateStorage(unsigned int size)
unsigned int GetOffset() const
Returns the array's offset.
BaseType::element element
const element * data() const
Returns a c-style pointer to the underlying array.
Array(unsigned int dim1Size, unsigned int dim2Size, const DataType *data)
static DataType * RawAllocate(unsigned int NumberOfElements)
Allocates a chunk of raw, uninitialized memory, capable of holding NumberOfElements objects...
size_type num_dimensions() const
const_reference operator[](unsigned int i) const
const element * data() const
BaseType::reference reference
const size_type * shape() const
const element * get() const
Returns a c-style pointer to the underlying array.
boost::multi_array_ref< DataType, 3 > ArrayType
reference operator[](index i)
static Array< OneD, Array< OneD, NekDouble > > NullNekDoubleArrayofArray
static Array< OneD, int > NullInt1DArray
Array< OneD, DataType > & operator=(const Array< OneD, DataType > &rhs)
size_type num_elements() const
1D Array of constant elements with garbage collection and bounds checking.
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode...
Array(const Array< OneD, const DataType > &rhs, AllowWrappingOfConstArrays a)
Array< TwoD, const DataType > BaseType
BaseType::iterator iterator
reference operator[](index i)
bool IsEqual(const Array< OneD, const NekDouble > &lhs, const Array< OneD, const NekDouble > &rhs, NekDouble tol)
static Array< OneD, T > CreateWithOffset(const Array< OneD, T > &rhs, unsigned int offset)