36 #ifndef NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
37 #define NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP
46 #include <boost/assign/list_of.hpp>
47 #include <boost/multi_array.hpp>
48 #include <boost/shared_ptr.hpp>
55 template<
typename Dim,
typename DataType>
59 template<
typename DataType>
91 explicit Array(
unsigned int dim1Size) :
111 Array(
unsigned int dim1Size,
const DataType& initValue) :
113 m_capacity(dim1Size),
129 Array(
unsigned int dim1Size,
const DataType* data) :
131 m_capacity(dim1Size),
151 m_capacity(rhs.m_capacity),
153 m_count(rhs.m_count),
154 m_offset(rhs.m_offset)
163 m_capacity(rhs.m_capacity),
165 m_count(rhs.m_count),
166 m_offset(rhs.m_offset)
205 const_iterator
begin()
const {
return m_data + m_offset + 1; }
206 const_iterator
end()
const {
return m_data + m_offset + m_size + 1; }
210 ASSERTL1(static_cast<size_type>(i) < m_size, (std::string(
"Element ") +
211 boost::lexical_cast<std::string>(i) + std::string(
" requested in an array of size ") +
212 boost::lexical_cast<std::string>(m_size)));
213 return *(m_data + i + m_offset + 1);
217 const element*
get()
const {
return m_data+m_offset+1; }
220 const element*
data()
const {
return m_data+m_offset+1; }
236 const element* start =
get();
237 const element* end = start + m_size;
239 const element* rhs_start = rhs.
get();
240 const element* rhs_end = rhs_start + rhs.
num_elements();
242 return (rhs_start >= start && rhs_start <= end) ||
243 (rhs_end >= start && rhs_end <= end);
246 template<
typename T1,
typename T2>
298 m_count = (
unsigned int*)storage;
310 result.m_offset += offset;
311 result.m_size = rhs.m_size - offset;
319 template<
typename DataType>
327 typedef typename ArrayType::index
index;
343 Array(
unsigned int dim1Size,
unsigned int dim2Size) :
349 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType& initValue) :
355 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType* data) :
377 const_iterator
begin()
const {
return m_data->begin(); }
378 const_iterator
end()
const {
return m_data->end(); }
379 const_reference
operator[](index i)
const {
return (*m_data)[i]; }
380 const element*
get()
const {
return m_data->data(); }
381 const element*
data()
const {
return m_data->data(); }
383 const size_type*
shape()
const {
return m_data->shape(); }
386 size_type
GetRows()
const {
return m_data->shape()[0]; }
397 template<
typename DataType>
405 typedef typename ArrayType::index
index;
421 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size) :
422 m_data(
CreateStorage<DataType>(dim1Size, dim2Size, dim3Size))
427 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size,
const DataType& initValue) :
428 m_data(
CreateStorage<DataType>(dim1Size, dim2Size, dim3Size))
444 const_iterator
begin()
const {
return m_data->begin(); }
445 const_iterator
end()
const {
return m_data->end(); }
446 const_reference
operator[](index i)
const {
return (*m_data)[i]; }
447 const element*
get()
const {
return m_data->data(); }
448 const element*
data()
const {
return m_data->data(); }
450 const size_type*
shape()
const {
return m_data->shape(); }
477 template<
typename DataType>
493 explicit Array(
unsigned int dim1Size) :
498 Array(
unsigned int dim1Size,
const DataType& initValue) :
499 BaseType(dim1Size, initValue)
503 Array(
unsigned int dim1Size,
const DataType* data) :
504 BaseType(dim1Size, data)
509 BaseType(dim1Size, rhs)
514 BaseType(dim1Size, rhs.data())
524 BaseType(rhs.num_elements(), rhs.data())
530 BaseType::operator=(rhs);
542 using BaseType::begin;
543 iterator
begin() {
return this->m_data + 1 +this->m_offset; }
546 iterator
end() {
return this->m_data + 1 + this->m_offset + this->m_size; }
548 using BaseType::operator[];
551 ASSERTL1(static_cast<size_type>(i) < this->num_elements(), (std::string(
"Element ") +
552 boost::lexical_cast<std::string>(i) + std::string(
" requested in an array of size ") +
553 boost::lexical_cast<std::string>(this->num_elements())));
559 element*
get() {
return this->m_data + 1 +this->m_offset; }
561 using BaseType::data;
562 element*
data() {
return this->m_data + 1 +this->m_offset; }
564 template<
typename T1>
567 template<
typename T1,
typename T3>
580 ASSERTL1(newSize <= this->m_capacity,
"Can't change an array size to something larger than its capacity.");
581 this->m_size = newSize;
589 template<
typename DataType>
606 Array(
unsigned int dim1Size,
unsigned int dim2Size) :
607 BaseType(dim1Size, dim2Size)
611 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType& initValue) :
612 BaseType(dim1Size, dim2Size, initValue)
616 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType* data) :
617 BaseType(dim1Size, dim2Size, data)
628 BaseType::operator=(rhs);
632 using BaseType::begin;
633 iterator
begin() {
return this->m_data->begin(); }
636 iterator
end() {
return this->m_data->end(); }
638 using BaseType::operator[];
642 element*
get() {
return this->m_data->data(); }
644 using BaseType::data;
645 element*
data() {
return this->m_data->data(); }
652 template<
typename DataType>
669 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size) :
670 BaseType(dim1Size, dim2Size, dim3Size)
674 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size,
const DataType& initValue) :
675 BaseType(dim1Size, dim2Size, dim3Size, initValue)
686 BaseType::operator=(rhs);
690 using BaseType::begin;
691 iterator
begin() {
return this->m_data->begin(); }
694 iterator
end() {
return this->m_data->end(); }
696 using BaseType::operator[];
700 element*
get() {
return this->m_data->data(); }
702 using BaseType::data;
703 element*
data() {
return this->m_data->data(); }
710 const Array<OneD, const NekDouble>& rhs,
714 template<
typename T1,
typename T2>
717 if( lhs.num_elements() != rhs.num_elements() )
722 if( lhs.data() == rhs.data() )
727 for(
unsigned int i = 0; i < lhs.num_elements(); ++i)
729 if( lhs[i] != rhs[i] )
738 template<
typename T1,
typename T2>
741 return !(lhs == rhs);
744 template<
typename DataType>
750 template<
typename DataType>
762 template<
typename ConstDataType,
typename DataType>
770 std::copy(source.data(), source.data() + source.num_elements(), dest.
data());
773 template<
typename ConstDataType,
typename DataType>
793 template<
typename DataType>
799 template<
typename DataType>
802 return !(lhs == rhs);
805 namespace LibUtilities
810 boost::assign::list_of(NullNekDoubleVector);
814 #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
static std::vector< NekDouble > NullNekDoubleVector
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
static std::vector< std::vector< NekDouble > > NullVectorNekDoubleVector
static std::vector< unsigned int > NullUnsignedIntVector
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
#define dest(otri, vertexptr)
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)