23 inline std::ostream&
operator<< (std::ostream &out,
const Data2D<T>& d);
35 void Initialize(
size_t new_d_size1,
size_t new_d_size2) {
36 d_size1 = new_d_size1;
37 d_size2 = new_d_size2;
40 for (
size_t i=0; i<d_size2; i++) {
60 explicit Data2D(
size_t d_size1,
size_t d_size2) {
61 Initialize(d_size1, d_size2);
69 : d_size1 (copy.d_size1),
70 d_size2 (copy.d_size2) {
79 d_size2(new_data.size()),
80 data(new_data.size()) {
81 std::copy(new_data.begin(), new_data.end(), data.Raw());
83 d_size1 = data[0].size();
117 for (
size_t i=0; i<d_size2; i++) {
128 return ( (d_size1 == 0) || (d_size2 == 0) );
137 if (
this != &other) {
138 d_size1 = other.d_size1;
139 d_size2 = other.d_size2;
201 inline T&
operator() (
size_t x,
size_t y) {
return data[y][x]; }
207 inline T&
At(
size_t x,
size_t y) {
return data[y][x]; }
209 inline const T&
At(
size_t x,
size_t y)
const {
214 inline size_t size1()
const {
return d_size1; }
216 inline size_t size2()
const {
return d_size2; }
219 inline size_t TypeSize()
const {
return sizeof(T); }
225 for (
size_t y=0; y<d_size2; y++) {
236 inline bool Check(
const size_t x,
const size_t y)
const {
237 if ( ! ((x < d_size1) && (y < d_size2)) ) {
251 inline void Assert(
const size_t x,
const size_t y)
const {
252 if ( !
Check(x, y) ) {
266 inline void Resize(
const size_t resize_size1,
const size_t resize_size2) {
267 data.Resize(resize_size2);
268 for (
size_t i=0; i<resize_size2; i++) {
269 data[i].Resize(resize_size1);
271 d_size2 = resize_size2;
272 d_size1 = resize_size1;
285 if (cptrs.size() != d_size2) {
286 cptrs.Resize(d_size2);
287 for (
size_t i=0; i<d_size2; i++) {
288 cptrs[i] = data[i].Raw();
313 for (
size_t y=0; y<d_size2; y++) {
314 for (
size_t x=0; x<d_size1; x++) {
326 for (
size_t y=0; y<d_size2; y++) {
327 for (
size_t x=0; x<d_size1; x++) {
357 swap(a.data, b.data);
369 if (d.
size2() == 0) {
374 for (i=1; i<d.size2(); i++) {
Provides a one-dimensional vector-like structure.
Provides informative exception handling.
#define Throw_RC_Type(Type, err)
Use this to throw an RC:ErrorMsg subtype exception.
Definition: Errors.h:282
A bounds-safe one-dimensional vector-like structure.
Definition: Data1D.h:49
A bounds-safe two-dimensional resizeable structure.
Definition: Data2D.h:32
~Data2D()
Deletes all contents upon destruction.
Definition: Data2D.h:89
size_t TypeSize() const
Returns sizeof(T).
Definition: Data2D.h:219
void Delete()
Delete all the elements and free all allocated memory.
Definition: Data2D.h:95
T & At(size_t x, size_t y)
Equivalent to Data2D::operator()(size_t x, size_t y)
Definition: Data2D.h:207
RAIter< Data1D< Data1D< T > >, Data1D< T > > end()
Return a bounds-checked random-access iterator starting just past the last element.
Definition: Data2D.h:171
void Crop()
Reduces memory consumption to only that necessary for the current size.
Definition: Data2D.h:114
RAIter< Data1D< Data1D< T > >, Data1D< T > > begin()
Copy data from any other object of a type with a compatible.
Definition: Data2D.h:155
void FromLilEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data2D.h:321
Data2D()
Default constructor which initializes to size 0.
Definition: Data2D.h:49
void ToLilEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data2D.h:311
void FromBigEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data2D.h:334
void Resize(const size_t resize_size1, const size_t resize_size2)
Resize the array, reallocating if necessary.
Definition: Data2D.h:266
RAIter< Data1D< Data1D< T > >, Data1D< T > > end() const
Const version end.
Definition: Data2D.h:175
const T & At(size_t x, size_t y) const
Const version of Data2D::operator()(size_t x, size_t y)
Definition: Data2D.h:209
T ** Raw()
Access a raw unprotected 2-dimensional C-array for the enclosed data.
Definition: Data2D.h:284
bool IsEmpty() const
Definition: Data2D.h:127
size_t size1() const
Get the size of dimension 1.
Definition: Data2D.h:214
bool Check(const size_t x, const size_t y) const
Check if the indices x and y are in bounds.
Definition: Data2D.h:236
Data2D(const std::initializer_list< Data1D< T >> &new_data)
Initializer list constructor, initializes with nested brackets.
Definition: Data2D.h:77
void Clear()
Identical to Delete().
Definition: Data2D.h:104
friend void swap(Data2D< T2 > &a, Data2D< T2 > &b)
Efficiently swap all the contents of a and b.
Definition: Data2D.h:354
size_t size2() const
Get the size of dimension 2.
Definition: Data2D.h:216
void Assert(const size_t x, const size_t y) const
Throw an ErrorMsgBounds exception if either x or y is out of bounds.
Definition: Data2D.h:251
Data1D< T > & operator[](size_t x)
Bounds-checked access of a Data1D corresponding to the data at index x in dimension 2.
Definition: Data2D.h:187
Data2D & operator=(const Data2D &other)
Assignment operator which copies all contents from other.
Definition: Data2D.h:136
void Zero()
Sets all elements equal to 0.
Definition: Data2D.h:224
Data1D< T > & operator()(size_t x)
Identical to Data2D::operator[].
Definition: Data2D.h:189
Data2D(size_t d_size1, size_t d_size2)
Constructor which sets the initial sizes.
Definition: Data2D.h:60
Data1D< Data1D< T > > & RawData()
Access the underlying nested Data1D structure for this object.
Definition: Data2D.h:300
Data2D(const Data2D< T > ©)
Copy constructor that copies all elements.
Definition: Data2D.h:68
void ToBigEndian()
Convert endianness of all elements if needed, for supported types.
Definition: Data2D.h:324
const Data1D< Data1D< T > > & RawData() const
Const version of RawData().
Definition: Data2D.h:304
const RAIter< Data1D< Data1D< T > >, Data1D< T > > begin() const
Const version of begin.
Definition: Data2D.h:159
static bool IsLittle()
True if this system is little-endian.
Definition: Types.h:335
static bool IsBig()
True if this system is big-endian.
Definition: Types.h:341
static T ToBig(const T &x)
Converts x to big-endian.
Definition: Types.h:319
static T ToLittle(const T &x)
Converts x to little-endian.
Definition: Types.h:302
A bounds-checked iterator for random-access containers that knows when its target was deleted.
Definition: Iter.h:27
void swap(Data2D< T2 > &a, Data2D< T2 > &b)
Efficiently swap all the contents of a and b.
Definition: Data2D.h:354
std::ostream & operator<<(std::ostream &out, APtr< T > obj)
A convenience stream output for displaying the enclosed object.
Definition: APtr.h:120
void swap(RC::Data1D< T > &a, RC::Data1D< T > &b)
Efficiently swap all the contents of a and b.
Definition: Data1D.h:1184