/* Example programs from the book Scientific and Engineering Programming in C++: An Introduction with Advanced Techniques and Examples, Addison-Wesley, 1994. (c) COPYRIGHT INTERNATIONAL BUSINESS MACHINES CORPORATION 1994. ALL RIGHTS RESERVED. See README file for further details. */ #ifndef ConcreteArray2dH #define ConcreteArray2dH #include "Array/ConcreteArrayIterator.h" #include "Array/ArrayIterator2d.h" #include "Array/Array2d.h" #include "Array/ConcreteArrayProjection1d.h" template class ConcreteArray2dRef; template class ConcreteArray2d; template class ConcreteArray2dConstRef : private Subscriptor { public: Subscriptor::dim; Subscriptor::shape; Subscriptor::numElts; Subscriptor::offset; typedef T EltT; typedef Subscriptor SubscriptorT; typedef ConstConcreteArrayProjection1d ConstProjectionT; typedef ArrayBrowser2d< ConcreteArray2dConstRef > BrowserType; const T& operator()(Subscript s0, Subscript s1) const { return firstDatum()[offset(SubscriptArray<2>(s0, s1))]; } ConstProjectionT project(Subscript, Dimension) const; ConstProjectionT operator[](Subscript s) const { return project(s, 0); } ConstProjectionT row(Subscript s) const { return project(s, 0); } ConstProjectionT column(Subscript s) const { return project(s, 1); } const T* firstDatum() const { return datap; } Subscriptor subscriptor() const { return *this; } protected: ConcreteArray2dConstRef(Subscriptor s, const T* p) : Subscriptor(s), datap(p) {} friend ConcreteArray2dRef; friend ConcreteArray2d; private: void operator=(const ConcreteArray2dConstRef&);// Prohibit private: const T* const datap; }; template class ConcreteArray2dRef : private Subscriptor { public: Subscriptor::dim; Subscriptor::shape; Subscriptor::numElts; Subscriptor::offset; typedef T EltT; typedef Subscriptor SubscriptorT; typedef ConstConcreteArrayProjection1d ConstProjectionT; typedef ConcreteArrayProjection1d ProjectionT; typedef ArrayBrowser2d< ConcreteArray2dRef > BrowserType; typedef ArrayIterator2d< ConcreteArray2dRef > IteratorType; T& operator()(Subscript s0, Subscript s1) const; Subscriptor subscriptor() const { return *this; } T* firstDatum() const { return datap; } ProjectionT project(Subscript, Dimension) const; ProjectionT operator[](Subscript s) const { return project(s, 0); } ProjectionT row(Subscript s) const { return project(s, 0); } ProjectionT column(Subscript s) const { return project(s, 1); } operator ConcreteArray2dConstRef() const; const ConcreteArray2dRef& operator=( const ConcreteArray2dConstRef& rhs) const; const ConcreteArray2dRef& operator=( const ConcreteArray2dRef& rhs) const; const ConcreteArray2dRef& operator=(const T& rhs) const; protected: ConcreteArray2dRef(Subscriptor s, T* p) : Subscriptor(s), datap(p) {} friend ConcreteArray2d; private: T* const datap; }; template inline T& ConcreteArray2dRef::operator()(Subscript s0, Subscript s1) const { return firstDatum()[offset(SubscriptArray<2>(s0, s1))]; } template inline ConcreteArray2dRef::operator ConcreteArray2dConstRef() const { return ConcreteArray2dConstRef(*this, datap); } template class ConcreteArray2d : private Subscriptor { public: Subscriptor::dim; Subscriptor::shape; Subscriptor::numElts; Subscriptor::offset; Subscriptor::setShape; typedef T EltT; typedef Subscriptor SubscriptorT; typedef ConcreteArrayProjection1d< Subscriptor, T > ProjectionT; typedef ConstConcreteArrayProjection1d< Subscriptor, T > ConstProjectionT; typedef ConcreteArrayBrowser< ConcreteArray2d > BrowserType; typedef ConcreteArrayIterator< ConcreteArray2d > IteratorType; const T& operator()(Subscript s0, Subscript s1) const; T& operator()(Subscript s0, Subscript s1); Subscriptor subscriptor() const { return *this; } T const * firstDatum() const { return datap; } T * firstDatum() { return datap; } ConstProjectionT project(Subscript s, Dimension d) const; ProjectionT project(Subscript s, Dimension d); ConstProjectionT operator[](Subscript s) const { return project(s, 0); } ProjectionT operator[](Subscript s) { return project(s, 0); } ConstProjectionT row(Subscript i) const { return project(i, 0); } ProjectionT row(Subscript i) { return project(i, 0); } ConstProjectionT column(Subscript i) const { return project(i, 1); } ProjectionT column(Subscript i) { return project(i, 1); } operator ConcreteArray2dConstRef() const; operator ConcreteArray2dRef(); ConcreteArray2d& operator=(const ConcreteArray2d& rhs); ConcreteArray2d& operator=(const ConcreteArray2dConstRef& rhs); ConcreteArray2d& operator=(const T& rhs); protected: ConcreteArray2d(const Subscriptor& s, T* p) : Subscriptor(s), datap(p) {} void reshapeOnHeap(const SubscriptArray<2>& s); void setSizeOnHeap(Subscript n); protected: T* datap; private: ConcreteArray2d(const ConcreteArray2d&); }; template inline const T& ConcreteArray2d::operator()(Subscript s0, Subscript s1) const { return firstDatum()[offset(SubscriptArray<2>(s0, s1))]; } template inline T& ConcreteArray2d::operator()(Subscript s0, Subscript s1) { return firstDatum()[offset(SubscriptArray<2>(s0, s1))]; } template inline ConcreteArray2d::ConstProjectionT ConcreteArray2d::project(Subscript s, Dimension d) const { return ConcreteArray2dConstRef(*this).project(s, d); } template inline ConcreteArray2d::ProjectionT ConcreteArray2d::project(Subscript s, Dimension d) { return ConcreteArray2dRef(*this).project(s, d); } template inline ConcreteArray2d& ConcreteArray2d::operator=(const ConcreteArray2dConstRef& rhs) { ConcreteArray2dRef(*this) = rhs; return *this; } template inline ConcreteArray2d& ConcreteArray2d::operator=(const ConcreteArray2d& rhs) { ConcreteArray2dRef(*this) = rhs; return *this; } template inline ConcreteArray2d& ConcreteArray2d::operator=(const T& rhs) { ConcreteArray2dRef(*this) = rhs; return *this; } template inline ConcreteArray2d::operator ConcreteArray2dConstRef() const { return ConcreteArray2dConstRef(subscriptor(), datap); } template inline ConcreteArray2d::operator ConcreteArray2dRef() { return ConcreteArray2dRef(subscriptor(), datap); } template ostream& operator<<(ostream& os, const ConcreteArray2dConstRef& a); template istream& operator>>(istream& is, const ConcreteArray2dRef& a); template inline ostream& operator<<(ostream& os, const ConcreteArray2d& a) { return os << ConcreteArray2dConstRef(a); } template inline istream& operator>>(istream& is, ConcreteArray2d& a) { return is >> ConcreteArray2dRef(a); } template void concreteCopy(const ConcreteArray2dRef& lhs, const ConcreteArray2dConstRef& rhs); template inline void concreteCopy(ConcreteArray2d& lhs, const ConcreteArray2d& rhs) { concreteCopy(ConcreteArray2dRef(lhs), ConcreteArray2dConstRef(rhs)); } template inline void concreteCopy(ConcreteArray2d& lhs, const ConcreteArray2dConstRef& rhs) { concreteCopy(ConcreteArray2dRef(lhs), rhs); } #ifdef XLC_QNOTEMPINC #include "Array/ConcreteArray2d.c" #endif #endif