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

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

#include <Data2D.h>

Public Member Functions

 Data2D ()
 Default constructor which initializes to size 0.
 
 Data2D (size_t d_size1, size_t d_size2)
 Constructor which sets the initial sizes. More...
 
 Data2D (const Data2D< T > &copy)
 Copy constructor that copies all elements. More...
 
 Data2D (const std::initializer_list< Data1D< T >> &new_data)
 Initializer list constructor, initializes with nested brackets.
 
 ~Data2D ()
 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
 
Data2Doperator= (const Data2D &other)
 Assignment operator which copies all contents from other. More...
 
RAIter< Data1D< Data1D< T > >, Data1D< T > > begin ()
 Copy data from any other object of a type with a compatible. More...
 
const RAIter< Data1D< Data1D< T > >, Data1D< T > > begin () const
 Const version of begin.
 
RAIter< Data1D< Data1D< T > >, Data1D< T > > end ()
 Return a bounds-checked random-access iterator starting just past the last element. More...
 
RAIter< Data1D< Data1D< T > >, Data1D< T > > end () const
 Const version end.
 
Data1D< T > & operator[] (size_t x)
 Bounds-checked access of a Data1D corresponding to the data at index x in dimension 2. More...
 
Data1D< T > & operator() (size_t x)
 Identical to Data2D::operator[].
 
const Data1D< T > & operator[] (size_t x) const
 Const version of Data2D::operator[].
 
const Data1D< T > & operator() (size_t x) const
 Const version of Data2D::operator[].
 
T & operator() (size_t x, size_t y)
 Bounds-checked access of an element. More...
 
const T & operator() (size_t x, size_t y) const
 Const version of Data2D::operator()(size_t x, size_t y)
 
T & At (size_t x, size_t y)
 Equivalent to Data2D::operator()(size_t x, size_t y)
 
const T & At (size_t x, size_t y) const
 Const version of Data2D::operator()(size_t x, size_t y)
 
size_t size1 () const
 Get the size of dimension 1.
 
size_t size2 () const
 Get the size of dimension 2.
 
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
 Check if the indices x and y are in bounds. More...
 
void Assert (const size_t x, const size_t y) const
 Throw an ErrorMsgBounds exception if either x or y is out of bounds. More...
 
void Resize (const size_t resize_size1, const size_t resize_size2)
 Resize the array, reallocating if necessary. More...
 
T ** Raw ()
 Access a raw unprotected 2-dimensional C-array for the enclosed data. More...
 
Data1D< Data1D< T > > & RawData ()
 Access the underlying nested Data1D structure for this object. More...
 
const Data1D< Data1D< T > > & RawData () const
 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 (Data2D< T2 > &a, Data2D< T2 > &b)
 Efficiently swap all the contents of a and b.
 

Detailed Description

template<class T>
class RC::Data2D< T >

A bounds-safe two-dimensional resizeable structure.

Note: Non-POD classes stored in Data2D containers must have a default constructor with default values or no arguments.

See also
Data1D
Data3D

Constructor & Destructor Documentation

template<class T>
RC::Data2D< T >::Data2D ( size_t  d_size1,
size_t  d_size2 
)
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.

Parameters
d_size1The size of the first dimension.
d_size2The size of the second dimension.
template<class T>
RC::Data2D< T >::Data2D ( const Data2D< T > &  copy)
inline

Copy constructor that copies all elements.

Parameters
copyA source Data2D from which elements should be copied.

Member Function Documentation

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

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

Parameters
xThe index for dimension 1.
yThe index for dimension 2.
template<class T>
RAIter< Data1D< Data1D<T> >, Data1D<T> > RC::Data2D< T >::begin ( )
inline

Copy data from any other object of a type with a compatible.

Return a bounds-checked random-access iterator starting at offset. Note that the iterator is revokable, meaning use of it will throw an exception if this Data2D is deleted.

Returns
A bounds-checked iterator.
See also
end()
template<class T>
bool RC::Data2D< T >::Check ( const size_t  x,
const size_t  y 
) const
inline

Check if the indices x and y are in bounds.

Parameters
xThe index for dimension 1.
yThe index for dimension 2.
Returns
True if in bounds.
template<class T>
void RC::Data2D< 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.

template<class T>
RAIter< Data1D< Data1D<T> >, Data1D<T> > RC::Data2D< T >::end ( )
inline

Return a bounds-checked random-access iterator starting just past the last element.

Note that the iterator is revokable, meaning use of it will throw an exception if this Data2D is deleted.

Returns
A bounds-checked iterator.
See also
begin()
template<class T>
bool RC::Data2D< T >::IsEmpty ( ) const
inline
Returns
True if there are no elements / at least one size is 0.
template<class T>
T& RC::Data2D< T >::operator() ( size_t  x,
size_t  y 
)
inline

Bounds-checked access of an element.

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

Parameters
xThe index of dimension 1
yThe index of dimension 2.
Returns
A reference to the indexed element.
template<class T>
Data2D& RC::Data2D< T >::operator= ( const Data2D< T > &  other)
inline

Assignment operator which copies all contents from other.

Parameters
otherData2D to copy from.
Returns
This object.
template<class T>
Data1D<T>& RC::Data2D< T >::operator[] ( size_t  x)
inline

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

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

Parameters
xThe index of dimension 2.
Returns
A Data1D of all elements in dimension 1 at that index.
template<class T>
T** RC::Data2D< T >::Raw ( )
inline

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

Warning: This convenience function bypasses the bounds protections provided by this class. Also the C-array becomes invalid if this object is resized, deleted, or cropped.

Returns
C-style pointer to the contents.
template<class T>
Data1D< Data1D<T> >& RC::Data2D< T >::RawData ( )
inline

Access the underlying nested Data1D structure for this object.

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

Returns
The nested Data1D contained within.
template<class T>
void RC::Data2D< T >::Resize ( const size_t  resize_size1,
const size_t  resize_size2 
)
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.
template<class T>
void RC::Data2D< 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