00001
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef _BILLCYCLE_H_
00035 #define _BILLCYCLE_H_
00036
00037
00038
00039
00040 #include <list>
00041 #include <vector>
00042 #include <map>
00043 #include <set>
00044
00045
00046 #include "osbid.h"
00047 #include "chrono.h"
00048
00049
00050
00051 namespace OSB_DB {
00052 class Session;
00053 class BillcycleGw;
00054 }
00055
00056
00057
00058 namespace OSB_LIB {
00059
00060
00061
00062 class TheBillcycleFactory;
00063
00064
00065
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,
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 };
00189
00198 class DateBillcycle : public Billcycle {
00199 public:
00200
00201 typedef std::auto_ptr<DateBillcycle> AutoPtr;
00202
00203
00204
00216 Date addBillingPeriod(const Date& from) const;
00217
00218
00219 int readSpecific(const OSB_DB::Session& session);
00220
00221
00222 AutoPtr clone() const;
00223
00224 private:
00225
00226 virtual Billcycle* clone_() const;
00227
00228 };
00229
00243 class IntervalBillcycle : public Billcycle {
00244 friend class OSB_DB::BillcycleGw;
00245 public:
00246
00247 typedef std::auto_ptr<IntervalBillcycle> AutoPtr;
00248
00253 enum Unit {
00254 utUnknown = '\0',
00255 utDays = 'd',
00256 utMonths = '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
00301 int readSpecific(const OSB_DB::Session& session);
00302
00303
00304 AutoPtr clone() const;
00305
00306 private:
00308 Unit unit_;
00310 int interval_;
00312 int startDay_;
00314 int minPeriod_;
00315
00316 virtual Billcycle* clone_() const;
00317 };
00318
00330 class MidMonthBillcycle : public Billcycle {
00331 friend class OSB_DB::BillcycleGw;
00332 public:
00333
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
00361 int readSpecific(const OSB_DB::Session& session);
00362
00363
00364 AutoPtr clone() const;
00365
00366 private:
00368 int midMonth_;
00370 int minPeriod_;
00371
00372
00373 virtual Billcycle* clone_() const;
00374 };
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 };
00516
00517
00518
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 };
00608 }
00609 #endif // #ifndef _BILLCYCLE_H_