billcycle.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00009 /*
00010   AUTHOR(S): Andreas Huggel (ahu)
00011 
00012   RCS information
00013    $Name: OSB_060808 $
00014    $Revision: 1.42 $
00015 
00016   License
00017    OSB rating and billing library for communication networks
00018    Copyright (C) 2004, 2005, 2006  OSB systems
00019 
00020    This file may be distributed and/or modify under the terms of the
00021    GNU General Public License (GPL) as published by the Free Software
00022    Foundation which is provided in the file LICENSE.GPL included in the
00023    packaging of this file.
00024 
00025    The file is distributed in the hope that it will be useful, but WITHOUT
00026    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00027    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00028    for more details.
00029 
00030    Holders of a OSB Commercial License may use this file under the terms
00031    and conditions of this commercial license.
00032  */
00033 
00034 #ifndef _BILLCYCLE_H_
00035 #define _BILLCYCLE_H_
00036 
00037 // *********************************************************************
00038 // included header files
00039 // + standard includes
00040 #include <list>
00041 #include <vector>
00042 #include <map>
00043 #include <set>
00044 
00045 // + local headers
00046 #include "osbid.h"
00047 #include "chrono.h"
00048 
00049 // *********************************************************************
00050 // class declarations
00051 namespace OSB_DB {
00052     class Session;
00053     class BillcycleGw;
00054 }
00055 
00056 // *********************************************************************
00057 // namespace extensions
00058 namespace OSB_LIB {
00059 
00060 // *********************************************************************
00061 // forward declarations
00062     class TheBillcycleFactory;
00063 
00064 // *********************************************************************
00065 // class definitions
00066 
00074     class Billcycle {
00075         friend class OSB_DB::BillcycleGw;
00079         friend class TheBillcycleFactory;
00080     public:
00082         typedef Id<Billcycle> Oid;
00083 
00090         typedef std::auto_ptr<Billcycle> AutoPtr;
00091 
00103         enum Type {
00104             btUnknown           = 0,    // unknown billcycle type
00105             btIntervalBillcycle = 1,
00106             btDateBillcycle     = 2,
00107             btMidMonthBillcycle = 3
00108         };
00109 
00117         static long toLong(Type bt);
00118 
00126         static Type type(long bt);
00127 
00128     public:
00130         virtual ~Billcycle() {}
00131 
00137         AutoPtr clone() const;
00138 
00140 
00141 
00142         const Oid& oid() const { return id_; }
00144         const std::string& name() const { return name_; }
00146         const std::string& des() const { return des_; }
00148 
00160         virtual Date addBillingPeriod(const Date& from) const =0;
00161 
00172         virtual int readSpecific(
00173             const OSB_DB::Session& session
00174         ) =0;
00175 
00176     private:
00182         virtual Billcycle* clone_() const = 0;
00183 
00184     private:
00185         Oid         id_;                
00186         std::string name_;              
00187         std::string des_;               
00188     }; // class Billcycle
00189 
00198     class DateBillcycle : public Billcycle {
00199     public:
00200         // Documentation from base class.
00201         typedef std::auto_ptr<DateBillcycle> AutoPtr;
00202 
00203         // Default constructor provided by compiler.
00204 
00216         Date addBillingPeriod(const Date& from) const;
00217 
00218         // Documentation from base class.
00219         int readSpecific(const OSB_DB::Session& session);
00220 
00221         // Documentation from base class.
00222         AutoPtr clone() const;
00223 
00224     private:
00225         // Documentation from base class.
00226         virtual Billcycle* clone_() const;
00227 
00228     }; // class DateBillcycle
00229 
00243     class IntervalBillcycle : public Billcycle {
00244         friend class OSB_DB::BillcycleGw;
00245     public:
00246         // Documentation from base class.
00247         typedef std::auto_ptr<IntervalBillcycle> AutoPtr;
00248 
00253         enum Unit {
00254             utUnknown = '\0',          // unknown unit
00255             utDays    = 'd',           // database: 'd'
00256             utMonths  = 'm'            // database: 'm'
00257         };
00258 
00266         static char toChar(Unit ut);
00267 
00275         static Unit unit(char ut);
00276 
00278         IntervalBillcycle()
00279             : Billcycle(), unit_(utUnknown), interval_(0),
00280               startDay_(0), minPeriod_(0) {}
00281 
00283 
00284         Unit unit() const { return unit_; }
00285         int interval() const { return interval_; }
00286         int startDay() const { return startDay_; }
00287         int minPeriod() const { return minPeriod_; }
00289 
00298         Date addBillingPeriod(const Date& from) const;
00299 
00300         // Documentation from base class.
00301         int readSpecific(const OSB_DB::Session& session);
00302 
00303         // Documentation from base class.
00304         AutoPtr clone() const;
00305 
00306     private:
00308         Unit unit_;
00310         int interval_;
00312         int startDay_;
00314         int minPeriod_;
00315         // Documentation from base class.
00316         virtual Billcycle* clone_() const;
00317     }; // class IntervalBillcycle
00318 
00330     class MidMonthBillcycle : public Billcycle {
00331         friend class OSB_DB::BillcycleGw;
00332     public:
00333         // Documentation from base class.
00334         typedef std::auto_ptr<MidMonthBillcycle> AutoPtr;
00335 
00337         MidMonthBillcycle()
00338             : Billcycle(), midMonth_(0), minPeriod_(0) {}
00339 
00341 
00342         int midMonth() const { return midMonth_; }
00343         int minPeriod() const { return minPeriod_; }
00345 
00358         Date addBillingPeriod(const Date& from) const;
00359 
00360         // Documentation from base class.
00361         int readSpecific(const OSB_DB::Session& session);
00362 
00363         // Documentation from base class.
00364         AutoPtr clone() const;
00365 
00366     private:
00368         int midMonth_;
00370         int minPeriod_;
00371 
00372         // Documentation from base class.
00373         virtual Billcycle* clone_() const;
00374     }; // class MidMonthBillcycle
00375 
00379     class BillcycleList {
00380     public:
00382 
00383 
00384         typedef std::vector<Billcycle*> List;
00386         typedef List::iterator Iterator;
00388         typedef List::const_iterator ConstIterator;
00390         typedef List::size_type SizeType;
00392 
00394         BillcycleList() {};
00395 
00402         BillcycleList(const BillcycleList& rhs);
00403 
00405         BillcycleList& operator=(const BillcycleList& rhs);
00406 
00408         ~BillcycleList();
00409 
00418 
00419         Iterator begin() { return list_.begin(); }
00421         Iterator end() { return list_.end(); }
00423         ConstIterator begin() const { return list_.begin(); }
00425         ConstIterator end() const { return list_.end(); }
00427         SizeType size() const { return list_.size(); }
00429         void swap(BillcycleList& rhs);
00431 
00444         void push_back(const Billcycle& bc);
00445 
00461         void push_back(Billcycle::AutoPtr ap);
00462 
00472         Iterator erase(Iterator pos);
00473 
00480         void clear();
00481 
00483         const List& list() const { return list_; }
00484 
00492         long read(const OSB_DB::Session& session);
00493 
00501         Billcycle* findBillcycle(const Billcycle::Oid& oid) const;
00502 
00510         Billcycle& getBillcycle(const Billcycle::Oid& oid) const;
00511 
00512     private:
00514         List list_;
00515     }; // class BillcycleList
00516 
00517     // *****************************************************************
00518     // TheBillcycleFactory
00526     class TheBillcycleFactory {
00527     public:
00540         static TheBillcycleFactory* instance();
00541 
00553         Billcycle::AutoPtr create(Billcycle::Type type);
00554 
00567         Billcycle::AutoPtr create(
00568                   Billcycle::Type type,
00569             const Billcycle::Oid& bcId
00570         );
00571 
00588         void registerBillcycle(
00589             Billcycle::Type type,
00590             Billcycle::AutoPtr billcycle
00591         );
00592 
00593     protected:
00595         TheBillcycleFactory();
00597         TheBillcycleFactory(const TheBillcycleFactory& rhs);
00598 
00599     private:
00601         static TheBillcycleFactory* instance_;
00603         typedef std::map<Billcycle::Type, Billcycle*> Registry;
00605         Registry registry_;
00606 
00607     }; // class TheBillcycleFactory
00608 }                                       // namespace OSB_LIB
00609 #endif                                  // #ifndef _BILLCYCLE_H_

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