MFEM  v4.2.0
Finite element discretization library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
mfem::Array< T > Class Template Reference

#include <adios2stream.hpp>

Public Member Functions

 Array ()
 Creates an empty array. More...
 
 Array (MemoryType mt)
 Creates an empty array with a given MemoryType. More...
 
 Array (int asize)
 Creates array of asize elements. More...
 
 Array (T *_data, int asize)
 Creates array using an existing c-array of asize elements; allocsize is set to -asize to indicate that the data will not be deleted. More...
 
 Array (const Array &src)
 Copy constructor: deep copy from src. More...
 
template<typename CT >
 Array (const Array< CT > &src)
 Copy constructor (deep copy) from 'src', an Array of convertible type. More...
 
 ~Array ()
 Destructor. More...
 
Array< T > & operator= (const Array< T > &src)
 Assignment operator: deep copy from 'src'. More...
 
template<typename CT >
Arrayoperator= (const Array< CT > &src)
 Assignment operator (deep copy) from src, an Array of convertible type. More...
 
 operator T * ()
 Return the data as 'T *'. More...
 
 operator const T * () const
 Return the data as 'const T *'. More...
 
T * GetData ()
 Returns the data. More...
 
const T * GetData () const
 Returns the data. More...
 
Memory< T > & GetMemory ()
 Return a reference to the Memory object used by the Array. More...
 
const Memory< T > & GetMemory () const
 Return a reference to the Memory object used by the Array, const version. More...
 
bool UseDevice () const
 Return the device flag of the Memory object used by the Array. More...
 
bool OwnsData () const
 Return true if the data will be deleted by the array. More...
 
void StealData (T **p)
 Changes the ownership of the data. More...
 
void LoseData ()
 NULL-ifies the data. More...
 
void MakeDataOwner () const
 Make the Array own the data. More...
 
int Size () const
 Return the logical size of the array. More...
 
void SetSize (int nsize)
 Change the logical size of the array, keep existing entries. More...
 
void SetSize (int nsize, const T &initval)
 Same as SetSize(int) plus initialize new entries with 'initval'. More...
 
void SetSize (int nsize, MemoryType mt)
 Resize the array to size nsize using MemoryType mt. Note that unlike the other versions of SetSize(), the current content of the array is not preserved. More...
 
int Capacity () const
 
void Reserve (int capacity)
 Ensures that the allocated size is at least the given size. More...
 
T & operator[] (int i)
 Reference access to the ith element. More...
 
const T & operator[] (int i) const
 Const reference access to the ith element. More...
 
int Append (const T &el)
 Append element 'el' to array, resize if necessary. More...
 
int Append (const T *els, int nels)
 Append another array to this array, resize if necessary. More...
 
int Append (const Array< T > &els)
 Append another array to this array, resize if necessary. More...
 
int Prepend (const T &el)
 Prepend an 'el' to the array, resize if necessary. More...
 
T & Last ()
 Return the last element in the array. More...
 
const T & Last () const
 Return the last element in the array. More...
 
int Union (const T &el)
 Append element when it is not yet in the array, return index. More...
 
int Find (const T &el) const
 Return the first index where 'el' is found; return -1 if not found. More...
 
int FindSorted (const T &el) const
 Do bisection search for 'el' in a sorted array; return -1 if not found. More...
 
void DeleteLast ()
 Delete the last entry of the array. More...
 
void DeleteFirst (const T &el)
 Delete the first entry with value == 'el'. More...
 
void DeleteAll ()
 Delete the whole array. More...
 
void Copy (Array &copy) const
 Create a copy of the internal array to the provided copy. More...
 
void MakeRef (T *, int)
 Make this Array a reference to a pointer. More...
 
void MakeRef (const Array &master)
 Make this Array a reference to 'master'. More...
 
void GetSubArray (int offset, int sa_size, Array< T > &sa) const
 Copy sub array starting from offset out to the provided sa. More...
 
void Print (std::ostream &out=mfem::out, int width=4) const
 Prints array to stream with width elements per row. More...
 
void Save (std::ostream &out, int fmt=0) const
 Save the Array to the stream out using the format fmt. The format fmt can be: More...
 
