#ifndef EQUIVSTR_H #define EQUIVSTR_H /////////////////////////////////////////////////////////////// // equivStr.h - defines an alternate set of equivalence // // properties for standard C++ string objects // // // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium 200, NT 4.0 // // Application: Design Patterns - property pattern, Su98 // // Author: Jim Fawcett, CST 2-187, (314) 443-3948 // // fawcett@neptune.syr.edu // /////////////////////////////////////////////////////////////// #include #include using namespace std; //////////////////////////////////////////////////////////////// // friend functions are used here because the C++ matching // rules for overloaded functions will select these functions // instead of the corresponding operators defined for the // basic_string class. However, if we define them as member // functions, the C++ matching rules will select the basic_string // operators instead. // // Stroustrup discusses matching rules in 7.4 and 7.4.4 template class Property { public: friend bool operator==(const T &lhs, const T &rhs) { return lhs.equiv(rhs); } friend bool operator!=(const T &lhs, const T &rhs) { return (!lhs.equiv(rhs)); } friend bool operator< (const T &lhs, const T &rhs) { return lhs.less(rhs); } friend bool operator> (const T &lhs, const T &rhs) { return ((!lhs.less(rhs)) && (!lhs.equiv(rhs))); } friend bool operator<=(const T &lhs, const T &rhs) { return (lhs.less(rhs) || lhs.equiv(rhs)); } friend bool operator>=(const T &lhs, const T &rhs) { return (!lhs.less(rhs)); } }; // class nearStr : public Property, public string { public: nearStr() {} nearStr(const nearStr &ns) : string(ns) { } nearStr(const char *s) : string(s) { } bool equiv(const nearStr &ns) const; bool less (const nearStr &ns) const; }; class noCaseStr : public string, public Property { public: noCaseStr() {} noCaseStr(const noCaseStr &ns) : string(ns) {} noCaseStr(const char *s) : string(s) {} bool equiv(const noCaseStr &ns) const; bool less (const noCaseStr &ns) const; }; #endif