00001 // OSB library ********************************************* -*- C++ -*- 00011 /* 00012 AUTHOR(S): Tang Boon Leong (tbl) 00013 00014 RCS information 00015 $Name: OSB_060808 $ 00016 $Revision: 1.15 $ 00017 00018 License 00019 OSB rating and billing library for communication networks 00020 Copyright (C) 2004, 2005, 2006 OSB systems 00021 00022 This file may be distributed and/or modify under the terms of the 00023 GNU General Public License (GPL) as published by the Free Software 00024 Foundation which is provided in the file LICENSE.GPL included in the 00025 packaging of this file. 00026 00027 The file is distributed in the hope that it will be useful, but WITHOUT 00028 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00029 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00030 for more details. 00031 00032 Holders of a OSB Commercial License may use this file under the terms 00033 and conditions of this commercial license. 00034 */ 00035 #ifndef _NUMBERANALYZER_H_ 00036 #define _NUMBERANALYZER_H_ 00037 00038 // ********************************************************************* 00039 // included header files 00040 // + standard includes 00041 #include <list> 00042 #include <memory> 00043 00044 // + local headers 00045 #include "osbid.h" 00046 00047 // ********************************************************************* 00048 // class declarations 00049 namespace OSB_DB { 00050 class NumberAnalyzerGw; 00051 class Session; 00052 } 00053 00054 namespace OSB_LIB { 00055 class NetworkElement; 00056 class TrunkGroup; 00057 class NwAddress; 00058 } 00059 00060 // ************************************************************************ 00061 // namespace extensions 00062 namespace OSB_LIB { 00063 // ********************************************************************* 00064 // class definitions 00065 00066 // ***************************************************************** 00067 // NumberAnalyzer 00073 class NumberAnalyzer { 00075 friend class NetworkElement; 00077 friend class TrunkGroup; 00079 friend class OSB_DB::NumberAnalyzerGw; 00080 public: 00082 typedef Id<NumberAnalyzer> Oid; 00083 00090 typedef std::auto_ptr<NumberAnalyzer> AutoPtr; 00091 00093 enum NumberAnalyzerType { 00094 naTypeUnknown = 0, 00095 00101 naType01 = 1 00102 }; 00103 00105 static long numberAnalyzerType(const NumberAnalyzerType& type); 00106 00108 static NumberAnalyzerType numberAnalyzerType(const long type); 00109 00111 NumberAnalyzer( 00112 const Oid& oid = Oid(), 00113 const NumberAnalyzerType& type = naTypeUnknown 00114 ); 00115 00117 virtual ~NumberAnalyzer() {} 00118 00124 AutoPtr clone() const; 00125 00156 template<typename T> T* isa(T*& ptr); 00157 00159 template<typename T> const T* isa(const T*& ptr) const; 00160 00161 public: 00163 00164 00169 virtual bool analyzeCalling(NwAddress& nwAddress) const = 0; 00170 00176 virtual bool analyzeCalled(NwAddress& nwAddress) const = 0; 00178 00180 00181 00182 const NumberAnalyzerType& type() const; 00183 00185 const Oid& oid() const; 00187 00189 00190 00204 bool read(const OSB_DB::Session& session); 00205 00206 private: 00219 void insert(const OSB_DB::Session& session); 00220 00235 void remove(const OSB_DB::Session& session); 00236 00250 void update(const OSB_DB::Session& session); 00252 00254 00255 00262 virtual bool 00263 readSpecific(const OSB_DB::Session& session) = 0; 00264 00269 virtual void 00270 insSpecific(const OSB_DB::Session& session) = 0; 00271 00276 virtual void 00277 removeSpecific(const OSB_DB::Session& session) = 0; 00278 00283 virtual void 00284 updSpecific(const OSB_DB::Session& session)= 0; 00286 00292 virtual NumberAnalyzer* clone_() const = 0; 00293 00294 protected: 00302 virtual NumberAnalyzer& operator=(const NumberAnalyzer& rhs); 00303 00304 private: 00306 Oid oid_; 00307 00309 NumberAnalyzerType type_; 00310 }; 00311 00312 // ***************************************************************** 00313 // NumberAnalyzerList 00322 struct NumberAnalyzerList { 00324 00325 00326 typedef std::list<NumberAnalyzer*> List; 00328 typedef List::iterator Iterator; 00330 typedef List::const_iterator ConstIterator; 00332 typedef List::size_type SizeType; 00334 00336 List items; 00337 00339 NumberAnalyzerList() {}; 00340 00347 NumberAnalyzerList(const NumberAnalyzerList& rhs); 00348 00350 NumberAnalyzerList& operator=(const NumberAnalyzerList& rhs); 00351 00353 ~NumberAnalyzerList(); 00354 00361 00362 Iterator begin(); 00364 Iterator end(); 00366 ConstIterator begin() const; 00368 ConstIterator end() const; 00370 SizeType size() const; 00372 void swap(NumberAnalyzerList& rhs); 00374 00384 void push_back(const NumberAnalyzer& numAnalyzer); 00385 00397 void push_back(NumberAnalyzer::AutoPtr naPtr); 00398 00409 Iterator erase(Iterator pos); 00410 00417 void clear(); 00418 }; 00419 00420 // ********************************************************************* 00421 // template definitions 00422 00423 // ***************************************************************** 00424 // NumberAnalyzer 00425 template<typename T> T* NumberAnalyzer::isa(T*& ptr) 00426 { 00427 ptr = dynamic_cast<T*>(this); 00428 return ptr; 00429 } 00430 00431 template<typename T> 00432 const T* NumberAnalyzer::isa(const T*& ptr) const 00433 { 00434 ptr = dynamic_cast<const T*>(this); 00435 return ptr; 00436 } 00437 } // namespace OSB_LIB 00438 #endif // #ifndef _NUMBERANALYZER_H_