address.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.4 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _ADDRESS_H_
00031 #define _ADDRESS_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 #include <set>
00037 #include <string>
00038 #include <vector>
00039 #include <map>
00040 
00041 // + libraries
00042 
00043 // + local headers
00044 #include "osbid.h"
00045 
00046 // + class declarations
00047 namespace OSB_DB {
00048     class AddressGw;
00049     class Session;
00050 }
00051 
00052 namespace OSB_LIB {
00053     class Associate;
00054 }
00055 
00056 // ************************************************************************
00057 // namespace extensions
00058 namespace OSB_LIB {
00059 
00060 // ************************************************************************
00061 // forward declarations
00062 
00063 // ************************************************************************
00064 // type definitions
00071     enum AddressType
00072     {
00074         atUnknown  = 0x0000,
00076         atBilling  = 0x0001,
00078         atHome     = 0x0002,
00080         atOffice   = 0x0004
00081     };
00082 
00084     inline AddressType addressType(unsigned long);
00085 
00086 // ************************************************************************
00087 // class definitions
00088 
00089     // *****************************************************************
00090     // Address
00102     class Address {
00104         friend class OSB_DB::AddressGw;
00106         friend class Associate;
00107 
00108     public:
00110         typedef Id<Associate> OwnerId;
00111 
00112     public:
00114         typedef std::set<AddressType> TypeList;
00115 
00117         Address(
00118             const OwnerId&  ownerId,
00119             const TypeList& types
00120         );
00121 
00123 
00124         inline const OwnerId&     ownerId()   const;
00125         inline const TypeList&    types()     const;
00126         inline const std::string& addressee() const;
00127         inline const std::string& street()    const;
00128         inline const std::string& city()      const;
00129         inline const std::string& state()     const;
00130         inline const std::string& zipcode()   const;
00131         inline const std::string& country()   const;
00132         inline const std::string& telNum()    const;
00133         inline const std::string& email()     const;
00134         inline const std::string& faxNum()    const;
00135         inline const std::string& function()  const;
00137 
00139 
00140         void setAddressee(const std::string& addressee);
00141         void setStreet(const std::string& street);
00142         void setCity(const std::string& city);
00143         void setState(const std::string& state);
00144         void setZipcode(const std::string& zip);
00145         void setCountry(const std::string& country);
00146         void setTelNum(const std::string& tel);
00147         void setEmail(const std::string& email);
00148         void setFaxNum(const std::string& fax);
00149         void setFunction(const std::string& function);
00151 
00152     private:
00162         bool insert(const OSB_DB::Session& session) const;
00163 
00173         bool update(const OSB_DB::Session& session) const;
00174 
00184         bool remove(const OSB_DB::Session& session) const;
00185 
00196         bool addType(
00197             const OSB_DB::Session& session,
00198                   AddressType            type
00199         );
00200 
00213         bool delType(
00214             const OSB_DB::Session& session,
00215                   AddressType            type
00216         );
00217 
00224         bool contains(AddressType type) const;
00225 
00226     private:
00227         OwnerId     ownerId_;           
00228         TypeList    types_;             
00229         std::string addressee_;         
00230         std::string street_;            
00231         std::string city_;              
00232         std::string state_;             
00233         std::string zipcode_;           
00234         std::string country_;           
00235         std::string telNum_;            
00236         std::string email_;             
00237         std::string faxNum_;            
00238         std::string function_;          
00239     };                                  // class Address
00240 
00242     typedef std::vector<Address>  AddressList;
00243 
00244 
00246     struct AddressTypeInfo {
00248         AddressType type;
00250         std::string name;
00251     };
00252 
00253     // *****************************************************************
00254     // AddressTypeList
00261     class AddressTypeList {
00262     public:
00264 
00265 
00266         typedef std::map<AddressType, AddressTypeInfo> List;
00268         typedef List::iterator Iterator;
00270         typedef List::const_iterator ConstIterator;
00272         typedef List::size_type SizeType;
00274         typedef List::key_type KeyType;
00276 
00278         const List& list() const { return list_; }
00279 
00288 
00289         Iterator begin() { return list_.begin(); }
00291         Iterator end() { return list_.end(); }
00293         Iterator find(const KeyType& k) { return list_.find(k); }
00295         ConstIterator begin() const { return list_.begin(); }
00297         ConstIterator end() const { return list_.end(); }
00299         ConstIterator find(const KeyType& k) const
00300         { return list_.find(k); }
00302         SizeType size() const { return list_.size(); }
00304 
00316         long read(const OSB_DB::Session& session);
00317 
00326         const AddressTypeInfo* findAddressType(
00327             AddressType typeId
00328         ) const;
00329 
00340         const AddressTypeInfo& getAddressType(
00341             AddressType typeId
00342         ) const;
00343 
00344     private:
00346         List list_;
00347     };                                  // class AddressTypeList
00348 
00349     // *****************************************************************
00350     // TheAddressTypeList
00362     class TheAddressTypeList {
00363     public:
00370         static AddressTypeList& instance();
00371 
00372     private:
00374         TheAddressTypeList();
00376         TheAddressTypeList(const TheAddressTypeList& rhs);
00377 
00379         static AddressTypeList* instance_;
00380     };                                  // TheAddressTypeList
00381 }                                       // namespace OSB_LIB
00382 
00383 // ************************************************************************
00384 // inline definitions
00385 namespace OSB_LIB {
00386     // ********************************************************************
00387     // AddressType
00388     inline AddressType addressType(unsigned long at)
00389     {
00390         switch (at) {
00391             case 0x0001: return atBilling;
00392             case 0x0002: return atHome;
00393             case 0x0004: return atOffice;
00394         }
00395         return AddressType(atUnknown);
00396     }
00397 
00398     inline long toLong(AddressType at)
00399     {
00400         long rc = at;
00401         switch (rc) {
00402             case atBilling:
00403             case atHome:
00404             case atOffice:   break;
00405             default:  rc = atUnknown;   // ToDo: remove
00406         }
00407         return rc;
00408     }
00409 
00410     // *****************************************************************
00411     // Address
00412     inline const Address::OwnerId& Address::ownerId() const
00413     {
00414         return ownerId_;
00415     }
00416 
00417     inline const Address::TypeList& Address::types() const
00418     {
00419         return types_;
00420     }
00421 
00422     inline const std::string& Address::addressee() const
00423     {
00424         return addressee_;
00425     }
00426 
00427     inline const std::string& Address::street() const
00428     {
00429         return street_;
00430     }
00431 
00432     inline const std::string& Address::city() const
00433     {
00434         return city_;
00435     }
00436 
00437     inline const std::string& Address::state() const
00438     {
00439         return state_;
00440     }
00441 
00442     inline const std::string& Address::zipcode() const
00443     {
00444         return zipcode_;
00445     }
00446 
00447     inline const std::string& Address::country() const
00448     {
00449         return country_;
00450     }
00451 
00452     inline const std::string& Address::telNum() const
00453     {
00454         return telNum_;
00455     }
00456 
00457     inline const std::string& Address::email() const
00458     {
00459         return email_;
00460     }
00461 
00462     inline const std::string& Address::faxNum() const
00463     {
00464         return faxNum_;
00465     }
00466 
00467     inline const std::string& Address::function() const
00468     {
00469         return function_;
00470     }
00471 }                                       // namespace OSB_LIB
00472 #endif                                  // #ifndef _ADDRESS_H_

Generated on Sat Sep 2 14:06:31 2006 for OSB Library by  doxygen 1.4.7