PSCF v1.1
Public Member Functions | List of all members
Util::RArray< Data > Class Template Reference

An Array that acts as a reference to another Array or C array. More...

#include <RArray.h>

Inheritance diagram for Util::RArray< Data >:
Util::Array< Data >

Public Member Functions

 RArray ()
 Constructor. More...
 
 RArray (RArray< Data > const &other)
 Copy constructor. More...
 
void associate (Array< Data > &array)
 Associate this RArray with an existing Array object. More...
 
void associate (Data *array, int capacity)
 Associate this RArray with an existing C array. More...
 
- Public Member Functions inherited from Util::Array< Data >
virtual ~Array ()
 Destructor. More...
 
int capacity () const
 Return allocated size. More...
 
void begin (ArrayIterator< Data > &iterator)
 Set an iterator to begin this Array. More...
 
void begin (ConstArrayIterator< Data > &iterator) const
 Set a const iterator to begin this Array. More...
 
Data & operator[] (int i)
 Get an element by non-const reference. More...
 
Data const & operator[] (int i) const
 Get an element by const reference. More...
 
Data * cArray ()
 Return a pointer to the underlying C array. More...
 
Data const * cArray () const
 Return pointer to const to the underlying C array. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Util::Array< Data >
 Array ()
 Default constructor. More...
 
- Protected Attributes inherited from Util::Array< Data >
Data * data_
 Pointer to an array of Data elements. More...
 
int capacity_
 Allocated size of the data_ array. More...
 

Detailed Description

template<typename Data>
class Util::RArray< Data >

An Array that acts as a reference to another Array or C array.

An RArray is associated with a "target" DArray or C array by the associate() method. The RArray and its target array then wrap the same underlying C array, and so access the same data. The associate() method simply copies the address and capacity of a C array. An RArray can be associated only once, after which it can be safely used as an alias for its target.

An RArray can only be associated with a DArray after the target DArray has been allocated. Because a DArray can be allocated only once, this association cannot be corrupted by re-allocation or re-sizing of the target DArray.

An RArray can be created from another RArray only after the target RArray has already been associated with some other Array.

An RArray differs from a C++ reference to an Array because a C++ reference must be initialized when it is instantiated, whereas an RArray is associated after it is instantiated. Because association is implemented by copying the address and capacity of a shared C array, access through an RArray should be exactly as efficient as access through a DArray.

Definition at line 46 of file RArray.h.

Constructor & Destructor Documentation

◆ RArray() [1/2]

template<typename Data >
Util::RArray< Data >::RArray ( )
inline

Constructor.

Definition at line 57 of file RArray.h.

◆ RArray() [2/2]

template<typename Data >
Util::RArray< Data >::RArray ( RArray< Data > const &  other)
inline

Copy constructor.

Shallow copy of another RArray

Parameters
otheranother RArray<Data> for which this is an alias.

Definition at line 68 of file RArray.h.

References Util::Array< Data >::capacity_, and Util::Array< Data >::data_.

Member Function Documentation

◆ associate() [1/2]

template<typename Data >
void Util::RArray< Data >::associate ( Array< Data > &  array)
inline

Associate this RArray with an existing Array object.

The target (i.e., the parameter array) must be allocated when this method is invoked, as discussed in the RArray class documentation.

Parameters
arraythe target Array

Definition at line 83 of file RArray.h.

References Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, and UTIL_THROW.

◆ associate() [2/2]

template<typename Data >
void Util::RArray< Data >::associate ( Data *  array,
int  capacity 
)
inline

Associate this RArray with an existing C array.

Parameters
arraythe target C array
capacitythe number of elements in the target array

Definition at line 101 of file RArray.h.

References Util::Array< Data >::capacity(), Util::Array< Data >::capacity_, Util::Array< Data >::data_, and UTIL_THROW.


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