void Load (std::istream &in, int fmt=0)
 Read an Array from the stream in using format fmt. The format fmt can be: More...
 
void Load (int new_size, std::istream &in)
 Set the Array size to new_size and read that many entries from the stream in. More...
 
Max () const
 Find the maximal element in the array, using the comparison operator < for class T. More...
 
Min () const
 Find the minimal element in the array, using the comparison operator < for class T. More...
 
void Sort ()
 Sorts the array in ascending order. This requires operator< to be defined for T. More...
 
template<class Compare >
void Sort (Compare cmp)
 Sorts the array in ascending order using the supplied comparison function object. More...
 
void Unique ()
 Removes duplicities from a sorted array. This requires operator== to be defined for T. More...
 
int IsSorted ()
 Return 1 if the array is sorted from lowest to highest. Otherwise return 0. More...
 
void PartialSum ()
 Fill the entries of the array with the cumulative sum of the entries. More...
 
Sum ()
 Return the sum of all the array entries using the '+'' operator for class 'T'. More...
 
void operator= (const T &a)
 Set all entries of the array to the provided constant. More...
 
void Assign (const T *)
 Copy data from a pointer. 'Size()' elements are copied. More...
 
template<typename U >
void CopyTo (U *dest)
 STL-like copyTo dest from begin to end. More...
 
template<typename U >
void CopyFrom (const U *src)
 Copy from src into this array. Copies enough entries to fill the Capacity size of this array. Careful this does not update the Size to match this Capacity after this. More...
 
T * begin ()
 STL-like begin. Returns pointer to the first element of the array. More...
 
T * end ()
 STL-like end. Returns pointer after the last element of the array. More...
 
const T * begin () const
 STL-like begin. Returns const pointer to the first element of the array. More...
 
const T * end () const
 STL-like end. Returns const pointer after the last element of the array. More...
 
long MemoryUsage () const
 Returns the number of bytes allocated for the array including any reserve. More...
 
const T * Read (bool on_dev=true) const
 Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev). More...
 
const T * HostRead () const
 Shortcut for mfem::Read(a.GetMemory(), a.Size(), false). More...
 
T * Write (bool on_dev=true)
 Shortcut for mfem::Write(a.GetMemory(), a.Size(), on_dev). More...
 
T * HostWrite ()
 Shortcut for mfem::Write(a.GetMemory(), a.Size(), false). More...
 
T * ReadWrite (bool on_dev=true)
 Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), on_dev). More...
 
T * HostReadWrite ()
 Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), false). More...
 
template<typename CT >
Array< T > & operator= (const Array< CT > &src)
 

Protected Member Functions

void GrowSize (int minsize)
 

Protected Attributes

Memory< T > data
 Pointer to data. More...
 
int size
 Size of the array. More...
 

Friends

void Swap (Array< T > &, Array< T > &)
 

Detailed Description

template<class T>
class mfem::Array< T >

Abstract data type Array.

Array<T> is an automatically increasing array containing elements of the generic type T, which must be a POD (plain old data) type. The allocated size may be larger then the logical size of the array. The elements can be accessed by the [] operator, the range is 0 to size-1.

Definition at line 44 of file adios2stream.hpp.

Constructor & Destructor Documentation

template<class T>
mfem::Array< T >::Array ( )
inline

Creates an empty array.

Definition at line 58 of file array.hpp.

template<class T>
mfem::Array< T >::Array ( MemoryType  mt)
inline

Creates an empty array with a given MemoryType.

Definition at line 61 of file array.hpp.

template<class T>
mfem::Array< T >::Array ( int  asize)
inlineexplicit

Creates array of asize elements.

Definition at line 64 of file array.hpp.

template<class T>
mfem::Array< T >::Array ( T *  _data,
int  asize 
)
inline

Creates array using an existing c-array of asize elements; allocsize is set to -asize to indicate that the data will not be deleted.

Definition at line 70 of file array.hpp.

template<class T>
mfem::Array< T >::Array ( const Array< T > &  src)
inline

Copy constructor: deep copy from src.

This method supports source arrays using any MemoryType.

Definition at line 618 of file array.hpp.

