1 #ifndef MHO_IntervalLabelInterface_HH__
2 #define MHO_IntervalLabelInterface_HH__
27 fDummy[
"lower_index"] = -1;
28 fDummy[
"upper_index"] = -1;
34 fDummy[
"lower_index"] = -1;
35 fDummy[
"upper_index"] = -1;
36 fIntervalLabelObjectPtr = copy.fIntervalLabelObjectPtr;
63 template<
typename XValueType >
65 const XValueType&
value)
67 std::string ikey =
ConstructKey(lower_index, upper_index);
68 (*fIntervalLabelObjectPtr)[ikey][key] =
value;
69 (*fIntervalLabelObjectPtr)[ikey][
"lower_index"] = lower_index;
70 (*fIntervalLabelObjectPtr)[ikey][
"upper_index"] = upper_index;
83 template<
typename XValueType >
85 const XValueType&
value)
const
87 std::string ikey =
ConstructKey(lower_index, upper_index);
88 if(fIntervalLabelObjectPtr->contains(ikey))
90 if((*fIntervalLabelObjectPtr)[ikey].contains(key))
92 value = (*fIntervalLabelObjectPtr)[ikey][key].get< XValueType >();
98 msg_warn(
"containers",
"cannot retrieve a key value pair for interval: " << ikey <<
"." << eom);
112 std::string ikey =
ConstructKey(lower_index, upper_index);
113 if(fIntervalLabelObjectPtr->contains(ikey))
115 return (*fIntervalLabelObjectPtr)[ikey];
119 msg_warn(
"containers",
"cannot retrieve interval data for: " << ikey <<
"." << eom);
133 std::string ikey =
ConstructKey(lower_index, upper_index);
134 obj[
"lower_index"] =
std::min(lower_index, upper_index);
135 obj[
"upper_index"] =
std::max(lower_index, upper_index);
136 (*fIntervalLabelObjectPtr)[ikey] = obj;
148 std::vector< mho_json > objects;
149 for(
auto it : fIntervalLabelObjectPtr->items())
151 if(it.value().contains(key))
153 objects.push_back(it.value());
167 template<
typename XLabelValueType >
171 for(
auto it : fIntervalLabelObjectPtr->items())
173 if(it.value().contains(key))
195 static std::string
ConstructKey(std::size_t lower_index, std::size_t upper_index)
197 if(lower_index <= upper_index)
199 return std::to_string(lower_index) +
"," + std::to_string(upper_index);
204 return std::to_string(upper_index) +
"," + std::to_string(lower_index);
220 if(key.find(
',') == std::string::npos)
225 lower_index = idx_pair.first;
226 upper_index = idx_pair.second;
227 if(upper_index < lower_index)
229 lower_index = idx_pair.second;
230 upper_index = idx_pair.first;
244 std::size_t lower_index = 0;
245 std::size_t upper_index = 0;
246 size_t pos = key.find(
',');
247 if(pos == std::string::npos)
249 return std::make_pair(lower_index, upper_index);
251 std::string first = key.substr(0, pos);
252 std::string second = key.substr(pos + 1);
253 lower_index = std::stoul(first);
254 upper_index = std::stoul(second);
255 if(upper_index < lower_index)
258 std::make_pair(upper_index, lower_index);
260 return std::make_pair(lower_index, upper_index);
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:248
Class MHO_IntervalLabelInterface - adds intervals with associated key:value pairs (used by MHO_Axis) ...
Definition: MHO_IntervalLabelInterface.hh:22
void ClearIntervalLabels()
Clears interval labels by setting *fIntervalLabelObjectPtr to an empty json object.
Definition: MHO_IntervalLabelInterface.hh:52
void SetIntervalLabelObject(mho_json &obj, std::size_t lower_index, std::size_t upper_index)
Setter for interval label object.
Definition: MHO_IntervalLabelInterface.hh:131
std::vector< mho_json > GetMatchingIntervalLabels(std::string key) const
get a vector of interval labels which contain a key with the same name
Definition: MHO_IntervalLabelInterface.hh:146
bool RetrieveIntervalLabelKeyValue(std::size_t lower_index, std::size_t upper_index, const std::string &key, const XValueType &value) const
Retrieves a value associated with a key within an interval range.
Definition: MHO_IntervalLabelInterface.hh:84
void SetIntervalLabelObject(mho_json *obj)
Setter for interval label object.
Definition: MHO_IntervalLabelInterface.hh:44
MHO_IntervalLabelInterface(const MHO_IntervalLabelInterface ©)
Definition: MHO_IntervalLabelInterface.hh:31
static std::pair< std::size_t, std::size_t > ExtractIndexesFromKey(const std::string &key)
Extracts lower and upper indexes from a key string separated by comma.
Definition: MHO_IntervalLabelInterface.hh:242
static std::string ConstructKey(std::size_t lower_index, std::size_t upper_index)
Constructs a key string from lower and upper indices, ensuring lower_index <= upper_index.
Definition: MHO_IntervalLabelInterface.hh:195
mho_json GetFirstIntervalWithKeyValue(std::string key, const XLabelValueType &value) const
Getter for first interval with key value.
Definition: MHO_IntervalLabelInterface.hh:168
virtual ~MHO_IntervalLabelInterface()
Definition: MHO_IntervalLabelInterface.hh:47
mho_json & GetIntervalLabelObject(std::size_t lower_index, std::size_t upper_index)
Get a reference to the dictionary object associated with this index.
Definition: MHO_IntervalLabelInterface.hh:110
bool ExtractIndexesFromKey(const std::string &key, std::size_t &lower_index, std::size_t &upper_index)
Extracts lower and upper indexes from a key string separated by comma.
Definition: MHO_IntervalLabelInterface.hh:216
void InsertIntervalLabelKeyValue(std::size_t lower_index, std::size_t upper_index, const std::string &key, const XValueType &value)
Inserts an interval label key-value pair into a map referenced by fIntervalLabelObjectPtr.
Definition: MHO_IntervalLabelInterface.hh:64
MHO_IntervalLabelInterface()
Definition: MHO_IntervalLabelInterface.hh:24
#define min(a, b)
Definition: max555.c:9
#define max(a, b)
Definition: max555.c:10
Definition: MHO_AdhocFlagging.hh:18