// Telephone number classes // (copyright 2004, Information Disciplines, Inc.) // These classes support telephone numbers and operations on them. #ifndef PHONE_NUMBER_BASE #define PHONE_NUMBER_BASE const PhoneNumberBase // For this freeware version the following four preprocessor lines are taken // from IDI's global.hpp definition file: #define ushort unsigned short #define uint unsigned int #define ulong unsigned long #include // Abstract base class assumes that all phone numbers can be decomposed into // 4 numerical components, described by the accessor functions below. class PhoneNumberBase { public: // (Member data items in derived classes may virtual ushort countryCode() const = 0; // be shorter than return values virtual ushort areaCode() const = 0; // of these accessor function. virtual uint exchange() const = 0; // Zero exchange signifies virtual ulong digits() const = 0; // illegal or unknown value virtual bool isLegal() const {return 0 != exchange();} virtual ostream& print(ostream& s) // Invoked polymorphically by const = 0; // by operator<< below }; // Non-member functions // -------------------- inline ostream& operator<< (ostream& ls, PHONE_NUMBER_BASE& rs) {return rs.print(ls);}; bool operator== (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs); bool operator< (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs); inline bool operator!= (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return !(ls == rs);} inline bool operator> (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return rs < ls;} inline bool operator<= (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return !(rs < ls);} inline bool operator>= (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return !(ls < rs);} // North American (U.S. & Canadian) telephone number class // ------------------------------------------------------- #define NA_PHONE_NUMBER const NA_PhoneNumber class NA_PhoneNumber : public PhoneNumberBase { short area_; // Member data (assumes Java standard sizes long localNumber_; // for efficient 6-byte representation) public: // Constructor: (See editing rules in TelephoneNumber.cpp) // ----------- NA_PhoneNumber(const short area, const short exchange, const short digits); NA_PhoneNumber() : area_(0), localNumber_(0) {} // NOTE: Because of the variety of formats and optional punctuation we // don't provide a constructor or parser for a character-string, nor do // we support mnemonic exchanges, which haven't been used for 40 years. . // The compiler will supply an acceptable destructor, copy constructor // and assignment operator. // Accessors // --------- ushort countryCode() const {return 1;} ushort NPA() const {return area_;} uint NXX() const {return localNumber_/10000;} ushort areaCode() const {return NPA();} uint exchange() const {return NXX();} ulong digits() const {return localNumber_%10000;} ostream& print (ostream& s) const; }; #undef ulong #undef uint #undef ushort #endif