8 #include "daq/slc/base/AbstractDBObject.h"
10 #include <daq/slc/base/StringUtil.h>
17 AbstractDBObject::AbstractDBObject() : m_index(0), m_path(), m_id(0)
23 : m_index(obj.m_index), m_path(obj.m_path),
27 AbstractDBObject::~AbstractDBObject()
32 void AbstractDBObject::reset()
37 m_name_v = DBField::NameList();
38 m_pro_m = DBField::PropertyList();
43 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
44 if (it != m_pro_m.end())
return it->second;
48 bool AbstractDBObject::hasField(
const std::string& name)
const
50 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
51 return (it != m_pro_m.end());
54 bool AbstractDBObject::hasValue(
const std::string& name)
const
56 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
57 return hasField(name) &&
58 it->second.getType() != DBField::TEXT &&
59 it->second.getType() != DBField::OBJECT;
62 bool AbstractDBObject::hasText(
const std::string& name)
const
64 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
65 return hasField(name) && it->second.getType() == DBField::TEXT;
68 bool AbstractDBObject::hasObject(
const std::string& name)
const
70 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
71 return hasField(name) &&
72 it->second.getType() == DBField::OBJECT;
77 if (!hasField(name)) {
78 m_name_v.push_back(name);
79 m_pro_m.insert(DBField::PropertyList::value_type(name, pro));
83 const std::string AbstractDBObject::getValueText(
const std::string& name)
86 const static int double_precision = std::numeric_limits<double>::digits10 + 2;
89 switch (getProperty(name).getType()) {
90 case DBField::BOOL:
return getBool(name) ?
"true" :
"false";
91 case DBField::CHAR:
return StringUtil::form(
"%d", (
int)getChar(name));
92 case DBField::SHORT:
return StringUtil::form(
"%d", (
int)getShort(name));
93 case DBField::INT:
return StringUtil::form(
"%d", (
int)getInt(name));
94 case DBField::LONG:
return StringUtil::form(
"%ld", getLong(name));
95 case DBField::FLOAT:
return StringUtil::form(
"%f", getFloat(name));
96 case DBField::DOUBLE:
return StringUtil::form(
"%.*e", double_precision, getDouble(name));
97 case DBField::TEXT:
return getText(name);
101 throw (std::out_of_range(name +
" not found"));
104 void AbstractDBObject::setValueText(
const std::string& name,
105 const std::string& value)
107 if (hasField(name)) {
108 switch (getProperty(name).getType()) {
109 case DBField::BOOL: setBool(name, value ==
"true" || value ==
"t");
break;
110 case DBField::CHAR: {
111 if (StringUtil::find(value,
"0x"))
112 setChar(name, (
char)strtol(value.c_str(), NULL, 0));
114 setChar(name, (
char)atoi(value.c_str()));
116 case DBField::SHORT: {
117 if (StringUtil::find(value,
"0x"))
118 setShort(name, (
short)strtol(value.c_str(), NULL, 0));
120 setShort(name, (
short)atoi(value.c_str()));
123 if (StringUtil::find(value,
"0x"))
124 setInt(name, (
int)strtol(value.c_str(), NULL, 0));
126 setInt(name, (
int)atoi(value.c_str()));
128 case DBField::LONG: setLong(name, (
long long)atoi(value.c_str()));
break;
129 case DBField::FLOAT: setFloat(name, atof(value.c_str()));
break;
130 case DBField::DOUBLE: setDouble(name, atof(value.c_str()));
break;
131 case DBField::TEXT: setText(name, value);
break;
136 throw (std::out_of_range(name +
" not found"));
Abstract base class for different kinds of events.