template<typename T >
template<typename CT >
mfem::Array< T >::Array ( const Array< CT > &  src)
inline

Copy constructor (deep copy) from 'src', an Array of convertible type.

Definition at line 627 of file array.hpp.

template<class T>
mfem::Array< T >::~Array ( )
inline

Destructor.

Definition at line 82 of file array.hpp.

Member Function Documentation

template<class T>
int mfem::Array< T >::Append ( const T &  el)
inline

Append element 'el' to array, resize if necessary.

Definition at line 726 of file array.hpp.

template<class T>
int mfem::Array< T >::Append ( const T *  els,
int  nels 
)
inline

Append another array to this array, resize if necessary.

Definition at line 734 of file array.hpp.

template<class T>
int mfem::Array< T >::Append ( const Array< T > &  els)
inline

Append another array to this array, resize if necessary.

Definition at line 158 of file array.hpp.

template<class T>
void mfem::Array< T >::Assign ( const T *  p)
inline

Copy data from a pointer. 'Size()' elements are copied.

Definition at line 875 of file array.hpp.

template<class T>
T* mfem::Array< T >::begin ( )
inline

STL-like begin. Returns pointer to the first element of the array.

Definition at line 275 of file array.hpp.

template<class T>
const T* mfem::Array< T >::begin ( ) const
inline

STL-like begin. Returns const pointer to the first element of the array.

Definition at line 281 of file array.hpp.

template<class T>
int mfem::Array< T >::Capacity ( ) const
inline

Maximum number of entries the array can store without allocating more memory.

Definition at line 139 of file array.hpp.

template<typename T >
void mfem::Array< T >::Copy ( Array< T > &  copy) const
inline

Create a copy of the internal array to the provided copy.

Definition at line 831 of file array.hpp.

template<class T>
template<typename U >
void mfem::Array< T >::CopyFrom ( const U *  src)
inline

Copy from src into this array. Copies enough entries to fill the Capacity size of this array. Careful this does not update the Size to match this Capacity after this.

Definition at line 271 of file array.hpp.

template<class T>
template<typename U >
void mfem::Array< T >::CopyTo ( U *  dest)
inline

STL-like copyTo dest from begin to end.

Definition at line 265 of file array.hpp.

template<class T >
void mfem::Array< T >::DeleteAll ( )
inline

Delete the whole array.

Definition at line 821 of file array.hpp.

template<class T>
void mfem::Array< T >::DeleteFirst ( const T &  el)
inline

Delete the first entry with value == 'el'.

Definition at line 804 of file array.hpp.

template<class T>
void mfem::Array< T >::DeleteLast ( )
inline

Delete the last entry of the array.

Definition at line 179 of file array.hpp.

template<class T>
T* mfem::Array< T >::end ( )
inline

STL-like end. Returns pointer after the last element of the array.

Definition at line 278 of file array.hpp.

template<class T>
const T* mfem::Array< T >::end ( ) const
inline

STL-like end. Returns const pointer after the last element of the array.

Definition at line 284 of file array.hpp.

template<class T>
int mfem::Array< T >::Find ( const T &  el) const
inline

Return the first index where 'el' is found; return -1 if not found.

Definition at line 785 of file array.hpp.

template<class T>
int mfem::Array< T >::FindSorted ( const T &  el) const
inline

Do bisection search for 'el' in a sorted array; return -1 if not found.

Definition at line 795 of file array.hpp.

template<class T>
T* mfem::Array< T >::GetData ( )
inline

Returns the data.

Definition at line 98 of file array.hpp.

template<class T>
const T* mfem::Array< T >::GetData ( ) const
inline

Returns the data.

Definition at line 100 of file array.hpp.

template<class T>
Memory<T>& mfem::Array< T >::GetMemory ( )
inline

Return a reference to the Memory object used by the Array.

Definition at line 103 of file array.hpp.

template<class T>
const Memory<T>& mfem::Array< T >::GetMemory ( ) const
inline

Return a reference to the Memory object used by the Array, const version.

Definition at line 106 of file array.hpp.

template<class T>
void mfem::Array< T >::GetSubArray ( int  offset,
int  sa_size,
Array< T > &  sa 
) const
inline

