/* 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 ConcreteArrayProjection1dH #define ConcreteArrayProjection1dH #include "Array/ConcreteArray1d.h" class ostream; class istream; template class ConstConcreteArrayProjection1d : public ConcreteArray1dConstRef { public: typedef Subscriptor::ProjectionT ProjectionSubscriptor; ConstConcreteArrayProjection1d(const ProjectionSubscriptor& s, const T* t) : ConcreteArray1dConstRef(s, t) { } protected: // Copying a projection does not copy the underlying array elements. It only duplicates // the reference to the underlying array. We make the copy constructor protected to avoid // accidental copies by client code. Assignment is already prohibited because // ConcreteArray1dConstRef's can't be assigned. ConstConcreteArrayProjection1d(const ConstConcreteArrayProjection1d& proj) : ConcreteArray1dConstRef(proj.subscriptor(), proj.firstDatum()) { } }; template class ConcreteArrayProjection1d : public ConcreteArray1dRef { public: typedef Subscriptor::ProjectionT ProjectionSubscriptor; ConcreteArrayProjection1d(const ProjectionSubscriptor& s, T* t); operator ConstConcreteArrayProjection1d() const; ConcreteArrayProjection1d& operator=(ConcreteArray1dConstRef rhs); ConcreteArrayProjection1d& operator=(const T& rhs); protected: // Copying a projection does not copy the underlying array elements. It only duplicates // the reference to the underlying array. We make the copy constructor protected to avoid // accidental copies by client code. ConcreteArrayProjection1d(const ConcreteArrayProjection1d& proj); }; template ConcreteArrayProjection1d:: ConcreteArrayProjection1d(const ProjectionSubscriptor& s, T* t) : ConcreteArray1dRef(s, t) { } template ConcreteArrayProjection1d::operator ConstConcreteArrayProjection1d() const { return ConstConcreteArrayProjection1d(subscriptor(), firstDatum()); } template ConcreteArrayProjection1d& ConcreteArrayProjection1d::operator=(ConcreteArray1dConstRef rhs) { ConcreteArray1dRef::operator=(rhs); return *this; } template ConcreteArrayProjection1d& ConcreteArrayProjection1d::operator=(const T& rhs) { ConcreteArray1dRef::operator=(rhs); return *this; } template ConcreteArrayProjection1d::ConcreteArrayProjection1d(const ConcreteArrayProjection1d& proj) : ConcreteArray1dRef(proj.subscriptor(), proj.firstDatum()) { } template inline ostream& operator<<(ostream& os, const ConstConcreteArrayProjection1d& a) { return os << ConcreteArray1dConstRef(a); } template inline ostream& operator<<(ostream& os, const ConcreteArrayProjection1d& a) { return os << ConcreteArray1dConstRef(a); } template inline istream& operator<<(istream& is, const ConcreteArrayProjection1d& a) { return is >> ConcreteArray1dRef(a); } #endif