/* 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 PhysicalH #define PhysicalH #include "Algebra/LinearSpaceCategory.h" class ostream; template class Physical : public LinearSpaceCategory< Physical, T > { public: Physical(const T& v) : val(v) {} T& value() { return val; } const T& value() const { return val; } private: typedef Physical Phys; // Shorthand public: Phys convertTo(const Phys& dest_unit) const { return val / dest_unit.val; } // LinearSpaceCategory "user must define" functions Phys& operator+=(const Phys& rhs) { val += rhs.val; return *this; } Phys& operator-=(const Phys& rhs) { val -= rhs.val; return *this; } Phys& setToZero() { val = T(0); return *this; } Phys& operator*=(T s) { val *= s; return *this; } Phys& operator/=(T s) { val /= s; return *this; } private: T val; }; template Physical operator*(const Physical& lhs, const Physical& rhs ) { return lhs.value() * rhs.value(); } template Physical operator/(const Physical& lhs, const Physical& rhs ) { return lhs.value() / rhs.value(); } template ostream& operator<<(ostream& os, const Physical& p); extern ostream& powerPrinter(ostream&, int[7]); #ifdef XLC_QNOTEMPINC #include "Units/Physical.c" #endif #endif