// Additive pattern for numeric classes // copyright 2001 Information Disciplines, Inc., Chicago // These preprocessor components define the pattern of arithmetic // operators for a numeric data item class that follows the additive pattern. // Before #include-ing this file, the programmer must set the macro // variable Class to the name of the class, and, optionally, set // PureType to the type of the pure number (default = double). It is up to // the class definition (.hpp) file to #undef these macros. #ifndef PureType #define PureType double #endif // The following functions must be defined in the class implementation (.cpp) // file or the class definition (.hpp) file. Class operator- () const; Class& operator+=(const Class rs); Class& operator-=(const Class rs); Class& operator*=(const PureType rs); Class& operator/=(const PureType rs); Class& operator%=(const PureType rs); // Omit these definitions Class& operator%=(const Class rs); // if operators are unused PureType operator/ (const Class rs) const; // The following inline functions are fully defined here: Class operator+(const Class rs) const {return Class(*this) += rs;} Class operator-(const Class rs) const {return Class(*this) -= rs;} Class operator*(const PureType rs) const {return Class(*this) *= rs;} Class operator/(const PureType rs) const {return Class(*this) /= rs;} Class operator%(const PureType rs) const {return Class(*this) %= rs;} Class operator%(const Class rs) const {return Class(*this) %= rs;} inline friend Class operator*(const PureType ls, const Class rs) {return rs * ls;} inline friend Class operator+(const PureType ls, const Class rs) {return Class(ls) + rs;} inline friend Class operator-(const PureType ls, const Class rs) {return Class(ls) - rs;}