#include #include namespace omega { template void Dynamic_Array::do_constr() { // #if ! defined SHUT_UP_ABOUT_STATEMENT_WITH_NO_EFFECT_IN_DYNAMIC_ARRAY_CREATION // assert(d > 0); // #endif bounds = 0; elements = 0; partial = false; } template void Dynamic_Array1::do_construct(int d0) { this->bounds = new int[1]; this->bounds[0] = d0; this->elements = new T [d0]; this->partial = false; } template void Dynamic_Array2::do_construct(int d0, int d1) { this->bounds = new int[2]; this->bounds[0] = d0; this->bounds[1] = d1; this->elements = new T [d0 * d1]; this->partial = false; } template void Dynamic_Array3::do_construct(int d0,int d1,int d2) { this->bounds = new int[3]; this->bounds[0] = d0; this->bounds[1] = d1; this->bounds[2] = d2; this->elements = new T [d0 * d1 * d2]; this->partial = false; } template void Dynamic_Array4::do_construct(int d0,int d1,int d2,int d3) { this->bounds = new int[4]; this->bounds[0] = d0; this->bounds[1] = d1; this->bounds[2] = d2; this->bounds[3] = d3; this->elements = new T [d0 * d1 * d2 * d3]; this->partial = false; } template Dynamic_Array::Dynamic_Array() { do_constr(); } template Dynamic_Array1::Dynamic_Array1(const char *) { this->do_constr(); } template Dynamic_Array2::Dynamic_Array2(const char *,const char *) { this->do_constr(); } template Dynamic_Array3::Dynamic_Array3(const char *,const char *,const char *) { this->do_constr(); } template Dynamic_Array4::Dynamic_Array4(const char *,const char *,const char *,const char *) { this->do_constr(); } template Dynamic_Array1::Dynamic_Array1(int d0) { do_construct(d0); } template Dynamic_Array2::Dynamic_Array2(int d0, int d1) { do_construct(d0, d1); } template Dynamic_Array3::Dynamic_Array3(int d0,int d1,int d2) { do_construct(d0, d1, d2); } template Dynamic_Array4::Dynamic_Array4(int d0,int d1,int d2,int d3) { do_construct(d0, d1, d2, d3); } template void Dynamic_Array::do_destruct() { if (! partial) { delete [] bounds; delete [] elements; } } template Dynamic_Array::~Dynamic_Array() { do_destruct(); } template void Dynamic_Array1::resize(int d0) { assert(!this->partial); this->do_destruct(); if (d0 == 0) this->do_constr(); else do_construct(d0); } template void Dynamic_Array2::resize(int d0, int d1) { assert(!this->partial); this->do_destruct(); if (d0 == 0 && d1 == 0) this->do_constr(); else do_construct(d0, d1); } template void Dynamic_Array3::resize(int d0, int d1, int d2) { assert(!this->partial); this->do_destruct(); if (d0 == 0 && d1 == 0 && d2 == 0) this->do_constr(); else do_construct(d0, d1, d2); } template void Dynamic_Array4::resize(int d0, int d1, int d2, int d3) { assert(!this->partial); this->do_destruct(); if (d0 == 0 && d1 == 0 && d2 == 0 && d3 == 0) this->do_constr(); else do_construct(d0, d1, d2, d3); } template T& Dynamic_Array1::operator[](int d0) { #if !defined (NDEBUG) assert(this->elements != 0 && "Trying to dereference undefined array"); assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); #endif return this->elements[d0]; } template Dynamic_Array1 Dynamic_Array2::operator[](int d0) { #if !defined (NDEBUG) assert(this->elements != 0 && "Trying to dereference undefined array"); assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); #endif Dynamic_Array1 result; result.bounds = this->bounds+1; result.elements = this->elements + this->bounds[1] * d0; result.partial = true; return result; } template Dynamic_Array2 Dynamic_Array3::operator[](int d0) { #if !defined (NDEBUG) assert(this->elements != 0 && "Trying to dereference undefined array"); assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); #endif Dynamic_Array2 result; result.bounds = this->bounds+1; result.elements = this->elements + this->bounds[1] * this->bounds[2] * d0; result.partial = true; return result; } template Dynamic_Array3 Dynamic_Array4::operator[](int d0) { #if !defined (NDEBUG) assert(this->elements != 0 && "Trying to dereference undefined array"); assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); #endif Dynamic_Array3 result; result.bounds = this->bounds+1; result.elements = this->elements + this->bounds[1] * this->bounds[2] * this->bounds[3] * d0; result.partial = true; return result; } template Dynamic_Array::Dynamic_Array(Dynamic_Array &D) { assert(D.elements != 0 && "Trying to copy an undefined array"); partial = true; bounds = D.bounds; elements = D.elements; } } // namespace