8#ifndef _Belle2_AbstractDBObject_hh
9#define _Belle2_AbstractDBObject_hh
11#include <daq/slc/base/FieldProperty.h>
13#include <daq/slc/base/Serializable.h>
38 const std::string& getPath()
const {
return m_path; }
39 void setPath(
const std::string& path) { m_path = path; }
40 int getId()
const {
return m_id; }
41 void setId(
int id) { m_id = id; }
42 const std::string& getName()
const {
return m_name; }
43 void setName(
const std::string& name) { m_name = name; }
44 int getIndex()
const {
return m_index; }
45 void setIndex(
int index) { m_index = index; }
46 DBField::NameList& getFieldNames() {
return m_name_v; }
47 const DBField::NameList& getFieldNames()
const {
return m_name_v; }
49 bool hasField(
const std::string& name)
const;
50 bool hasValue(
const std::string& name)
const;
51 bool hasText(
const std::string& name)
const;
52 bool hasObject(
const std::string& name)
const;
54 void setValue(
const std::string& name,
const std::string& value);
55 void setText(
const std::string& name,
const std::string& value) { addText(name, value); }
58 bool getBool(
const std::string& name,
int index = 0)
const;
59 char getChar(
const std::string& name,
int index = 0)
const;
60 short getShort(
const std::string& name,
int index = 0)
const;
61 int getInt(
const std::string& name,
int index = 0)
const;
62 long long getLong(
const std::string& name,
int index = 0)
const;
63 float getFloat(
const std::string& name,
int index = 0)
const;
64 double getDouble(
const std::string& name,
int index = 0)
const;
65 void addBool(
const std::string& name,
bool value);
66 void addChar(
const std::string& name,
char value);
67 void addShort(
const std::string& name,
short value);
68 void addInt(
const std::string& name,
int value);
69 void addLong(
const std::string& name,
long long value);
70 void addFloat(
const std::string& name,
float value);
71 void addDouble(
const std::string& name,
double value);
72 void setBool(
const std::string& name,
bool value,
int index = 0);
73 void setChar(
const std::string& name,
int value,
int index = 0);
74 void setShort(
const std::string& name,
int value,
int index = 0);
75 void setInt(
const std::string& name,
int value,
int index = 0);
76 void setLong(
const std::string& name,
long long value,
int index = 0);
77 void setFloat(
const std::string& name,
float value,
int index = 0);
78 void setDouble(
const std::string& name,
double value,
int index = 0);
79 const std::string getValueText(
const std::string& name)
const;
82 virtual const void* getValue(
const std::string& name)
const = 0;
83 virtual const std::string& getText(
const std::string& name)
const = 0;
84 virtual void addText(
const std::string& name,
const std::string& value) = 0;
85 virtual void addValue(
const std::string& name,
const void* value,
86 DBField::Type type,
int length) = 0;
87 virtual void setValue(
const std::string& name,
const void* value,
int index) = 0;
88 virtual void setValueText(
const std::string& name,
const std::string& value);
98 DBField::NameList m_name_v;
99 DBField::PropertyList m_pro_m;
103 T getD(
const std::string& name,
int index = 0)
const
105 const void* value = getValue(name);
107 throw (std::out_of_range(name +
" not found"));
109 DBField::Type type(getProperty(name).getType());
110 if (type == DBField::INT)
return (T)(((
int*)value)[index]);
111 if (type == DBField::FLOAT)
return (T)(((
float*)value)[index]);
112 if (type == DBField::DOUBLE)
return (T)(((
double*)value)[index]);
113 if (type == DBField::SHORT)
return (T)(((
short*)value)[index]);
114 if (type == DBField::CHAR)
return (T)(((
char*)value)[index]);
115 if (type == DBField::LONG)
return (T)(((
long*)value)[index]);
116 return ((T*)value)[index];
121 inline bool AbstractDBObject::getBool(
const std::string& name,
int index)
const
123 return getD<bool>(name, index);
126 inline char AbstractDBObject::getChar(
const std::string& name,
int index)
const
128 return getD<char>(name, index);
131 inline short AbstractDBObject::getShort(
const std::string& name,
int index)
const
133 return getD<short>(name, index);
136 inline int AbstractDBObject::getInt(
const std::string& name,
int index)
const
138 return getD<int>(name, index);
141 inline long long AbstractDBObject::getLong(
const std::string& name,
int index)
const
143 return getD<long long>(name, index);
146 inline float AbstractDBObject::getFloat(
const std::string& name,
int index)
const
148 return getD<float>(name, index);
151 inline double AbstractDBObject::getDouble(
const std::string& name,
int index)
const
153 return getD<double>(name, index);
156 inline void AbstractDBObject::setBool(
const std::string& name,
bool value,
int index)
158 setValue(name, &value, index);
161 inline void AbstractDBObject::setChar(
const std::string& name,
int value,
int index)
163 setValue(name, &value, index);
166 inline void AbstractDBObject::setShort(
const std::string& name,
int value,
int index)
168 setValue(name, &value, index);
171 inline void AbstractDBObject::setInt(
const std::string& name,
int value,
int index)
173 setValue(name, &value, index);
176 inline void AbstractDBObject::setLong(
const std::string& name,
long long value,
int index)
178 setValue(name, &value, index);
181 inline void AbstractDBObject::setFloat(
const std::string& name,
float value,
int index)
183 setValue(name, &value, index);
186 inline void AbstractDBObject::setDouble(
const std::string& name,
double value,
int index)
188 setValue(name, &value, index);
191 inline void AbstractDBObject::addBool(
const std::string& name,
bool value)
193 addValue(name, &value, DBField::BOOL, 0);
196 inline void AbstractDBObject::addChar(
const std::string& name,
char value)
198 addValue(name, &value, DBField::CHAR, 0);
201 inline void AbstractDBObject::addShort(
const std::string& name,
short value)
203 addValue(name, &value, DBField::SHORT, 0);
206 inline void AbstractDBObject::addInt(
const std::string& name,
int value)
208 addValue(name, &value, DBField::INT, 0);
211 inline void AbstractDBObject::addLong(
const std::string& name,
long long value)
213 addValue(name, &value, DBField::LONG, 0);
216 inline void AbstractDBObject::addFloat(
const std::string& name,
float value)
218 addValue(name, &value, DBField::FLOAT, 0);
221 inline void AbstractDBObject::addDouble(
const std::string& name,
double value)
223 addValue(name, &value, DBField::DOUBLE, 0);
const AbstractDBObject & operator=(const AbstractDBObject &object)
Operator =.
Abstract base class for different kinds of events.