TBTK
Need a break? Support the development by playing Polarity Puzzles
TBTK::CArray< DataType > Class Template Reference

Container for a C style array. More...

#include <CArray.h>

Public Member Functions

 CArray ()
 
 CArray (unsigned int size)
 
 CArray (const CArray &carray)
 
 CArray (CArray &&carray)
 
 CArray (const std::string &serialization, Serializable::Mode mode)
 
 ~CArray ()
 
CArrayoperator= (const CArray &carray)
 
CArrayoperator= (CArray &&carray)
 
DataType & operator[] (unsigned int n)
 
const DataType & operator[] (unsigned int n) const
 
DataType * getData ()
 
const DataType * getData () const
 
unsigned int getSize () const
 
std::string serialize (Serializable::Mode mode) const
 

Detailed Description

template<typename DataType>
class TBTK::CArray< DataType >

Container for a C style array.

The CArray contains a pointer to an array and its size. It provides the same efficiency as a raw array, but without requiring manual memory management.

Example

#include "TBTK/CArray.h"
#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
using namespace TBTK;
int main(){
for(unsigned int n = 0; n < carray.getSize(); n++)
carray[n] = n;
for(unsigned int n = 0; n < carray.getSize(); n++)
Streams::out << carray[n] << "\t";
Streams::out << "\n";
unsigned int *rawArray = carray.getData();
for(unsigned int n = 0; n < 10; n++)
Streams::out << rawArray[n] << "\t";
Streams::out << "\n";
}

Output

0 1 2 3 4 5 6 7 8 9
0 1 2 3 4 5 6 7 8 9

Constructor & Destructor Documentation

◆ CArray() [1/5]

template<typename DataType >
TBTK::CArray< DataType >::CArray

Constructor.

◆ CArray() [2/5]

template<typename DataType >
TBTK::CArray< DataType >::CArray ( unsigned int  size)

Constructor.

Parameters
sizeThe size of the array.

◆ CArray() [3/5]

template<typename DataType >
TBTK::CArray< DataType >::CArray ( const CArray< DataType > &  carray)

Copy constructor.

Parameters
carrayThe carray to copy.

◆ CArray() [4/5]

template<typename DataType >
TBTK::CArray< DataType >::CArray ( CArray< DataType > &&  carray)

Move constructor.

Parameters
carrayThe carray to move.

◆ CArray() [5/5]

template<typename DataType >
TBTK::CArray< DataType >::CArray ( const std::string &  serialization,
Serializable::Mode  mode 
)

Constructs a CArray from a serialization string.

Parameters
serializationSerialization string from which to construct the CArray.
modeMode with which the string has been serialized.

◆ ~CArray()

template<typename DataType >
TBTK::CArray< DataType >::~CArray

Destructor.

Member Function Documentation

◆ getData() [1/2]

template<typename DataType >
const DataType * TBTK::CArray< DataType >::getData

Get the data as a bare c-array.

Returns
Pointer to the data array.

◆ getData() [2/2]

template<typename DataType >
const DataType* TBTK::CArray< DataType >::getData ( ) const

Get the data as a bare c-array.

Returns
Pointer to the data array.

◆ getSize()

template<typename DataType >
unsigned int TBTK::CArray< DataType >::getSize

Get size.

Returns
The size of the array.

◆ operator=() [1/2]

template<typename DataType >
CArray< DataType > & TBTK::CArray< DataType >::operator= ( CArray< DataType > &&  carray)

Move assignment operator.

Parameters
rhsThe right hand side of the expression.
Returns
The left hand side after assignment has occured.

◆ operator=() [2/2]

template<typename DataType >
CArray< DataType > & TBTK::CArray< DataType >::operator= ( const CArray< DataType > &  carray)

Assignment operator.

Parameters
rhsThe right hand side of the expression.
Returns
The left hand side after assignment has occured.

◆ operator[]() [1/2]

template<typename DataType >
DataType & TBTK::CArray< DataType >::operator[] ( unsigned int  n)

Array subscript operator.

Parameters
nPosition to get the value for.
Returns
The value at position n.

◆ operator[]() [2/2]

template<typename DataType >
const DataType & TBTK::CArray< DataType >::operator[] ( unsigned int  n) const

Array subscript operator.

Parameters
nPosition to get the value for.
Returns
The value at position n.

◆ serialize()

template<typename DataType >
std::string TBTK::CArray< DataType >::serialize ( Serializable::Mode  mode) const

Serialize the CArray. Note that CArray is pseudo-Serializable in that it implements Serializable interface, but does so non-virtually.

Parameters
modeSerialization mode to use.
Returns
Serialized string representation of the CArray.

The documentation for this class was generated from the following file:
TBTK::CArray
Container for a C style array.
Definition: CArray.h:44
Streams.h
Streams for TBTK output.
TBTK::Initialize
void Initialize()
TBTK::Streams::out
static std::ostream out
Definition: Streams.h:70
CArray.h
Container for a C style array.
TBTK.h
TBTK initialization.