rcolyer.net
RC Lib  Version 202403231100
Public Member Functions | Friends | List of all members
RC::Data3D< T > Class Template Reference

A bounds-safe three-dimensional resizeable structure. More...

#include <Data3D.h>

Public Member Functions

 Data3D ()
 Default constructor which initializes to size 0, 0, 0.
 
 Data3D (size_t d_size1, size_t d_size2, size_t d_size3)
 Constructor which sets the initial sizes. More...
 
 Data3D (const Data3D< T > &copy)
 Copy constructor that copies all elements. More...
 
 Data3D (const std::initializer_list< Data2D< T >> &new_data)
 Initializer list constructor, initializes with nested brackets.
 
 ~Data3D ()
 Deletes all contents upon destruction.
 
void Delete ()
 Delete all the elements and free all allocated memory.
 
void Clear ()
 Identical to Delete().
 
void Crop ()
 Reduces memory consumption to only that necessary for the current size. More...
 
bool IsEmpty () const
 
Data3Doperator= (const Data3D &other)
 Assignment operator which copies all contents from other. More...
 
Data2D< T > & operator[] (size_t x)
 Bounds-checked access of a Data2D corresponding to the data at index x in dimension 3. More...
 
Data2D< T > & operator() (size_t x)
 Identical to Data3D::operator[].
 
const Data2D< T > & operator[] (size_t x) const
 Const version of Data3D::operator[].
 
const Data2D< T > & operator() (size_t x) const
 Const version of Data3D::operator[].
 
T & operator() (size_t x, size_t y, size_t z)
 Bounds-checked access of an element. More...
 
const T & operator() (size_t x, size_t y, size_t z) const
 Const version of Data3D::operator()(size_t x, size_t y, size_t z)
 
T & At (size_t x, size_t y, size_t z)
 Equivalent to Data3D::operator()(size_t x, size_t y, size_t z)
 
const T & At (size_t x, size_t y, size_t z) const
 Const version of Data3D::operator()(size_t x, size_t y, size_t z))
 
size_t size1 () const
 Get the size of dimension 1.
 
size_t size2 () const
 Get the size of dimension 2.
 
size_t size3 () const
 Get the size of dimension 3.
 
size_t TypeSize () const
 Returns sizeof(T).
 
void Zero ()
 Sets all elements equal to 0. More...
 
bool Check (const size_t x, const size_t y, const size_t z) const
 Check if the indices x, y, and z are in bounds. More...
 
void Assert (const size_t x, const size_t y, const size_t z) const
 Throw an ErrorMsgBounds exception if either x, y, or z is out of bounds. More...
 
void Resize (const size_t resize_size1, const size_t resize_size2, const size_t resize_size3)
 Resize the array, reallocating if necessary. More...
 
T *** Raw ()
 Access a raw unprotected 3-dimensional C-array for the enclosed data. More...
 
const Data1D< Data2D< T > > & RawData () const
 Access the underlying nested Data1D/Data2D structure for this object. More...
 
Data1D< Data2D< T > > & RawData ()
 Const version of RawData().
 
void ToLilEndian ()
 Convert endianness of all elements if needed, for supported types.
 
void FromLilEndian ()
 Convert endianness of all elements if needed, for supported types.
 
void ToBigEndian ()
 Convert endianness of all elements if needed, for supported types.
 
void FromBigEndian ()
 Convert endianness of all elements if needed, for supported types.
 

Friends

template<class T2 >
void swap (Data3D< T2 > &a, Data3D< T2 > &b)
 Efficiently swap all the contents of a and b.
 

Detailed Description

template<class T>
class RC::Data3D< T >

A bounds-safe three-dimensional resizeable structure.

See also
Data1D
Data2D

Constructor & Destructor Documentation

◆ Data3D() [1/2]

template<class T >
RC::Data3D< T >::Data3D ( size_t  d_size1,
size_t  d_size2,
size_t  d_size3 
)
inlineexplicit

Constructor which sets the initial sizes.

