1 #ifndef _Belle2_AbstractDBObject_hh
2 #define _Belle2_AbstractDBObject_hh
4 #include <daq/slc/base/FieldProperty.h>
6 #include <daq/slc/base/Serializable.h>
26 const std::string& getPath()
const {
return m_path; }
27 void setPath(
const std::string& path) { m_path = path; }
28 int getId()
const {
return m_id; }
29 void setId(
int id) { m_id = id; }
30 const std::string& getName()
const {
return m_name; }
31 void setName(
const std::string& name) { m_name = name; }
32 int getIndex()
const {
return m_index; }
33 void setIndex(
int index) { m_index = index; }
34 DBField::NameList& getFieldNames() {
return m_name_v; }
35 const DBField::NameList& getFieldNames()
const {
return m_name_v; }
37 bool hasField(
const std::string& name)
const;
38 bool hasValue(
const std::string& name)
const;
39 bool hasText(
const std::string& name)
const;
40 bool hasObject(
const std::string& name)
const;
42 void setValue(
const std::string& name,
const std::string& value);
43 void setText(
const std::string& name,
const std::string& value) { addText(name, value); }
46 bool getBool(
const std::string& name,
int index = 0)
const;
47 char getChar(
const std::string& name,
int index = 0)
const;
48 short getShort(
const std::string& name,
int index = 0)
const;
49 int getInt(
const std::string& name,
int index = 0)
const;
50 long long getLong(
const std::string& name,
int index = 0)
const;
51 float getFloat(
const std::string& name,
int index = 0)
const;
52 double getDouble(
const std::string& name,
int index = 0)
const;
53 void addBool(
const std::string& name,
bool value);
54 void addChar(
const std::string& name,
char value);
55 void addShort(
const std::string& name,
short value);
56 void addInt(
const std::string& name,
int value);
57 void addLong(
const std::string& name,
long long value);
58 void addFloat(
const std::string& name,
float value);
59 void addDouble(
const std::string& name,
double value);
60 void setBool(
const std::string& name,
bool value,
int index = 0);
61 void setChar(
const std::string& name,
int value,
int index = 0);
62 void setShort(
const std::string& name,
int value,
int index = 0);
63 void setInt(
const std::string& name,
int value,
int index = 0);
64 void setLong(
const std::string& name,
long long value,
int index = 0);
65 void setFloat(
const std::string& name,
float value,
int index = 0);
66 void setDouble(
const std::string& name,
double value,
int index = 0);
67 const std::string getValueText(
const std::string& name)
const;
70 virtual const void* getValue(
const std::string& name)
const = 0;
71 virtual const std::string& getText(
const std::string& name)
const = 0;
72 virtual void addText(
const std::string& name,
const std::string& value) = 0;
73 virtual void addValue(
const std::string& name,
const void* value,
74 DBField::Type type,
int length) = 0;
75 virtual void setValue(
const std::string& name,
const void* value,
int index) = 0;
76 virtual void setValueText(
const std::string& name,
const std::string& value);
86 DBField::NameList m_name_v;
87 DBField::PropertyList m_pro_m;
91 T getD(
const std::string& name,
int index = 0)
const
93 const void* value = getValue(name);
95 throw (std::out_of_range(name +
" not found"));
97 DBField::Type type(getProperty(name).getType());
98 if (type == DBField::INT)
return (T)(((
int*)value)[index]);
99 if (type == DBField::FLOAT)
return (T)(((
float*)value)[index]);
100 if (type == DBField::DOUBLE)
return (T)(((
double*)value)[index]);
101 if (type == DBField::SHORT)
return (T)(((
short*)value)[index]);
102 if (type == DBField::CHAR)
return (T)(((
char*)value)[index]);
103 if (type == DBField::LONG)
return (T)(((
long*)value)[index]);
104 return ((T*)value)[index];
109 inline bool AbstractDBObject::getBool(
const std::string& name,
int index)
const
111 return getD<bool>(name, index);
114 inline char AbstractDBObject::getChar(
const std::string& name,
int index)
const
116 return getD<char>(name, index);
119 inline short AbstractDBObject::getShort(
const std::string& name,
int index)
const
121 return getD<short>(name, index);
124 inline int AbstractDBObject::getInt(
const std::string& name,
int index)
const
126 return getD<int>(name, index);
129 inline long long AbstractDBObject::getLong(
const std::string& name,
int index)
const
131 return getD<long long>(name, index);
134 inline float AbstractDBObject::getFloat(
const std::string& name,
int index)
const
136 return getD<float>(name, index);
139 inline double AbstractDBObject::getDouble(
const std::string& name,
int index)
const
141 return getD<double>(name, index);
144 inline void AbstractDBObject::setBool(
const std::string& name,
bool value,
int index)
146 setValue(name, &value, index);
149 inline void AbstractDBObject::setChar(
const std::string& name,
int value,
int index)
151 setValue(name, &value, index);
154 inline void AbstractDBObject::setShort(
const std::string& name,
int value,
int index)
156 setValue(name, &value, index);
159 inline void AbstractDBObject::setInt(
const std::string& name,
int value,
int index)
161 setValue(name, &value, index);
164 inline void AbstractDBObject::setLong(
const std::string& name,
long long value,
int index)
166 setValue(name, &value, index);
169 inline void AbstractDBObject::setFloat(
const std::string& name,
float value,
int index)
171 setValue(name, &value, index);
174 inline void AbstractDBObject::setDouble(
const std::string& name,
double value,
int index)
176 setValue(name, &value, index);
179 inline void AbstractDBObject::addBool(
const std::string& name,
bool value)
181 addValue(name, &value, DBField::BOOL, 0);
184 inline void AbstractDBObject::addChar(
const std::string& name,
char value)
186 addValue(name, &value, DBField::CHAR, 0);
189 inline void AbstractDBObject::addShort(
const std::string& name,
short value)
191 addValue(name, &value, DBField::SHORT, 0);
194 inline void AbstractDBObject::addInt(
const std::string& name,
int value)
196 addValue(name, &value, DBField::INT, 0);
199 inline void AbstractDBObject::addLong(
const std::string& name,
long long value)
201 addValue(name, &value, DBField::LONG, 0);
204 inline void AbstractDBObject::addFloat(
const std::string& name,
float value)
206 addValue(name, &value, DBField::FLOAT, 0);
209 inline void AbstractDBObject::addDouble(
const std::string& name,
double value)
211 addValue(name, &value, DBField::DOUBLE, 0);