PSCF v1.1
|
An Array that acts as a reference to another Array or C array. More...
#include <RArray.h>
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... | |
![]() | |
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 | |
![]() | |
Array () | |
Default constructor. More... | |
![]() | |
Data * | data_ |
Pointer to an array of Data elements. More... | |
int | capacity_ |
Allocated size of the data_ array. More... | |
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.
|
inline |
|
inline |
Copy constructor.
Shallow copy of another RArray
other | another 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_.
|
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.
array | the 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.
|
inline |
Associate this RArray with an existing C array.
array | the target C array |
capacity | the 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.