Luiza  v03-01
GloriaTableColumn.h
1 // -*- mode: c++; mode: auto-fill; mode: flyspell-prog; -*-
2 
3 
4 #ifndef GloriaTableColumn_h
5 #define GloriaTableColumn_h 1
6 
7 
8 /*
9  * This source code is part of the LUIZA software package for GLORIA.
10  * You are free to use this source files for your own development as
11  * long as it stays in a public research context. You are not
12  * allowed to use it for commercial purpose. You must put this
13  * header with author names in all development based on this file.
14  *
15  */
16 
17 #include <string>
18 #include <vector>
19 #include <map>
20 #include <sstream>
21 
22 #include "GloriaSTLTypes.h"
23 
24 using namespace std;
25 
26 namespace gloria{
27 
28 
30 
47  { UndefinedColumn = 0,
48  LongColumn,
49  DoubleColumn,
50  StringColumn,
51  LongVectorColumn,
52  DoubleVectorColumn
53  };
54 
56 
59 template<class T>
60 TableColumnType GetValueType(T val);
61 
63 
66 template<class T>
67 string GetValueTypeName(T val);
68 
69 
71 
81 
82 public:
83 
84  GloriaTableColumn(string Name, string Unit = "", string Comment = "") :
85  _name(Name), _unit(Unit), _comment(Comment){}
86 
87  inline virtual ~GloriaTableColumn() {}
88 
90  inline string& Name() { return _name; }
91 
93  inline string& Unit() { return _unit; }
94 
96  inline string& Comment() { return _comment; }
97 
99  inline TableColumnType& Type() { return _type; }
100 
102  string TypeName();
103 
105  virtual int Size() = 0;
106 
108  virtual void Clear() = 0;
109 
111  virtual void AddRow() = 0;
112 
114  virtual void Resize(int Nrow) = 0;
115 
117  virtual void DeleteRow(int iRow) = 0;
118 
120 
125  virtual int ValSize(int i) = 0;
126 
128 
132  virtual long LongVal(int i, int j=0) = 0;
133 
135 
139  virtual double DoubleVal(int i, int j=0) = 0;
140 
142 
146  virtual string StringVal(int i) = 0;
147 
149 
153  virtual string StringVal(int i, int j) = 0;
154 
155 
157  virtual GloriaTableColumn* Clone() = 0;
158 
159 
161  virtual GloriaTableColumn* EmptyClone() = 0;
162 
163 
165  virtual void CopyCellValue(GloriaTableColumn* source, int isource, int itarget=-1) = 0;
166 
167 
169  virtual long* CreateSortIndex(bool reverse=false) = 0;
170 
172  virtual void SortByIndex(long* index) = 0;
173 
174 protected:
175  string _name;
176  string _unit;
177  string _comment;
178  TableColumnType _type;
179 };
180 
181 
182 
184 template <class T>
186 
187 public:
188  GloriaTableColumnOf(string Name, T empty, string Unit = "", string Comment = "") :
189  GloriaTableColumn(Name,Unit,Comment), _emptyVal(empty)
190  { _type = GetValueType(empty); }
191 
192  inline ~GloriaTableColumnOf() {}
193 
195  inline vector<T>& Data() { return _data;}
196 
198  inline T& At(int i) { return _data.at(i); }
199 
201  inline T& EmptyVal() { return _emptyVal; }
202 
204  inline int Size() { return _data.size(); }
205 
207  inline void Clear() { _data.clear(); }
208 
210  inline void Push_Back(T val) { _data.push_back(val); }
211 
213  inline void AddRow() { _data.push_back(_emptyVal); }
214 
216  inline void Resize(int Nrow){_data.resize(Nrow,_emptyVal); }
217 
219  inline void DeleteRow(int iRow) { _data.erase(_data.begin()+iRow); }
220 
221 
223 
228  int ValSize(int i);
229 
230 
232 
236  long LongVal(int i, int j=0);
237 
238 
240 
244  double DoubleVal(int i, int j=0);
245 
246 
248 
252  string StringVal(int i);
253 
255 
259  string StringVal(int i, int j);
260 
262  GloriaTableColumn* Clone();
263 
265  GloriaTableColumn* EmptyClone();
266 
268  void CopyCellValue(GloriaTableColumn* source, int isource, int itarget=-1);
269 
271  long* CreateSortIndex(bool reverse=false);
272 
274  void SortByIndex(long* index);
275 
276 protected:
277 
278  T _emptyVal;
279  vector<T> _data;
280 };
281 
282 
283 
284 }
285 
286 #endif
287 
288 
289 
TableColumnType
Enumerator for allowed column type classes.
Definition: GloriaTableColumn.h:46
namespace for data storing and exchange formats
Definition: GloriaAstrometry.h:15
Abstract class. Used for deriving classes with different column types.
Definition: GloriaTableColumn.h:80
TableColumnType GetValueType(T val)
Helper function recognizing column type.
Definition: GloriaTableColumn.cc:22
void Push_Back(T val)
Add element to the column.
Definition: GloriaTableColumn.h:210
Table column class for different content types.
Definition: GloriaTableColumn.h:185
vector< T > & Data()
Direct access to the data stored in the table.
Definition: GloriaTableColumn.h:195
void DeleteRow(int iRow)
Delete given cell.
Definition: GloriaTableColumn.h:219
T & EmptyVal()
Element used to initialize empty cells when new row is added.
Definition: GloriaTableColumn.h:201
void Resize(int Nrow)
Resize column to given number of rows.
Definition: GloriaTableColumn.h:216
string & Name()
Column name. Used to address columns in the table.
Definition: GloriaTableColumn.h:90
string & Comment()
Column comment, can be used to store additional information.
Definition: GloriaTableColumn.h:96
void Clear()
Clear column (clear vector of column elements)
Definition: GloriaTableColumn.h:207
void AddRow()
Add empty cell at the end of the column.
Definition: GloriaTableColumn.h:213
int Size()
Column size (size of vector storing column elements)
Definition: GloriaTableColumn.h:204
TableColumnType & Type()
Column type defining type of elements stored.
Definition: GloriaTableColumn.h:99
string & Unit()
Units for values stored in this column.
Definition: GloriaTableColumn.h:93
T & At(int i)
Direct access to single cell.
Definition: GloriaTableColumn.h:198