8#include "daq/slc/base/AbstractDBObject.h"
10#include <daq/slc/base/StringUtil.h>
17AbstractDBObject::AbstractDBObject() : m_index(0), m_path(), m_id(0)
23 : m_index(obj.m_index), m_path(obj.m_path),
27AbstractDBObject::~AbstractDBObject()
35 Serializable::operator=(
object);
36 m_index =
object.m_index;
37 m_path =
object.m_path;
39 m_name =
object.m_name;
40 m_name_v =
object.m_name_v;
41 m_pro_m =
object.m_pro_m;
45void AbstractDBObject::reset()
50 m_name_v = DBField::NameList();
51 m_pro_m = DBField::PropertyList();
56 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
57 if (it != m_pro_m.end())
return it->second;
61bool AbstractDBObject::hasField(
const std::string& name)
const
63 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
64 return (it != m_pro_m.end());
67bool AbstractDBObject::hasValue(
const std::string& name)
const
69 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
70 return hasField(name) &&
71 it->second.getType() != DBField::TEXT &&
72 it->second.getType() != DBField::OBJECT;
75bool AbstractDBObject::hasText(
const std::string& name)
const
77 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
78 return hasField(name) && it->second.getType() == DBField::TEXT;
81bool AbstractDBObject::hasObject(
const std::string& name)
const
83 DBField::PropertyList::const_iterator it = m_pro_m.find(name);
84 return hasField(name) &&
85 it->second.getType() == DBField::OBJECT;
90 if (!hasField(name)) {
91 m_name_v.push_back(name);
92 m_pro_m.insert(DBField::PropertyList::value_type(name, pro));
96const std::string AbstractDBObject::getValueText(
const std::string& name)
99 const static int double_precision = std::numeric_limits<double>::digits10 + 2;
101 if (hasField(name)) {
102 switch (getProperty(name).getType()) {
103 case DBField::BOOL:
return getBool(name) ?
"true" :
"false";
104 case DBField::CHAR:
return StringUtil::form(
"%d", (
int)getChar(name));
105 case DBField::SHORT:
return StringUtil::form(
"%d", (
int)getShort(name));
106 case DBField::INT:
return StringUtil::form(
"%d", (
int)getInt(name));
107 case DBField::LONG:
return StringUtil::form(
"%ld", getLong(name));
108 case DBField::FLOAT:
return StringUtil::form(
"%f", getFloat(name));
109 case DBField::DOUBLE:
return StringUtil::form(
"%.*e", double_precision, getDouble(name));
110 case DBField::TEXT:
return getText(name);
114 throw (std::out_of_range(name +
" not found"));
117void AbstractDBObject::setValueText(
const std::string& name,
118 const std::string& value)
120 if (hasField(name)) {
121 switch (getProperty(name).getType()) {
122 case DBField::BOOL: setBool(name, value ==
"true" || value ==
"t");
break;
123 case DBField::CHAR: {
124 if (StringUtil::find(value,
"0x"))
125 setChar(name, (
char)strtol(value.c_str(), NULL, 0));
127 setChar(name, (
char)atoi(value.c_str()));
129 case DBField::SHORT: {
130 if (StringUtil::find(value,
"0x"))
131 setShort(name, (
short)strtol(value.c_str(), NULL, 0));
133 setShort(name, (
short)atoi(value.c_str()));
136 if (StringUtil::find(value,
"0x"))
137 setInt(name, (
int)strtol(value.c_str(), NULL, 0));
139 setInt(name, (
int)atoi(value.c_str()));
141 case DBField::LONG: setLong(name, (
long long)atoi(value.c_str()));
break;
142 case DBField::FLOAT: setFloat(name, atof(value.c_str()));
break;
143 case DBField::DOUBLE: setDouble(name, atof(value.c_str()));
break;
144 case DBField::TEXT: setText(name, value);
break;
149 throw (std::out_of_range(name +
" not found"));
const AbstractDBObject & operator=(const AbstractDBObject &object)
Operator =.
Abstract base class for different kinds of events.