Copy sub array starting from offset out to the provided sa.

Definition at line 856 of file array.hpp.

template<class T >
void mfem::Array< T >::GrowSize ( int  minsize)
inlineprotected

Definition at line 635 of file array.hpp.

template<class T>
const T* mfem::Array< T >::HostRead ( ) const
inline

Shortcut for mfem::Read(a.GetMemory(), a.Size(), false).

Definition at line 294 of file array.hpp.

template<class T>
T* mfem::Array< T >::HostReadWrite ( )
inline

Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), false).

Definition at line 310 of file array.hpp.

template<class T>
T* mfem::Array< T >::HostWrite ( )
inline

Shortcut for mfem::Write(a.GetMemory(), a.Size(), false).

Definition at line 302 of file array.hpp.

template<class T >
int mfem::Array< T >::IsSorted ( )

Return 1 if the array is sorted from lowest to highest. Otherwise return 0.

Definition at line 127 of file array.cpp.

template<class T >
T & mfem::Array< T >::Last ( )
inline

Return the last element in the array.

Definition at line 759 of file array.hpp.

template<class T >
const T & mfem::Array< T >::Last ( ) const
inline

Return the last element in the array.

Definition at line 766 of file array.hpp.

template<class T >
void mfem::Array< T >::Load ( std::istream &  in,
int  fmt = 0 
)

Read an Array from the stream in using format fmt. The format fmt can be:

0 - read the size then the entries 1 - read Size() entries

Definition at line 53 of file array.cpp.

template<class T>
void mfem::Array< T >::Load ( int  new_size,
std::istream &  in 
)
inline

Set the Array size to new_size and read that many entries from the stream in.

Definition at line 222 of file array.hpp.

template<class T>
void mfem::Array< T >::LoseData ( )
inline

NULL-ifies the data.

Definition at line 118 of file array.hpp.

template<class T>
void mfem::Array< T >::MakeDataOwner ( ) const
inline

Make the Array own the data.

Definition at line 121 of file array.hpp.

template<class T>
void mfem::Array< T >::MakeRef ( T *  p,
int  s 
)
inline

Make this Array a reference to a pointer.

Definition at line 839 of file array.hpp.

template<class T>
void mfem::Array< T >::MakeRef ( const Array< T > &  master)
inline

Make this Array a reference to 'master'.

Definition at line 847 of file array.hpp.

template<class T >
T mfem::Array< T >::Max ( ) const

Find the maximal element in the array, using the comparison operator < for class T.

Definition at line 68 of file array.cpp.

template<class T>
long mfem::Array< T >::MemoryUsage ( ) const
inline

Returns the number of bytes allocated for the array including any reserve.

Definition at line 287 of file array.hpp.

template<class T >
T mfem::Array< T >::Min ( ) const

Find the minimal element in the array, using the comparison operator < for class T.

Definition at line 85 of file array.cpp.

template<class T>
mfem::Array< T >::operator const T * ( ) const
inline

Return the data as 'const T *'.

Definition at line 95 of file array.hpp.

template<class T>
mfem::Array< T >::operator T * ( )
inline

Return the data as 'T *'.

Definition at line 92 of file array.hpp.

template<class T>
Array<T>& mfem::Array< T >::operator= ( const Array< T > &  src)
inline

Assignment operator: deep copy from 'src'.

Definition at line 85 of file array.hpp.

template<class T>
template<typename CT >
Array& mfem::Array< T >::operator= ( const Array< CT > &  src)
inline

Assignment operator (deep copy) from src, an Array of convertible type.

template<class T>
void mfem::Array< T >::operator= ( const T &  a)
inline

Set all entries of the array to the provided constant.

Definition at line 866 of file array.hpp.

template<class T>
template<typename CT >
Array<T>& mfem::Array< T >::operator= ( const Array< CT > &  src)
inline

Definition at line 646 of file array.hpp.

template<class T >
T & mfem::Array< T >::operator[] ( int  i)
inline

Reference access to the ith element.

Definition at line 710 of file array.hpp.

template<class T >
const T & mfem::Array< T >::operator[] ( int  i) const
inline

Const reference access to the ith element.

Definition at line 718 of file array.hpp.

