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>
59 class Array<
OneD, const DataType>
90 explicit Array(
unsigned int dim1Size) :
98 ArrayInitializationPolicy<DataType>::Initialize(m_data + 1, m_capacity);
110 Array(
unsigned int dim1Size,
const DataType& initValue) :
112 m_capacity(dim1Size),
118 ArrayInitializationPolicy<DataType>::Initialize(m_data + 1, m_capacity, initValue);
128 Array(
unsigned int dim1Size,
const DataType* data) :
130 m_capacity(dim1Size),
136 ArrayInitializationPolicy<DataType>::Initialize(m_data + 1, m_capacity, data);
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)
180 ArrayDestructionPolicy<DataType>::Destroy(m_data+1, m_capacity);
191 ArrayDestructionPolicy<DataType>::Destroy(m_data+1, m_capacity);
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; }
236 const element* end = start + m_size;
241 return (rhs_start >= start && rhs_start <= end) ||
242 (rhs_end >= start && rhs_end <= end);
245 template<
typename T1,
typename T2>
246 friend bool operator==(
const Array<OneD, T1>&,
const Array<OneD, T2>&);
261 friend Array<OneD, T>
operator+(
const Array<OneD, T>&
lhs,
unsigned int offset);
264 friend Array<OneD, T>
operator+(
unsigned int offset,
const Array<OneD, T>& rhs);
297 m_count = (
unsigned int*)storage;
306 static Array<OneD, T> CreateWithOffset(
const Array<OneD, T>& rhs,
unsigned int offset)
308 Array<OneD, T> result(rhs);
309 result.m_offset += offset;
310 result.m_size = rhs.m_size - offset;
318 template<
typename DataType>
319 class Array<
TwoD, const DataType>
326 typedef typename ArrayType::index
index;
342 Array(
unsigned int dim1Size,
unsigned int dim2Size) :
345 ArrayInitializationPolicy<DataType>::Initialize(m_data->data(), m_data->num_elements());
348 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType& initValue) :
351 ArrayInitializationPolicy<DataType>::Initialize(m_data->data(), m_data->num_elements(), initValue);
354 Array(
unsigned int dim1Size,
unsigned int dim2Size,
const DataType* data) :
357 ArrayInitializationPolicy<DataType>::Initialize(m_data->data(), m_data->num_elements(), data);
372 friend bool operator==(
const Array<TwoD, T>&,
const Array<TwoD, T>&);
379 const element*
get()
const {
return m_data->data(); }
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))
423 ArrayInitializationPolicy<DataType>::Initialize(m_data->data(), m_data->num_elements());
426 Array(
unsigned int dim1Size,
unsigned int dim2Size,
unsigned int dim3Size,
const DataType& initValue) :
427 m_data(
CreateStorage<DataType>(dim1Size, dim2Size, dim3Size))
429 ArrayInitializationPolicy<DataType>::Initialize(m_data->data(), m_data->num_elements(), initValue);
446 const element*
get()
const {
return m_data->data(); }
476 template<
typename DataType>
477 class Array<
OneD, DataType> :
public Array<OneD, const DataType>
492 explicit Array(
unsigned int dim1Size) :
497 Array(
unsigned int dim1Size,
const DataType& initValue) :
502 Array(
unsigned int dim1Size,
const DataType* data) :
523 BaseType(rhs.num_elements(), rhs.data())
529 BaseType::operator=(rhs);
541 using BaseType::begin;
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;
563 template<
typename T1>
566 template<
typename T1,
typename T3>
567 friend class NekMatrix;
577 void ChangeSize(
unsigned int newSize)
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>
589 class Array<
TwoD, DataType> :
public Array<TwoD, const DataType>
605 Array(
unsigned int dim1Size,
unsigned int 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) :
627 BaseType::operator=(rhs);
631 using BaseType::begin;
637 using BaseType::operator[];
641 element*
get() {
return this->m_data->data(); }
643 using BaseType::data;
651 template<
typename DataType>
652 class Array<
ThreeD, DataType> :
public Array<ThreeD, const 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;
695 using BaseType::operator[];
699 element*
get() {
return this->m_data->data(); }
701 using BaseType::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());
788 const Array<TwoD, const NekDouble>& rhs,
792 template<
typename DataType>
798 template<
typename DataType>
801 return !(lhs == rhs);
807 #endif //NEKTAR_LIB_UTILITIES_BASIC_UTILS_SHARED_ARRAY_HPP