00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef _RATINGFN_H_
00031 #define _RATINGFN_H_
00032
00033
00034
00035
00036 #include <list>
00037 #include <map>
00038
00039
00040 #include "osbid.h"
00041 #include "osbtype.h"
00042 #include "decimal.h"
00043 #include "tariffobject.h"
00044
00045
00046
00047 namespace OSB_DB {
00048 struct RatingFnGw;
00049 struct RfStairCaseGw;
00050 struct RfSlotGw;
00051 }
00052
00053 namespace OSB_LIB {
00054 class CtBase;
00055 class ChargeTraits;
00056 class Unit;
00057 class Money;
00058 class Currency;
00059 }
00060
00061
00062
00063 namespace OSB_LIB {
00064
00065
00066
00067
00068
00069
00073 class RatingFn : public TariffObject, public ToCfgBase {
00078 friend struct OSB_DB::RatingFnGw;
00083 friend class TariffCatalogue;
00088 friend class RatingFns;
00089 public:
00091 typedef Id<RatingFn> Oid;
00092
00094 typedef TypeId<RatingFn> Type;
00101 typedef std::auto_ptr<RatingFn> AutoPtr;
00103 enum RfType {
00104 rfStairCase = 1,
00105 rfSlot = 2
00106 };
00108 static RfType rfType(const Type& t);
00109 public:
00111 explicit RatingFn(
00112 const Oid& oid = Oid()
00113 );
00115 virtual ~RatingFn() {}
00116
00122 AutoPtr clone() const;
00123
00154 template<typename F> F* isa(F*& ptr);
00156 template<typename F> const F* isa(const F*& ptr) const;
00157 public:
00170 virtual const Money rateVolumeToMoney(
00171 const TypeId<Unit>& unitId,
00172 const Decimal& volume,
00173 Decimal& roundedVolume
00174 ) const = 0;
00175
00186 virtual const Decimal rateMoneyToVolume(
00187 const Money& money
00188 ) const = 0;
00189
00191
00192
00193 virtual Type type() const = 0;
00195 RfType rfType() const;
00197 const Oid& oid() const;
00199 const Id<CtBase>& ctId() const;
00201 const std::string& currency() const;
00203 const TypeId<Unit>& unitId() const;
00205
00207
00208
00215 void setCtId(const ChargeTraits& ct);
00216
00223 void setUnitId(const TypeId<Unit>& id);
00225
00227
00228
00241 bool freeze(
00242 const OSB_DB::Session& session,
00243 OsbErrors& errors
00244 );
00245
00258 bool release(
00259 const OSB_DB::Session& session,
00260 OsbErrors& errors
00261 );
00262
00277 bool revoke(
00278 const OSB_DB::Session& session,
00279 OsbErrors& errors
00280 );
00281
00296 bool unfreeze(
00297 const OSB_DB::Session& session,
00298 OsbErrors& errors
00299 );
00301
00302 protected:
00310 virtual RatingFn& operator=(const RatingFn& rhs);
00311
00312 protected:
00322 bool checkObjVs(
00323 const OSB_DB::Session& session,
00324 OsbErrors& errors
00325 );
00326 private:
00332 virtual RatingFn* clone_() const = 0;
00333
00352 virtual bool freezeSpecific(
00353 const OSB_DB::Session& session,
00354 OsbErrors& errors
00355 ) = 0;
00356
00365 virtual bool releaseSpecific(
00366 const OSB_DB::Session& session,
00367 OsbErrors& errors
00368 ) = 0;
00369
00378 virtual bool revokeSpecific(
00379 const OSB_DB::Session& session,
00380 OsbErrors& errors
00381 ) = 0;
00382
00391 virtual bool unfreezeSpecific(
00392 const OSB_DB::Session& session,
00393 OsbErrors& errors
00394 ) = 0;
00396
00412 virtual bool
00413 readSpecific(const OSB_DB::Session& session) = 0;
00414
00423 virtual bool
00424 insSpecific(const OSB_DB::Session& session) = 0;
00425
00434 virtual bool
00435 removeSpecific(const OSB_DB::Session& session) = 0;
00436
00445 virtual bool
00446 updSpecific(const OSB_DB::Session& session) = 0;
00448
00450
00451 public:
00464 bool read(const OSB_DB::Session& session);
00465
00466 private:
00480 bool insert(const OSB_DB::Session& session);
00481
00495 bool remove(const OSB_DB::Session& session);
00496
00510 bool update(const OSB_DB::Session& session);
00512
00513 private:
00515 Oid oid_;
00517 Id<CtBase> ctId_;
00519 std::string currency_;
00521 TypeId<Unit> unitId_;
00522 };
00523
00524
00525
00534 class RatingFns {
00539 friend struct OSB_DB::RatingFnGw;
00540
00541 public:
00543 RatingFns() {};
00544
00551 RatingFns(const RatingFns& rhs);
00552
00554 RatingFns& operator=(const RatingFns& rhs);
00555
00557 ~RatingFns();
00558
00560
00561
00562 typedef std::list<RatingFn*> List;
00564 typedef List::iterator Iterator;
00566 typedef List::const_iterator ConstIterator;
00568 typedef List::size_type SizeType;
00570
00577
00578 Iterator begin();
00580 Iterator end();
00582 ConstIterator begin() const;
00584 ConstIterator end() const;
00586 SizeType size() const;
00588 void swap(RatingFns& rhs);
00590
00592 const List& list() const { return items_; }
00593
00595 List& getList() { return items_; }
00596
00604 long read(const OSB_DB::Session& session);
00605
00613 RatingFn* ratingFn(
00614 const RatingFn::Oid& id
00615 ) const;
00616
00624 const RatingFn* findRatingFn(
00625 const RatingFn::Oid& id
00626 ) const;
00627
00635 const RatingFn& getRatingFn(
00636 const RatingFn::Oid& id
00637 ) const;
00638
00647 void erase(const RatingFn& rf);
00648
00655 void clear();
00656
00666 void pushBack(const RatingFn& rf);
00667
00677 void pushBack(RatingFn::AutoPtr rf);
00678
00679 private:
00681 List items_;
00682 };
00683
00684
00685
00686
00690 class RfStairCase : public RatingFn
00691 {
00696 friend struct OSB_DB::RfStairCaseGw;
00697
00698 public:
00699
00700 typedef std::auto_ptr<RfStairCase> AutoPtr;
00701
00706 struct Charge {
00708 Charge(
00709 long seq,
00710 const Decimal& len,
00711 long multi,
00712 const Decimal& rate
00713 ) : sequence_(seq), length_(len),
00714 multiplier_(multi), rate_(rate)
00715 {
00716
00717 }
00718
00720 Charge () {};
00721
00723 long sequence_;
00725 Decimal length_;
00727 long multiplier_;
00729 Decimal rate_;
00730 };
00731
00733 typedef std::list<Charge> Charges;
00734
00744 explicit RfStairCase(const RatingFn::Oid& oid = Oid());
00745
00746
00747 AutoPtr clone() const;
00748
00761 virtual const Money rateVolumeToMoney(
00762 const TypeId<Unit>& unitId,
00763 const Decimal& volume,
00764 Decimal& roundedVolume
00765 ) const;
00766
00777 virtual const Decimal rateMoneyToVolume(
00778 const Money& money
00779 ) const;
00780
00782
00783
00784 Type type() const;
00786 const Charges& charges() const;
00788
00790
00791
00800 bool setCharges(const Charges& charges);
00802
00803 private:
00804
00805 virtual RatingFn* clone_() const;
00806
00822 void volumeToMoney(
00823 Decimal& volume,
00824 Decimal& roundedVolume,
00825 long seq,
00826 Decimal& rate
00827 ) const;
00828
00842 void moneyToVolume(
00843 Money& money,
00844 long& seq,
00845 Decimal& volume
00846 ) const;
00847
00849
00850
00858 virtual bool freezeSpecific(
00859 const OSB_DB::Session& session,
00860 OsbErrors& errors
00861 );
00862
00871 virtual bool releaseSpecific(
00872 const OSB_DB::Session& session,
00873 OsbErrors& errors
00874 );
00875
00884 virtual bool revokeSpecific(
00885 const OSB_DB::Session& session,
00886 OsbErrors& errors
00887 );
00888
00897 virtual bool unfreezeSpecific(
00898 const OSB_DB::Session& session,
00899 OsbErrors& errors
00900 );
00902
00904
00905
00912 bool readSpecific(const OSB_DB::Session& session);
00913
00921 bool insSpecific(const OSB_DB::Session& session);
00922
00930 bool removeSpecific(const OSB_DB::Session& session);
00931
00939 bool updSpecific(const OSB_DB::Session& session);
00941
00942 private:
00944 Charges charges_;
00945 };
00946
00947
00948
00949
00963 class RfSlot : public RatingFn
00964 {
00969 friend struct OSB_DB::RfSlotGw;
00970
00971 public:
00972
00973 typedef std::auto_ptr<RfSlot> AutoPtr;
00974
00980 typedef std::map<Decimal, Decimal> Charges;
00981
00991 explicit RfSlot(const RatingFn::Oid& oid = Oid());
00992
00993
00994 AutoPtr clone() const;
00995
01007 virtual const Money rateVolumeToMoney(
01008 const TypeId<Unit>& unitId,
01009 const Decimal& volume,
01010 Decimal& roundedVolume
01011 ) const;
01012
01013 protected:
01017 virtual const Decimal rateMoneyToVolume(const Money&) const;
01018
01019 public:
01021
01022
01023 Type type() const;
01025 const Charges& charges() const;
01027
01029
01030
01039 bool setCharges(const Charges& charges);
01041
01042 private:
01043
01044 virtual RatingFn* clone_() const;
01045
01047
01048
01056 virtual bool freezeSpecific(
01057 const OSB_DB::Session& session,
01058 OsbErrors& errors
01059 );
01060
01069 virtual bool releaseSpecific(
01070 const OSB_DB::Session& session,
01071 OsbErrors& errors
01072 );
01073
01082 virtual bool revokeSpecific(
01083 const OSB_DB::Session& session,
01084 OsbErrors& errors
01085 );
01086
01095 virtual bool unfreezeSpecific(
01096 const OSB_DB::Session& session,
01097 OsbErrors& errors
01098 );
01100
01102
01103
01110 bool readSpecific(const OSB_DB::Session& session);
01111
01119 bool insSpecific(const OSB_DB::Session& session);
01120
01128 bool removeSpecific(const OSB_DB::Session& session);
01129
01137 bool updSpecific(const OSB_DB::Session& session);
01139
01140 private:
01142 Charges charges_;
01143 };
01144
01145
01146
01147
01156 class RatingFnFactory {
01157 public:
01171 static RatingFn::AutoPtr create(
01172 const RatingFn::Type& rfType,
01173 const RatingFn::Oid& oid = RatingFn::Oid()
01174 );
01175
01176 private:
01178 RatingFnFactory();
01180 RatingFnFactory(const RatingFnFactory& rhs);
01181 };
01182
01183
01184
01185
01186
01187
01188 template<typename F> F* RatingFn::isa(F*& ptr)
01189 {
01190 ptr = dynamic_cast<F*>(this);
01191 return ptr;
01192 }
01193
01194 template<typename F> const F* RatingFn::isa(const F*& ptr) const
01195 {
01196 ptr = dynamic_cast<const F*>(this);
01197 return ptr;
01198 }
01199 }
01200 #endif // #ifndef _RATINGFN_H_