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 _PRODUCTITEM_H_
00031 #define _PRODUCTITEM_H_
00032
00033
00034
00035
00036 #include <vector>
00037
00038
00039
00040
00041 #include "osbid.h"
00042 #include "osbtype.h"
00043
00044
00045 namespace OSB_DB {
00046 class Session;
00047 class ProductGw;
00048 }
00049
00050 namespace OSB_LIB {
00051 class PersProductItem;
00052 }
00053
00054
00055
00056 namespace OSB_LIB {
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00081 class ProductItemBase {
00082 public:
00088 typedef TypeId<ProductItemBase> Type;
00089 public:
00091 ProductItemBase();
00093 virtual ~ProductItemBase();
00094
00095 protected:
00097 ProductItemBase(const ProductItemBase& rhs);
00099 ProductItemBase& operator=(const ProductItemBase& rhs);
00100
00101 public:
00129 template<typename P> P* isa(P*& ptr);
00131 template<typename P> const P* isa(const P*& ptr) const;
00132
00153 virtual Type type() const = 0;
00154 };
00155
00156
00157
00161 class ProductItem : public ProductItemBase {
00167 friend class OSB_DB::ProductGw;
00168
00169 public:
00171 typedef Id<ProductItem> Oid;
00172
00179 typedef std::auto_ptr<ProductItem> AutoPtr;
00180
00187 enum CfgType {
00188 cfgMandatory = -1,
00189 cfgOptional = 0,
00190 cfgNone = 1
00191 };
00192
00199 enum DefPersType {
00201 defPersMandatory = -1,
00203 defPersOptional = 0,
00205 defPersNone = 1
00206 };
00207
00214 enum CfgPersType {
00215 persMandatory = -1,
00216 persOptional = 0,
00217 persNone = 1
00218 };
00219
00223 ProductItem(
00224 const Oid& oid,
00225 const std::string& name = "",
00226 const std::string& desc = ""
00227 );
00228
00234 AutoPtr clone() const;
00235
00236 protected:
00238 ProductItem(const ProductItem& rhs);
00240 ProductItem& operator=(const ProductItem& rhs);
00241
00242 private:
00248 virtual ProductItem* clone_() const = 0;
00249
00250 public:
00252
00253
00254 const Oid& oid() const { return oid_; }
00256 const std::string& name() const { return name_; }
00258 const std::string& desc() const { return des_; }
00265 virtual CfgType canConfigure() const = 0;
00272 virtual DefPersType canDefPers() const = 0;
00279 virtual CfgPersType canPersonalize() const = 0;
00285 virtual const PersProductItem* defPersItem() const = 0;
00286
00295 const std::string& configDes() const { return configDes_; }
00304 const std::string& defPersDes() const { return defPersDes_; }
00306
00308
00309
00310 void setName(const std::string& name);
00312 void setDesc(const std::string& desc);
00319 bool setConfigDes(const std::string& configDes);
00327 bool setDefPersDes(const std::string& defPersDes);
00329
00342 virtual std::auto_ptr<PersProductItem>
00343 crePersProductItem() const = 0;
00344
00345 public:
00370 bool read(
00371 const OSB_DB::Session& session,
00372 bool baseRead = false
00373 );
00374
00396 bool insert(const OSB_DB::Session& session);
00397
00414 bool update(const OSB_DB::Session& session);
00415
00436 bool remove(const OSB_DB::Session& session);
00438
00439 private:
00460 virtual bool
00461 readSpecific(const OSB_DB::Session& session) = 0;
00462
00470 virtual bool
00471 insSpecific(const OSB_DB::Session& session) = 0;
00472
00480 virtual bool
00481 updSpecific(const OSB_DB::Session& session) = 0;
00482
00491 virtual bool
00492 delSpecific(const OSB_DB::Session& session) = 0;
00494
00504 public:
00505 virtual std::ostream& prInfo(std::ostream& os) const;
00506
00507 private:
00508 Oid oid_;
00509 std::string name_;
00510 std::string des_;
00511 protected:
00513 std::string configDes_;
00515 std::string defPersDes_;
00516 };
00517
00519 std::ostream& operator<<(
00520 std::ostream& o,
00521 const ProductItem& pi
00522 );
00523
00535 class DescriptionItem : public ProductItem {
00536 public:
00538 static const Type type_;
00539
00540 typedef std::auto_ptr<DescriptionItem> AutoPtr;
00541
00542 public:
00549 DescriptionItem(
00550 const Oid& oid,
00551 const std::string& name = "",
00552 const std::string& des = ""
00553 );
00554
00555 public:
00556
00557 Type type() const { return type_; }
00558
00559 AutoPtr clone() const;
00560
00565 std::auto_ptr<PersProductItem> crePersProductItem() const;
00566
00568 ProductItem::CfgType canConfigure() const
00569 {
00570 return ProductItem::cfgNone;
00571 }
00572
00574 ProductItem::DefPersType canDefPers() const
00575 {
00576 return ProductItem::defPersNone;
00577 }
00578
00580 CfgPersType canPersonalize() const
00581 {
00582 return persNone;
00583 }
00584
00586 const PersProductItem* defPersItem() const
00587 {
00588 return 0;
00589 }
00590
00591 private:
00598 bool readSpecific(const OSB_DB::Session& session);
00599 bool insSpecific(const OSB_DB::Session& session);
00600 bool updSpecific(const OSB_DB::Session& session);
00601 bool delSpecific(const OSB_DB::Session& session);
00603
00604
00605 ProductItem* clone_() const;
00606 };
00607
00608
00609
00616 class ProductItemTypes {
00617 public:
00619 struct Info {
00621 typedef TypeId<ProductItemBase> PiType;
00623 PiType type_;
00625 std::string name_;
00627 std::string des_;
00629 bool isProductPart_;
00630
00632 Info();
00633 };
00634
00636 typedef std::vector<Info> List;
00638 typedef List::iterator Iterator;
00640 typedef List::const_iterator ConstIterator;
00642 typedef List::size_type SizeType;
00643
00645 const List& list() const;
00646
00655
00656 Iterator begin();
00658 Iterator end();
00660 ConstIterator begin() const;
00662 ConstIterator end() const;
00664 SizeType size() const;
00666 void swap(List& other);
00668
00679 long read(const OSB_DB::Session& session);
00680
00689 const Info* find(TypeId<ProductItemBase> type) const;
00690
00698 const Info& get(TypeId<ProductItemBase> type) const;
00699
00700 private:
00702 List list_;
00703 };
00704 }
00705
00706
00707
00708 namespace OSB_LIB {
00709
00710
00711
00712 template<typename P>
00713 P* ProductItemBase::isa(P*& ptr)
00714 {
00715 ptr = dynamic_cast<P*>(this);
00716 return ptr;
00717 }
00718
00719 template<typename P>
00720 const P* ProductItemBase::isa(const P*& ptr) const
00721 {
00722 ptr = dynamic_cast<const P*>(this);
00723 return ptr;
00724 }
00725 }
00726 #endif // #ifndef _PRODUCTITEM_H_