Efficiency note: The first dimension, set by d_size1, should be the one which is iterated over most frequently in innermost loops for caching gains. Note: Non-POD classes stored in Data3D containers must have a default constructor with default values or no arguments.

Parameters
d_size1The size of the first dimension.
d_size2The size of the second dimension.
d_size3The size of the third dimension.

◆ Data3D() [2/2]

template<class T >
RC::Data3D< T >::Data3D ( const Data3D< T > &  copy)
inline

Copy constructor that copies all elements.

Parameters
copyA source Data3D from which elements should be copied.

Member Function Documentation

◆ Assert()

template<class T >
void RC::Data3D< T >::Assert ( const size_t  x,
const size_t  y,
const size_t  z 
) const
inline

Throw an ErrorMsgBounds exception if either x, y, or z is out of bounds.

Parameters
xThe index for dimension 1.
yThe index for dimension 2.
zThe index for dimension 3.

◆ Check()

template<class T >
bool RC::Data3D< T >::Check ( const size_t  x,
const size_t  y,
const size_t  z 
) const
inline

Check if the indices x, y, and z are in bounds.

Parameters
xThe index for dimension 1.
yThe index for dimension 2.
zThe index for dimension 3.
Returns
True of in bounds.

◆ Crop()

template<class T >
void RC::Data3D< T >::Crop ( )
inline

Reduces memory consumption to only that necessary for the current size.

Efficiency note: This function may copy all elements if necessary for reallocating.

◆ IsEmpty()

template<class T >
bool RC::Data3D< T >::IsEmpty ( ) const
inline
Returns
True of there are no elements / at least one size is 0.

◆ operator()()

template<class T >
T& RC::Data3D< T >::operator() ( size_t  x,
size_t  y,
size_t  z 
)
inline

Bounds-checked access of an element.

Throws an ErrorMsgBounds if out of bounds. Note that for Data3D<int> arr; arr(x, y, z) is equivalent to arr[z][y][x].

Parameters
xThe index of dimension 1
yThe index of dimension 2.
zThe index of dimension 3.
Returns
A reference to the indexed element.

◆ operator=()

template<class T >
Data3D& RC::Data3D< T >::operator= ( const Data3D< T > &  other)
inline

Assignment operator which copies all contents from other.

Parameters
otherData3D to copy from.
Returns
This object.

◆ operator[]()

template<class T >
Data2D<T>& RC::Data3D< T >::operator[] ( size_t  x)
inline

Bounds-checked access of a Data2D corresponding to the data at index x in dimension 3.

Throws an ErrorMsgBounds if out of bounds. Usage note: Data3D<int> arr(size1, size2, size3); int val = arr[x3][x2][x1];

Parameters
xThe index of dimension 3.
Returns
A Data2D of the elements in dimension 1 and 2 at that index.

◆ Raw()

template<class T >
T*** RC::Data3D< T >::Raw ( )
inline

Access a raw unprotected 3-dimensional C-array for the enclosed data.

Warning: This convenience function bypasses the bounds protections provided by this class.

Returns
C-style pointer to the contents.

◆ RawData()

template<class T >
const Data1D< Data2D<T> >& RC::Data3D< T >::RawData ( ) const
inline

Access the underlying nested Data1D/Data2D structure for this object.

Attempts should not be made to resize the underlying data accessed with this convenience function.

Returns
The nested Data1D/Data2D contained within.

◆ Resize()

template<class T >
void RC::Data3D< T >::Resize ( const size_t  resize_size1,
const size_t  resize_size2,
const size_t  resize_size3 
)
inline

Resize the array, reallocating if necessary.

This may trigger a copy operation upon expansion. For efficiency, it never reallocates or copies while shrinking or expanding within a previous size range. Use Crop if necessary to shrink storage to the current size.

Parameters
resize_size1The new size for dimension 1.
resize_size2The new size for dimension 2.
resize_size3The new size for dimension 2.

◆ Zero()

template<class T >
void RC::Data3D< T >::Zero ( )
inline

Sets all elements equal to 0.

See also
Data1D::Zero()

The documentation for this class was generated from the following file:
email address
— (c) 2015