template<class T>
bool mfem::Array< T >::OwnsData ( ) const
inline

Return true if the data will be deleted by the array.

Definition at line 112 of file array.hpp.

template<class T >
void mfem::Array< T >::PartialSum ( )

Fill the entries of the array with the cumulative sum of the entries.

Definition at line 103 of file array.cpp.

template<class T>
int mfem::Array< T >::Prepend ( const T &  el)
inline

Prepend an 'el' to the array, resize if necessary.

Definition at line 747 of file array.hpp.

template<class T >
void mfem::Array< T >::Print ( std::ostream &  out = mfem::out,
int  width = 4 
) const

Prints array to stream with width elements per row.

Definition at line 23 of file array.cpp.

template<class T>
const T* mfem::Array< T >::Read ( bool  on_dev = true) const
inline

Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).

Definition at line 290 of file array.hpp.

template<class T>
T* mfem::Array< T >::ReadWrite ( bool  on_dev = true)
inline

Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), on_dev).

Definition at line 306 of file array.hpp.

template<class T>
void mfem::Array< T >::Reserve ( int  capacity)
inline

Ensures that the allocated size is at least the given size.

Definition at line 142 of file array.hpp.

template<class T >
void mfem::Array< T >::Save ( std::ostream &  out,
int  fmt = 0 
) const

Save the Array to the stream out using the format fmt. The format fmt can be:

0 - write the size followed by all entries 1 - write only the entries

Definition at line 40 of file array.cpp.

template<class T >
void mfem::Array< T >::SetSize ( int  nsize)
inline

Change the logical size of the array, keep existing entries.

Definition at line 654 of file array.hpp.

template<class T>
void mfem::Array< T >::SetSize ( int  nsize,
const T &  initval 
)
inline

Same as SetSize(int) plus initialize new entries with 'initval'.

Definition at line 665 of file array.hpp.

template<class T>
void mfem::Array< T >::SetSize ( int  nsize,
MemoryType  mt 
)
inline

Resize the array to size nsize using MemoryType mt. Note that unlike the other versions of SetSize(), the current content of the array is not preserved.

Definition at line 683 of file array.hpp.

template<class T>
int mfem::Array< T >::Size ( ) const
inline

Return the logical size of the array.

Definition at line 124 of file array.hpp.

template<class T>
void mfem::Array< T >::Sort ( )
inline

Sorts the array in ascending order. This requires operator< to be defined for T.

Definition at line 234 of file array.hpp.

template<class T>
template<class Compare >
void mfem::Array< T >::Sort ( Compare  cmp)
inline

Sorts the array in ascending order using the supplied comparison function object.

Definition at line 238 of file array.hpp.

template<class T>
void mfem::Array< T >::StealData ( T **  p)
inline

Changes the ownership of the data.

Definition at line 115 of file array.hpp.

template<class T >
T mfem::Array< T >::Sum ( )

Return the sum of all the array entries using the '+'' operator for class 'T'.

Definition at line 115 of file array.cpp.

template<class T>
int mfem::Array< T >::Union ( const T &  el)
inline

Append element when it is not yet in the array, return index.

Definition at line 773 of file array.hpp.

template<class T>
void mfem::Array< T >::Unique ( )
inline

Removes duplicities from a sorted array. This requires operator== to be defined for T.

Definition at line 242 of file array.hpp.

template<class T>
bool mfem::Array< T >::UseDevice ( ) const
inline

Return the device flag of the Memory object used by the Array.

Definition at line 109 of file array.hpp.

template<class T>
T* mfem::Array< T >::Write ( bool  on_dev = true)
inline

Shortcut for mfem::Write(a.GetMemory(), a.Size(), on_dev).

Definition at line 298 of file array.hpp.

Friends And Related Function Documentation

template<class T>
void Swap ( Array< T > &  a,
Array< T > &  b 
)
friend

Member Data Documentation

template<class T>
Memory<T> mfem::Array< T >::data
protected

Pointer to data.

Definition at line 48 of file array.hpp.

template<class T>
int mfem::Array< T >::size
protected

Size of the array.

Definition at line 50 of file array.hpp.


The documentation for this class was generated from the following files: