otsdaq  v2_04_01
RegisterView.h
1 /*
2  * RegisterView.h
3  *
4  * Created on: Jul 29, 2015
5  * Author: parilla
6  */
7 
8 #ifndef _ots_RegisterView_h_
9 #define _ots_RegisterView_h_
10 #include "otsdaq-core/ConfigurationDataFormats/ViewRegisterInfo.h"
11 #include "otsdaq-core/ConfigurationDataFormats/ViewRegisterSequencerInfo.h"
12 #include "otsdaq-core/Macros/CoutMacros.h"
13 #include "otsdaq-core/MessageFacility/MessageFacility.h"
14 
15 #include <stdlib.h>
16 #include <cassert>
17 #include <iostream>
18 #include <sstream> // std::stringstream, std::stringbuf
19 #include <string>
20 #include <typeinfo>
21 #include <vector>
22 namespace ots
23 {
25 {
26  public:
27  typedef std::vector<std::vector<std::string> > DataView;
28  typedef DataView::iterator iterator;
29  typedef DataView::const_iterator const_iterator;
30 
31  RegisterView(std::string name = "");
32  virtual ~RegisterView();
33 
34  unsigned int findRow(unsigned int col, const std::string value) const;
35  unsigned int findRow(unsigned int col, const unsigned int value) const;
36 
37  // Getters
38  std::string getName() const;
39  int getVersion() const;
40  std::string getComment() const;
41  std::string getAuthor() const;
42  time_t getCreationTime() const;
43  unsigned int getNumberOfRows() const;
44  unsigned int getNumberOfColumns() const;
45  const std::vector<ViewRegisterInfo>& getRegistersInfo() const;
46  std::vector<ViewRegisterInfo>* getRegistersInfoPointer();
47  const std::vector<ViewRegisterSequencerInfo>& getRegistersSequencerInfo() const;
48  std::vector<ViewRegisterSequencerInfo>* getRegistersSequencerInfoPointer();
49 
50  /*template<class T>
51  void getValue(T& value, unsigned int row, unsigned int col) const
52  {
53  assert(col < columnsInfo_.size() && row < getNumberOfRows());
54  if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_NUMBER)
55  if(typeid(double) == typeid(value))
56  value = strtod(theDataView_[row][col].c_str(),0);
57  else if(typeid(float) == typeid(value))
58  value = strtof(theDataView_[row][col].c_str(),0);
59  else
60  value = strtol(theDataView_[row][col].c_str(),0,10);
61  else
62  {
63  std::cout << __COUT_HDR_FL__ << "\tUnrecognized View data type: " <<
64  columnsInfo_[col].getDataType() << std::endl; assert(0);
65  }
66  }
67  void getValue(std::string& value, unsigned int row, unsigned int col) const
68  {
69  assert(col < columnsInfo_.size() && row < getNumberOfRows());
70  if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
71  value = theDataView_[row][col];
72  else if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
73  value = theDataView_[row][col];
74  else
75  {
76  std::cout << __COUT_HDR_FL__ << "\tUnrecognized View data type: " <<
77  columnsInfo_[col].getDataType() << std::endl; assert(0);
78  }
79  }*/
80 
81  // Setters
82  void setName(std::string name);
83  void setVersion(int version);
84  void setVersion(char* version);
85  void setComment(std::string name);
86  void setAuthor(std::string name);
87  void setCreationTime(time_t t);
88 
89  /* template<class T>
90  void setValue(T value, unsigned int row, unsigned int col)
91  {
92  assert(col < columnsInfo_.size() && row < getNumberOfRows());
93  if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_NUMBER)
94  {
95  std::stringstream ss;
96  ss << value;
97  theDataView_[row][col] = ss.str();
98  //TODO: Should this number be forced to a long int???.. currently getValue
99  only gets long int.
100  }
101  else
102  {
103  std::cout << __COUT_HDR_FL__ << "\tUnrecognized View data type: " <<
104  columnsInfo_[col].getDataType() << std::endl; assert(0);
105  }
106  }*/
107  /*void setValue(std::string value, unsigned int row, unsigned int col)
108  {
109  assert(col < columnsInfo_.size() && row < getNumberOfRows());
110  if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_STRING)
111  theDataView_[row][col] = value;
112  else if(columnsInfo_[col].getDataType() == TableViewColumnInfo::DATATYPE_TIME)
113  theDataView_[row][col] = value;
114  else
115  {
116  std::cout << __COUT_HDR_FL__ << "\tUnrecognized View data type: " <<
117  columnsInfo_[col].getDataType() << std::endl; assert(0);
118  }
119  }*/
120 
121  int addRow(); // returns index of added row, always is last row unless
122  bool deleteRow(int r); // returns true on success
123 
124  private:
125  std::string name_; // View name (extensionTableName in xml)
126  int version_; // Configuration version
127  std::string comment_; // Configuration version comment
128  std::string author_;
129  time_t creationTime_;
130  std::vector<ViewRegisterInfo> registersInfo_;
131  std::vector<ViewRegisterSequencerInfo> registersSequencerInfo_;
132  DataView theDataView_;
133 };
134 
135 } // namespace ots
136 
137 #endif /* REGISTERVIEW_H_ */