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