UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
table_doc.hpp
1 /* table_doc.hpp */
2 /* $Id$ */
3 #ifndef __table_doc_hpp
4 #define __table_doc_hpp
5 
6 #include <string>
7 
9 namespace hds
10 {
12  class TableDoc
13  {
14  public:
15 
17  enum ItemType
18  {
24  };
25 
28  {
29  public:
30 
32  AbstractItem(const bool ro_flag = false):
33  m_ro_flag(ro_flag) {/* nothing to do. */}
34 
36  virtual ~AbstractItem() {/* nothing to do. */}
37 
39  virtual ItemType type() const {return InvalidType;}
40 
42  bool readOnly() const {return m_ro_flag;}
43 
45  void setReadOnly(const bool ro_flag) {m_ro_flag = ro_flag;}
46 
47  private:
48 
50  bool m_ro_flag;
51  };
52 
54  template <typename T>
55  class Item : public AbstractItem
56  {
57  public:
58 
60  Item(const bool ro_flag = false):
61  AbstractItem(ro_flag) {/* nothing to do. */}
62 
64  Item(const T &val, const bool ro_flag=false):
65  AbstractItem(ro_flag), m_val(val) {/* nothing to do. */}
66 
68  const T& value() const {return m_val;}
69 
71  void setValue(const T &val) {m_val = val;}
72 
74  virtual ItemType type() const {return InvalidType;}
75 
76  private:
77 
79  T m_val;
80  };
81 
83  class HdrItem
84  {
85  public:
86 
88  HdrItem(const ItemType items_type,
89  const std::string &caption_str = std::string()):
90  m_items_type(items_type),
91  m_caption(caption_str) {/* nothing to do. */}
92 
94  ItemType type() const {return m_items_type;}
95 
97  void setType(const ItemType items_type) {m_items_type = items_type;}
98 
100  const std::string& caption() const {return m_caption;}
101 
103  void setCaption(const std::string &caption_str) {m_caption = caption_str;}
104 
105  protected:
106 
109 
111  std::string m_caption;
112  };
113 
114 
116  TableDoc(const std::string &name = std::string());
117 
119  virtual ~TableDoc() {/* nothing to do. */}
120 
121  /*
122  * Common polymorphic methods
123  */
124 
126  virtual size_t rowsNum() const = 0;
127 
129  virtual size_t colsNum() const = 0;
130 
131 
133  virtual const HdrItem& hdrItem(const size_t col) const = 0;
134 
135 
139  virtual const AbstractItem& item(const size_t row, const size_t col) const = 0;
140 
143  virtual bool setItem(const size_t row, const size_t col, const AbstractItem &item) = 0;
144 
145 
150  virtual bool insertRow(const size_t cur_row) = 0;
151 
155  virtual bool removeRow(const size_t row) = 0;
156 
157  /*
158  * Additional features
159  */
160 
164  virtual bool canInsertRow(const size_t /*cur_row*/) const {return true;}
165 
169  virtual bool canRemoveRow(const size_t /*row*/) const {return true;}
170 
172  const std::string& name() const;
173 
174  private:
175 
177  std::string m_name;
178  };
179 
180  // IntegerType table item specialization
181  template <>
182  inline TableDoc::ItemType TableDoc::Item<int>::type() const {return IntegerType;}
183  template <>
184  inline TableDoc::Item<int>::Item(const bool ro_flag):
185  AbstractItem(ro_flag), m_val(0) {/* nothing to do */}
186 
187  // FloatType table item specialization
188  template <>
190  template <>
191  inline TableDoc::Item<float>::Item(const bool ro_flag):
192  AbstractItem(ro_flag), m_val(0.) {/* nothing to do */}
193 
194  // DoubleType table item specialization
195  template <>
197  template <>
198  inline TableDoc::Item<double>::Item(const bool ro_flag):
199  AbstractItem(ro_flag), m_val(0.) {/* nothing to do */}
200 
201  // StringType table item specialization
202  template <>
204 
205 }; // hds
206 
207 #endif /* table_doc.hpp */
virtual const AbstractItem & item(const size_t row, const size_t col) const =0
virtual bool canRemoveRow(const size_t) const
Definition: table_doc.hpp:169
Item(const T &val, const bool ro_flag=false)
Definition: table_doc.hpp:64
TableDoc(const std::string &name=std::string())
virtual ~AbstractItem()
Definition: table_doc.hpp:36
AbstractItem(const bool ro_flag=false)
Definition: table_doc.hpp:32
Definition: table_doc.hpp:12
Definition: table_doc.hpp:19
bool readOnly() const
Definition: table_doc.hpp:42
virtual const HdrItem & hdrItem(const size_t col) const =0
void setType(const ItemType items_type)
Definition: table_doc.hpp:97
virtual bool setItem(const size_t row, const size_t col, const AbstractItem &item)=0
virtual ItemType type() const
Definition: table_doc.hpp:39
virtual bool insertRow(const size_t cur_row)=0
virtual size_t rowsNum() const =0
Definition: table_doc.hpp:27
Item(const bool ro_flag=false)
Definition: table_doc.hpp:60
void setReadOnly(const bool ro_flag)
Definition: table_doc.hpp:45
const T & value() const
Definition: table_doc.hpp:68
ItemType m_items_type
Definition: table_doc.hpp:108
const std::string & name() const
virtual bool removeRow(const size_t row)=0
virtual ItemType type() const
Definition: table_doc.hpp:74
Definition: table_doc.hpp:23
ItemType type() const
Definition: table_doc.hpp:94
Definition: table_doc.hpp:55
HdrItem(const ItemType items_type, const std::string &caption_str=std::string())
Definition: table_doc.hpp:88
virtual bool canInsertRow(const size_t) const
Definition: table_doc.hpp:164
void setCaption(const std::string &caption_str)
Definition: table_doc.hpp:103
Definition: table_doc.hpp:83
Definition: table_doc.hpp:20
Definition: table_doc.hpp:22
Definition: table_doc.hpp:21
virtual ~TableDoc()
Definition: table_doc.hpp:119
virtual size_t colsNum() const =0
const std::string & caption() const
Definition: table_doc.hpp:100
void setValue(const T &val)
Definition: table_doc.hpp:71
ItemType
Definition: table_doc.hpp:17