MFEM  v3.4
Finite element discretization library
Public Member Functions | Friends | List of all members
mfem::Array< T > Class Template Reference

#include <array.hpp>

Inheritance diagram for mfem::Array< T >:
[legend]
Collaboration diagram for mfem::Array< T >:
[legend]

Public Member Functions

 Array (int asize=0, int ainc=0)
 Creates array of asize elements. More...
 
 Array (T *_data, int asize, int ainc=0)
 
 Array (const Array< T > &src)
 Copy constructor: deep copy. More...
 
template<typename CT >
 Array (const Array< CT > &src)
 Copy constructor (deep copy) from an Array of convertable type. More...
 
 ~Array ()
 Destructor. More...
 
Array< T > & operator= (const Array< T > &src)
 Assignment operator: deep copy. More...
 
template<typename CT >
Array< T > & operator= (const Array< CT > &src)
 Assignment operator (deep copy) from an Array of convertable 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...
 
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 ()
 Make the Array own the data. More...
 
int Size () const
 Logical size of the array. More...
 
void SetSize (int nsize)
 Change 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...
 
int Capacity () const
 
void Reserve (int capacity)
 Ensures that the allocated size is at least the given size. More...
 
T & operator[] (int i)
 Access element. More...
 
const T & operator[] (int i) const
 Access const element. More...
 
int Append (const T &el)
 Append element 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 element to the array, resize if necessary. More...
 
T & Last ()
 Return the last element in the array. More...
 
const T & Last () const
 
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. More...
 
void DeleteFirst (const T &el)
 Delete the first 'el' entry. More...
 
void DeleteAll ()
 Delete whole array. More...
 
void Copy (Array &copy) const
 Create a copy of the current array. 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)
 
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. This requires operator< to be defined for T. More...
 
template<class Compare >
void Sort (Compare cmp)
 Sorts the array using the supplied comparison function object. More...
 
void Unique ()
 
int IsSorted ()
 return true if the array is sorted. More...
 
void PartialSum ()
 Partial Sum. More...
 
Sum ()
 Sum all entries. More...
 
void operator= (const T &a)
 
void Assign (const T *)
 Copy data from a pointer. Size() elements are copied. More...
 
T * begin () const
 
T * end () const
 
long MemoryUsage () const
 

Friends

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

Additional Inherited Members

- Protected Member Functions inherited from mfem::BaseArray
 BaseArray ()
 
 BaseArray (int asize, int ainc, int elmentsize)
 Creates array of asize elements of size elementsize. More...
 
 ~BaseArray ()
 Free the allocated memory. More...
 
void GrowSize (int minsize, int elementsize)
 
- Protected Attributes inherited from mfem::BaseArray
void * data
 Pointer to data. More...
 
int size
 Size of the array. More...
 
int allocsize
 Size of the allocated memory. More...
 
int inc
 

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. 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 53 of file array.hpp.

Constructor & Destructor Documentation

◆ Array() [1/4]

template<class T>
mfem::Array< T >::Array ( int  asize = 0,
int  ainc = 0 
)
inlineexplicit

Creates array of asize elements.

Definition at line 73 of file array.hpp.

◆ Array() [2/4]

template<class T>
mfem::Array< T >::Array ( T *  _data,
int  asize,
int  ainc = 0 
)
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 79 of file array.hpp.

◆ Array() [3/4]

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

Copy constructor: deep copy.

Definition at line 83 of file array.hpp.

◆ Array() [4/4]

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

Copy constructor (deep copy) from an Array of convertable type.

Definition at line 89 of file array.hpp.

◆ ~Array()

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

Destructor.

Definition at line 94 of file array.hpp.

Member Function Documentation

◆ Append() [1/3]

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

Append element to array, resize if necessary.

Definition at line 614 of file array.hpp.

◆ Append() [2/3]

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 622 of file array.hpp.

◆ Append() [3/3]

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 162 of file array.hpp.

◆ Assign()

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

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

Definition at line 764 of file array.hpp.

◆ begin()

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

