1 #ifndef MHO_IndexLabelInterface_HH__
2 #define MHO_IndexLabelInterface_HH__
55 fIndexLabelObjectPtr->clear();
66 template<
typename XValueType >
69 if(fIndexLabelObjectPtr !=
nullptr)
71 std::string ikey = index2key(index);
72 if(!(fIndexLabelObjectPtr->contains(ikey)))
75 (*fIndexLabelObjectPtr).emplace(ikey, fDummy);
76 (*fIndexLabelObjectPtr)[ikey][
"index"] = index;
81 (*fIndexLabelObjectPtr)[ikey].update(obj);
85 msg_error(
"utilities",
"cannot insert key:value pair, index label interface is missing object!" << eom);
98 template<
typename XValueType >
101 if(fIndexLabelObjectPtr !=
nullptr)
103 std::string ikey = index2key(index);
104 if((*fIndexLabelObjectPtr)[ikey].contains(key))
106 value = (*fIndexLabelObjectPtr)[ikey][key].get< XValueType >();
112 msg_error(
"utilities",
"cannot retrieve key:value pair, index label interface is missing object!" << eom);
125 if(fIndexLabelObjectPtr !=
nullptr)
131 if(!(fIndexLabelObjectPtr->is_object()))
133 (*fIndexLabelObjectPtr) =
mho_json();
135 std::string ikey = index2key(index);
136 if(!(fIndexLabelObjectPtr->contains(ikey)))
140 (*fIndexLabelObjectPtr)[ikey] = fDummy;
141 (*fIndexLabelObjectPtr)[ikey][
"index"] = index;
145 obj[
"index"] = index;
146 (*fIndexLabelObjectPtr)[ikey].update(obj);
150 msg_error(
"utilities",
"cannot insert label object, index label interface is missing object!" << eom);
162 if(fIndexLabelObjectPtr !=
nullptr)
164 std::string ikey = index2key(index);
165 return (*fIndexLabelObjectPtr)[ikey];
169 msg_error(
"utilities",
"cannot retrieve label object, index label interface is missing object!" << eom);
182 if(fIndexLabelObjectPtr !=
nullptr)
184 std::string ikey = index2key(index);
185 return (*fIndexLabelObjectPtr)[ikey];
189 msg_error(
"utilities",
"cannot retrieve label object, index label interface is missing object!" << eom);
202 std::vector< std::size_t > idx;
203 if(fIndexLabelObjectPtr !=
nullptr)
205 for(std::size_t i = 0; i < fIndexLabelObjectPtr->size(); i++)
207 std::string ikey = index2key(i);
208 if((*fIndexLabelObjectPtr)[ikey].contains(key))
216 msg_error(
"utilities",
"cannot determine matching indexes, index label interface is missing object!" << eom);
229 template<
typename XValueType >
232 std::vector< std::size_t > idx;
233 if(fIndexLabelObjectPtr !=
nullptr)
235 for(std::size_t i = 0; i < fIndexLabelObjectPtr->size(); i++)
237 std::string ikey = index2key(i);
238 if((*fIndexLabelObjectPtr)[ikey].contains(key))
240 XValueType v = (*fIndexLabelObjectPtr)[ikey][key].get< XValueType >();
250 msg_error(
"utilities",
"cannot determine matching indexes, index label interface is missing object!" << eom);
263 static std::string index2key(std::size_t idx) {
return std::to_string(idx); }
#define msg_error(xKEY, xCONTENT)
Definition: MHO_Message.hh:238
Class MHO_IndexLabelInterface - adds indexes associated with key:value pairs (used by MHO_Axis) const...
Definition: MHO_IndexLabelInterface.hh:22
std::size_t GetIndexLabelSize() const
Getter for index label size.
Definition: MHO_IndexLabelInterface.hh:47
std::vector< std::size_t > GetMatchingIndexes(std::string &key, const XValueType &value) const
Get a vector of indexes which contain a key with a value which matches the passed value.
Definition: MHO_IndexLabelInterface.hh:230
bool RetrieveIndexLabelKeyValue(std::size_t index, const std::string &key, XValueType &value) const
Retrieves value associated with given key and index from IndexLabelObjectPtr if it exists.
Definition: MHO_IndexLabelInterface.hh:99
mho_json & GetLabelObject(std::size_t index)
get a reference to the dictionary object associated with this index
Definition: MHO_IndexLabelInterface.hh:160
virtual ~MHO_IndexLabelInterface()
Definition: MHO_IndexLabelInterface.hh:40
void SetLabelObject(mho_json &obj, std::size_t index)
get a reference to the dictionary object associated with this index
Definition: MHO_IndexLabelInterface.hh:123
void SetIndexLabelObject(mho_json *obj)
Setter for index label object.
Definition: MHO_IndexLabelInterface.hh:37
void InsertIndexLabelKeyValue(std::size_t index, const std::string &key, const XValueType &value)
Function InsertIndexLabelKeyValue.
Definition: MHO_IndexLabelInterface.hh:67
std::vector< std::size_t > GetMatchingIndexes(std::string &key) const
get a vector of indexes which contain a key with the same name
Definition: MHO_IndexLabelInterface.hh:200
MHO_IndexLabelInterface(const MHO_IndexLabelInterface ©)
Definition: MHO_IndexLabelInterface.hh:30
mho_json GetLabelObject(std::size_t index) const
Getter for label object.
Definition: MHO_IndexLabelInterface.hh:180
void ClearIndexLabels()
Clears all index labels.
Definition: MHO_IndexLabelInterface.hh:52
MHO_IndexLabelInterface()
Definition: MHO_IndexLabelInterface.hh:25
Definition: MHO_AdhocFlagging.hh:18