Row.h
Go to the documentation of this file.
1 #ifndef __DBIROW_HPP_
2 #define __DBIROW_HPP_
3 
4 #include <string>
5 #include <vector>
6 
9 
10 namespace nutools {
11  namespace dbi {
12 
13  /**
14  * Generalized Database Row Interface
15  *
16  * @author Jonathan Paley
17  * @version $Id: Row.h,v 1.16 2011/11/01 16:15:18 anorman Exp $
18  */
19  class Row
20  {
21  public:
22  Row(int ncol) : fIsVldRow(false), fNModified(0), fCol(ncol) { };
23 
24  Row(const std::vector<Column>&);
25  Row(std::vector<ColumnDef>&);
26  ~Row();
27 
28  void Clear();
29 
30  template <class T>
31  bool Set(int idx, T value) {
32  if (idx < (int)fCol.size() && idx>=0)
33  return (fCol[idx].Set(value));
34  return false;
35  }
36 
37  template <class T>
38  bool Update(int idx, T value) {
39  if (idx < (int)fCol.size() && idx>=0) {
40  if (!fCol[idx].Modified()) fNModified++;
41  return (fCol[idx].Update(value));
42  }
43  return false;
44  }
45 
46  bool InDB() { return fInDB; }
47  void SetInDB() { fInDB = true; }
48 
49  int NModified() { return fNModified; }
50 
51  int NCol() { return fCol.size(); }
52 
53  Column& Col(int i) {return fCol[i]; }
54 
55  uint64_t Channel() { return fChannel; }
56  float VldTime() { return fVldTime; }
57  float VldTimeEnd() { return fVldTimeEnd; }
58  bool IsVldRow() { return fIsVldRow; }
59 
60  bool SetChannel(uint64_t ch) { fIsVldRow=true; return (fChannel=ch); }
61  bool SetVldTime(float t) { fIsVldRow=true; return (fVldTime=t); }
62  bool SetVldTimeEnd(float t) { fIsVldRow=true; return (fVldTime=t); }
63 
64  // bool operator==(const Row& other) const;
65 
66  friend std::ostream& operator<< (std::ostream& stream, const Row& row);
67  // friend std::istream& operator>> (std::istream& stream, Row& row);
68 
69  private:
70  bool fInDB;
71  bool fIsVldRow;
73  uint64_t fChannel;
74  float fVldTime;
75  float fVldTimeEnd;
76  std::vector<Column> fCol;
77 
78  }; // class end
79 
80  //************************************************************
81 
82  inline std::ostream& operator<< (std::ostream& stream, const Row& row) {
83  for (unsigned int i=0; i<row.fCol.size(); ++i) {
84  stream << row.fCol[i];
85  if (i < row.fCol.size()-1)
86  stream << ", ";
87  }
88  return stream;
89  }
90 
91  } // namespace dbi close
92 } // namespace nova close
93 
94 #endif
std::vector< Column > fCol
Definition: Row.h:76
bool Update(int idx, T value)
Definition: Row.h:38
float VldTime()
Definition: Row.h:56
uint64_t fChannel
Definition: Row.h:73
bool InDB()
Definition: Row.h:46
bool fIsVldRow
Definition: Row.h:71
uint64_t Channel()
Definition: Row.h:55
int NModified()
Definition: Row.h:49
Row(int ncol)
Definition: Row.h:22
int NCol()
Definition: Row.h:51
Simple service to provide a RunHistory configured to the right run.
Definition: Column.cpp:14
void SetInDB()
Definition: Row.h:47
float fVldTimeEnd
Definition: Row.h:75
const XML_Char int const XML_Char * value
Definition: expat.h:331
float fVldTime
Definition: Row.h:74
float VldTimeEnd()
Definition: Row.h:57
bool Set(int idx, T value)
Definition: Row.h:31
bool IsVldRow()
Definition: Row.h:58
void Clear()
Definition: Row.cpp:40
bool fInDB
Definition: Row.h:70
friend std::ostream & operator<<(std::ostream &stream, const Row &row)
Definition: Row.h:82
bool SetVldTimeEnd(float t)
Definition: Row.h:62
double T
Definition: Xdiff_gwt.C:5
int fNModified
Definition: Row.h:72
Column & Col(int i)
Definition: Row.h:53
bool SetChannel(uint64_t ch)
Definition: Row.h:60
bool SetVldTime(float t)
Definition: Row.h:61
c1 Modified()