1 #include "daq/slc/database/DBRecord.h"
3 #include "daq/slc/base/StringUtil.h"
9 const std::string DBRecord::get(
const std::string& name)
const
11 if (m_value_m.find(name) != m_value_m.end())
return m_value_m[name];
15 const std::string DBRecord::get(
int i)
const
17 if (i >= 0 && i < (
int)m_name_v.size())
18 return m_value_m[m_name_v[i]];
22 unsigned long long int DBRecord::getULLInt(
const std::string& name)
const
24 return std::strtoull(get(name).c_str(), NULL, 10);
27 int DBRecord::getInt(
const std::string& name)
const
29 return atoi(get(name).c_str());
32 int DBRecord::getInt(
int i)
const
34 return atoi(get(i).c_str());
37 bool DBRecord::getBool(
const std::string& name)
const
39 return get(name) ==
"t";
42 bool DBRecord::getBool(
int i)
const
47 float DBRecord::getFloat(
const std::string& name)
const
49 return atof(get(name).c_str());
52 float DBRecord::getFloat(
int i)
const
54 return atof(get(i).c_str());
57 std::vector<std::string> DBRecord::getArray(
const std::string& name)
const
59 std::string value = StringUtil::replace(StringUtil::replace(get(name),
"}",
""),
"{",
"");
60 return StringUtil::split(value,
',');
63 std::vector<std::string> DBRecord::getArray(
int i)
const
65 std::string value = StringUtil::replace(StringUtil::replace(get(i),
"}",
""),
"{",
"");
66 return StringUtil::split(value,
',');
69 std::vector<int> DBRecord::getIntArray(
const std::string& name)
const
71 std::vector<int> value_i_v;
72 std::vector<std::string> value_v = getArray(name);
73 for (
size_t i = 0; i < value_v.size(); i++) {
74 value_i_v.push_back(atoi(value_v[i].c_str()));
79 std::vector<int> DBRecord::getIntArray(
int i)
const
81 std::vector<int> value_i_v;
82 std::vector<std::string> value_v = getArray(i);
83 for (
size_t i = 0; i < value_v.size(); i++) {
84 value_i_v.push_back(atoi(value_v[i].c_str()));
89 std::vector<float> DBRecord::getFloatArray(
const std::string& name)
const
91 std::vector<float> value_i_v;
92 std::vector<std::string> value_v = getArray(name);
93 for (
size_t i = 0; i < value_v.size(); i++) {
94 value_i_v.push_back(atof(value_v[i].c_str()));
99 std::vector<float> DBRecord::getFloatArray(
int i)
const
101 std::vector<float> value_i_v;
102 std::vector<std::string> value_v = getArray(i);
103 for (
size_t i = 0; i < value_v.size(); i++) {
104 value_i_v.push_back(atof(value_v[i].c_str()));
109 void DBRecord::add(std::string name, std::string value)
111 m_name_v.push_back(name);
112 m_value_m.insert(DBFieldList::value_type(name, value));
115 const std::string DBRecord::getFieldName(
int i)
const
117 if (i >= 0 && i < (
int) m_name_v.size())
return m_name_v[i];