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 _ROUNDRULE_H_
00035 #define _ROUNDRULE_H_
00036
00037
00038
00039
00040
00041
00042 #include "osbid.h"
00043 #include "decimal.h"
00044
00045
00046
00047 namespace OSB_DB {
00048 class Session;
00049 }
00050
00051
00052
00053 namespace OSB_LIB {
00054
00055
00056
00057
00058
00059
00060
00066 class RoundRule
00067 {
00068 public:
00070 typedef Id<RoundRule> Oid;
00071
00078 typedef std::auto_ptr<RoundRule> AutoPtr;
00079
00086 enum Type {
00087 rr_unknown = 0,
00088 rr_roundUp = 1,
00089 rr_dontRound = 2
00090 };
00091
00093 RoundRule(const Oid& id): id_(id) {}
00095 RoundRule(const Oid& id,
00096 const std::string& name,
00097 const std::string& des
00098 ) : id_(id), name_(name), des_(des) {}
00100 virtual ~RoundRule() {}
00102 virtual Decimal operator()(const Decimal&) const =0;
00104 Decimal round(const Decimal& d) const { return operator()(d); }
00105
00107
00108
00109 const Oid& oid() const { return id_; }
00111 const std::string& name() const { return name_; }
00113 const std::string& des() const { return des_; }
00115
00117
00118
00119 void setName(const std::string& name);
00121 void setDes(const std::string& des);
00123
00129 AutoPtr clone() const;
00130
00158 template<typename R> R* isa(R*& ptr);
00160 template<typename R> const R* isa(R*& ptr) const;
00161
00162 private:
00163 Oid id_;
00164 std::string name_;
00165 std::string des_;
00166
00167 private:
00173 virtual RoundRule* clone_() const = 0;
00174 };
00175
00195 class RoundUp : public RoundRule
00196 {
00197 public:
00198
00199 typedef std::auto_ptr<RoundUp> AutoPtr;
00200
00202 RoundUp(const Oid& id,
00203 const Decimal& threshold,
00204 const Decimal& multiple);
00206 RoundUp(const Oid& id,
00207 const std::string& name,
00208 const std::string& des,
00209 const Decimal& threshold,
00210 const Decimal& multiple);
00211
00212 Decimal operator()(const Decimal& d) const;
00213
00215
00216
00217 const Decimal& threshold() const { return threshold_; }
00219 const Decimal& multiple() const { return multiple_; }
00221
00222
00223 AutoPtr clone() const;
00224
00225 private:
00226 Decimal threshold_;
00227 Decimal multiple_;
00228
00229 private:
00230
00231 virtual RoundRule* clone_() const;
00232 };
00233
00239 class DontRound : public RoundRule
00240 {
00241 public:
00242
00243 typedef std::auto_ptr<DontRound> AutoPtr;
00244
00246 DontRound(const Oid& id) : RoundRule(id) {};
00248 DontRound(const Oid& id,
00249 const std::string& name,
00250 const std::string& des
00251 ) : RoundRule(id, name, des) {};
00252
00253 Decimal operator()(const Decimal& d) const { return d; }
00254
00255
00256 AutoPtr clone() const;
00257
00258 private:
00259
00260 virtual RoundRule* clone_() const;
00261 };
00262
00266 class RoundRuleList {
00267 public:
00269
00270
00271 typedef std::vector<RoundRule*> List;
00273 typedef List::iterator Iterator;
00275 typedef List::const_iterator ConstIterator;
00277 typedef List::size_type SizeType;
00279
00281 RoundRuleList() {};
00282
00289 RoundRuleList(const RoundRuleList& rhs);
00290
00292 RoundRuleList& operator=(const RoundRuleList& rhs);
00293
00295 ~RoundRuleList();
00296
00305
00306 Iterator begin() { return list_.begin(); }
00308 Iterator end() { return list_.end(); }
00310 ConstIterator begin() const { return list_.begin(); }
00312 ConstIterator end() const { return list_.end(); }
00314 SizeType size() const { return list_.size(); }
00316 void swap(RoundRuleList& rhs);
00318
00331 void push_back(const RoundRule& rr);
00332
00348 void push_back(RoundRule::AutoPtr ap);
00349
00359 Iterator erase(Iterator pos);
00360
00367 void clear();
00368
00370 const List& list() const { return list_; }
00371
00379 long read(const OSB_DB::Session& session);
00380
00388 const RoundRule* findRoundRule(const RoundRule::Oid& oid) const;
00389
00397 const RoundRule& getRoundRule(const RoundRule::Oid& oid) const;
00398
00406 RoundRule::Oid getRoundRuleByName(const std::string& name) const;
00407
00408 private:
00410 List list_;
00411 };
00412
00413
00414
00425 class RoundRuleFactory {
00426 public:
00446 static RoundRule::AutoPtr create(
00447 const RoundRule::Type& type,
00448 const RoundRule::Oid& oid,
00449 const Decimal& threshold,
00450 const Decimal& multiple
00451 );
00452
00474 static RoundRule::AutoPtr create(
00475 const RoundRule::Type& type,
00476 const RoundRule::Oid& oid,
00477 const std::string& name,
00478 const std::string& desc,
00479 const Decimal& threshold,
00480 const Decimal& multiple
00481 );
00482
00483 private:
00485 RoundRuleFactory();
00487 RoundRuleFactory(const RoundRuleFactory& rhs);
00488 };
00489
00490
00491
00492
00493
00494
00495
00496 template<typename R> R* RoundRule::isa(R*& ptr)
00497 {
00498 ptr = dynamic_cast<R*>(this);
00499 return ptr;
00500 }
00501
00502 template<typename R> const R* RoundRule::isa(R*& ptr) const
00503 {
00504 ptr = dynamic_cast<const R*>(this);
00505 return ptr;
00506 }
00507
00508
00509 }
00510 #endif // #ifndef _ROUNDRULE_H_
00511
00512