1 #include "otsdaq/TableCore/TableGroupKey.h"
3 #include "otsdaq/Macros/CoutMacros.h"
10 const unsigned int TableGroupKey::INVALID = -1;
11 const unsigned int TableGroupKey::DEFAULT = 0;
14 TableGroupKey::TableGroupKey(
unsigned int key) : key_(key) {}
18 TableGroupKey::TableGroupKey(
char*
const& groupString)
22 key_ = TableGroupKey::INVALID;
28 int i = strlen(groupString) - 1;
30 if((groupString[i] <
'0' || groupString[i] >
'9') && groupString[i] !=
'-' &&
31 groupString[i] !=
'_' && groupString[i] !=
'.')
34 if(i == (
int)strlen(groupString) - 1)
36 key_ = TableGroupKey::DEFAULT;
45 sscanf(&groupString[i],
"%u", &key_);
49 TableGroupKey::TableGroupKey(
const std::string& groupString)
55 TableGroupKey::~TableGroupKey(
void) {}
58 unsigned int TableGroupKey::key(
void)
const {
return key_; }
65 return (key_ == key.key_);
114 return (
isInvalid()) ? std::to_string((
int)key_) : std::to_string(key_);
126 bool TableGroupKey::operator!=(
unsigned int key)
const {
return (key_ != key); }
127 bool TableGroupKey::operator!=(
const TableGroupKey& key)
const
129 return (key_ != key.key_);
136 return (key_ < key.key_);
143 return (key_ > key.key_);
163 unsigned int TableGroupKey::getDefaultKey(
void) {
return DEFAULT; }
166 unsigned int TableGroupKey::getInvalidKey(
void) {
return INVALID; }
176 const std::string& preKey ,
177 const std::string& postKey )
179 if(groupName.size() == 0)
182 << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group Name "
183 "was not provided.\n");
184 __COUT_ERR__ << ss.str();
187 else if(groupName.size() == 1)
189 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! The Group "
190 "Name is too short: \"" +
193 __COUT_ERR__ << ss.str();
198 for(
unsigned int i = 0; i < groupName.size(); ++i)
201 (groupName[i] >=
'A' && groupName[i] <=
'Z') ||
202 (groupName[i] >=
'a' && groupName[i] <=
'z') ||
203 (groupName[i] >=
'0' && groupName[i] <=
'9')))
205 __SS__ << (
"TableGroupKey::getFullGroupString() Illegal Group Name! "
206 "Group Name must be alpha-numeric: \"" +
209 __COUT_ERR__ << ss.str();
215 return groupName + preKey + std::to_string(key.key_) + postKey;
221 std::string& groupName,
224 auto i = fullGroupString.rfind(
"_v");
225 groupName = fullGroupString.substr(0, i);
std::string toString(void) const
toString
static TableGroupKey getNextKey(const TableGroupKey &key=TableGroupKey())
bool operator>(const TableGroupKey &key) const
operator>
bool operator==(unsigned int key) const
operator==
TableGroupKey & operator=(const unsigned int key)
Operators.
static void getGroupNameAndKey(const std::string &fullGroupString, std::string &groupName, TableGroupKey &key)
requires fullGroupString created as name + "_v" + key + ""
bool isInvalid(void) const
isInvalid
TableGroupKey & operator/=(const TableGroupKey a)
to support StringMacros on TableGroupKey types
TableGroupKey & operator-=(const TableGroupKey a)
to support StringMacros on TableGroupKey types
TableGroupKey & operator+=(const TableGroupKey a)
to support StringMacros on TableGroupKey types
TableGroupKey & operator*=(const unsigned int a)
to support StringMacros on TableGroupKey types
static std::string getFullGroupString(const std::string &groupName, const TableGroupKey &key, const std::string &preKey="_v", const std::string &postKey="")
bool operator<(const TableGroupKey &key) const
operator<