Definition at line 266 of file array.hpp.

◆ Capacity()

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 143 of file array.hpp.

◆ Copy()

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

Create a copy of the current array.

Definition at line 190 of file array.hpp.

◆ DeleteAll()

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

Delete whole array.

Definition at line 709 of file array.hpp.

◆ DeleteFirst()

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

Delete the first 'el' entry.

Definition at line 692 of file array.hpp.

◆ DeleteLast()

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

Delete the last entry.

Definition at line 181 of file array.hpp.

◆ end()

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

Definition at line 267 of file array.hpp.

◆ Find()

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 673 of file array.hpp.

◆ FindSorted()

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 683 of file array.hpp.

◆ GetData() [1/2]

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

Returns the data.

Definition at line 115 of file array.hpp.

◆ GetData() [2/2]

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

Returns the data.

Definition at line 117 of file array.hpp.

◆ GetSubArray()

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

Definition at line 745 of file array.hpp.

◆ IsSorted()

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

return true if the array is sorted.

Definition at line 164 of file array.cpp.

◆ Last() [1/2]

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

Return the last element in the array.

Definition at line 647 of file array.hpp.

◆ Last() [2/2]

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

Definition at line 654 of file array.hpp.

◆ Load() [1/2]

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 94 of file array.cpp.

◆ Load() [2/2]

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 225 of file array.hpp.

◆ LoseData()

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

NULL-ifies the data.

Definition at line 127 of file array.hpp.

◆ MakeDataOwner()

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

Make the Array own the data.

Definition at line 130 of file array.hpp.

◆ MakeRef() [1/2]

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

Make this Array a reference to a pointer.

Definition at line 720 of file array.hpp.

◆ MakeRef() [2/2]

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

Make this Array a reference to 'master'.

Definition at line 732 of file array.hpp.

◆ Max()

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 109 of file array.cpp.

◆ MemoryUsage()

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

Definition at line 269 of file array.hpp.

◆ Min()

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 124 of file array.cpp.

◆ operator const T *()

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

Return the data as 'const T *'.

Definition at line 112 of file array.hpp.

◆ operator T*()

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

Return the data as 'T *'.

Definition at line 109 of file array.hpp.

◆ operator=() [1/3]

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

Assignment operator: deep copy.

Definition at line 97 of file array.hpp.

◆ operator=() [2/3]

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

Assignment operator (deep copy) from an Array of convertable type.

Definition at line 101 of file array.hpp.

◆ operator=() [3/3]

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

Definition at line 755 of file array.hpp.

◆ operator[]() [1/2]

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

Access element.

Definition at line 598 of file array.hpp.

◆ operator[]() [2/2]

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

Access const element.

Definition at line 606 of file array.hpp.

◆ OwnsData()

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

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

Definition at line 120 of file array.hpp.

◆ PartialSum()

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

Partial Sum.

Definition at line 140 of file array.cpp.

◆ Prepend()

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

Prepend an element to the array, resize if necessary.

Definition at line 635 of file array.hpp.

◆ Print()

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 64 of file array.cpp.

◆ Reserve()

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 146 of file array.hpp.

◆ Save()

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 81 of file array.cpp.

◆ SetSize() [1/2]

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

Change logical size of the array, keep existing entries.

Definition at line 569 of file array.hpp.

◆ SetSize() [2/2]

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 580 of file array.hpp.

◆ Size()

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

Logical size of the array.

Definition at line 133 of file array.hpp.

◆ Sort() [1/2]

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

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

Definition at line 237 of file array.hpp.

◆ Sort() [2/2]

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

Sorts the array using the supplied comparison function object.

Definition at line 241 of file array.hpp.

◆ StealData()

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

Changes the ownership of the data.

Definition at line 123 of file array.hpp.

◆ Sum()

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

Sum all entries.

Definition at line 152 of file array.cpp.

◆ Union()

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 661 of file array.hpp.

◆ Unique()

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 245 of file array.hpp.

Friends And Related Function Documentation

◆ Swap

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

Definition at line 560 of file array.hpp.


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