// Telephone Number functions Conrad Weisert // -------------------------- // (copyright 2004 Information Disciplnes, Inc., Chicago) #include "TelephoneNumber.hpp" // Constructor -- In order to minimize the burden on the user program we don't // ----------- throw an exception for an illegal value, but simply set the // object to zeros. Some applications use 555 exchange to // indicate an unknown value. NA_PhoneNumber:: NA_PhoneNumber(const short area, const short exchange, const short digits) : area_(area), localNumber_(exchange*10000+digits) {if (area_ <= 200 || area_ % 100 == 11 || area_ > 999 ||(area_ % 100 == 0 && area != 800) || exchange<= 200 || exchange % 100 == 11 || exchange > 999 || exchange % 100 == 0 || digits < 0 || digits > 9999) localNumber_ = area_ = 0; } // Relational Operators // -------------------- bool operator== (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return ls.countryCode() == rs.countryCode() && ls.digits() == rs.digits() && ls.exchange() == rs.exchange() && ls.areaCode() == rs.areaCode();} bool operator< (PHONE_NUMBER_BASE& ls, PHONE_NUMBER_BASE& rs) {return ls.countryCode() < rs.countryCode() ? true : ls.countryCode() > rs.countryCode() ? false : ls.areaCode() < rs.areaCode() || (ls.areaCode()== rs.areaCode() && (ls.exchange() < rs.exchange() || (ls.exchange() == rs.exchange() && ls.digits() < rs.digits())));} // Output-stream insertion // Format (North American) is: (nnn) nnn-nnnn // (The country code is not included.) ostream& NA_PhoneNumber::print (ostream& s) const {if (!isLegal()) return s << "(***) UNKNOWN!"; s << '(' << areaCode() << ") " << exchange() << '-'; long n = digits(); // Insert leading zeros if (n < 1000) s << '0'; if (n < 100) s << '0'; if (n < 10) s << '0'; return s << n; }