1 #ifndef MHO_IntervalLabelInterface_HH__
2 #define MHO_IntervalLabelInterface_HH__
28 fDummy[
"lower_index"] = -1;
29 fDummy[
"upper_index"] = -1;
35 fDummy[
"lower_index"] = -1;
36 fDummy[
"upper_index"] = -1;
37 fIntervalLabelObjectPtr = copy.fIntervalLabelObjectPtr;
64 template<
typename XValueType >
66 const XValueType&
value)
68 std::string ikey =
ConstructKey(lower_index, upper_index);
69 (*fIntervalLabelObjectPtr)[ikey][key] =
value;
70 (*fIntervalLabelObjectPtr)[ikey][
"lower_index"] = lower_index;
71 (*fIntervalLabelObjectPtr)[ikey][
"upper_index"] = upper_index;
84 template<
typename XValueType >
86 const XValueType&
value)
const
88 std::string ikey =
ConstructKey(lower_index, upper_index);
89 if(fIntervalLabelObjectPtr->contains(ikey))
91 if((*fIntervalLabelObjectPtr)[ikey].contains(key))
93 value = (*fIntervalLabelObjectPtr)[ikey][key].get< XValueType >();
99 msg_warn(
"containers",
"cannot retrieve a key value pair for interval: " << ikey <<
"." << eom);
113 std::string ikey =
ConstructKey(lower_index, upper_index);
114 if(fIntervalLabelObjectPtr->contains(ikey))
116 return (*fIntervalLabelObjectPtr)[ikey];
120 msg_warn(
"containers",
"cannot retrieve interval data for: " << ikey <<
"." << eom);
134 std::string ikey =
ConstructKey(lower_index, upper_index);
135 obj[
"lower_index"] =
std::min(lower_index, upper_index);
136 obj[
"upper_index"] =
std::max(lower_index, upper_index);
137 (*fIntervalLabelObjectPtr)[ikey] = obj;
149 std::vector< mho_json > objects;
150 for(
auto it : fIntervalLabelObjectPtr->items())
152 if(it.value().contains(key))
154 objects.push_back(it.value());
168 template<
typename XLabelValueType >
172 for(
auto it : fIntervalLabelObjectPtr->items())
174 if(it.value().contains(key))
196 static std::string
ConstructKey(std::size_t lower_index, std::size_t upper_index)
198 if(lower_index <= upper_index)
200 return std::to_string(lower_index) +
"," + std::to_string(upper_index);
205 return std::to_string(upper_index) +
"," + std::to_string(lower_index);
221 if(key.find(
',') == std::string::npos)
226 lower_index = idx_pair.first;
227 upper_index = idx_pair.second;
228 if(upper_index < lower_index)
230 lower_index = idx_pair.second;
231 upper_index = idx_pair.first;
245 std::size_t lower_index = 0;
246 std::size_t upper_index = 0;
247 size_t pos = key.find(
',');
248 if(pos == std::string::npos)
250 return std::make_pair(lower_index, upper_index);
252 std::string first = key.substr(0, pos);
253 std::string second = key.substr(pos + 1);
254 lower_index = std::stoul(first);
255 upper_index = std::stoul(second);
256 if(upper_index < lower_index)
259 std::make_pair(upper_index, lower_index);
261 return std::make_pair(lower_index, upper_index);
#define msg_warn(xKEY, xCONTENT)
Definition: MHO_Message.hh:254
Class MHO_IntervalLabelInterface - adds intervals with associated key:value pairs (used by MHO_Axis) ...
Definition: MHO_IntervalLabelInterface.hh:23
void ClearIntervalLabels()
Clears interval labels by setting *fIntervalLabelObjectPtr to an empty json object.
Definition: MHO_IntervalLabelInterface.hh:53
void SetIntervalLabelObject(mho_json &obj, std::size_t lower_index, std::size_t upper_index)
Setter for interval label object.
Definition: MHO_IntervalLabelInterface.hh:132
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:147
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:85
void SetIntervalLabelObject(mho_json *obj)
Setter for interval label object.
Definition: MHO_IntervalLabelInterface.hh:45
MHO_IntervalLabelInterface(const MHO_IntervalLabelInterface ©)
Definition: MHO_IntervalLabelInterface.hh:32
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:243
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:196
mho_json GetFirstIntervalWithKeyValue(std::string key, const XLabelValueType &value) const
Getter for first interval with key value.
Definition: MHO_IntervalLabelInterface.hh:169
virtual ~MHO_IntervalLabelInterface()
Definition: MHO_IntervalLabelInterface.hh:48
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:111
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:217
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:65
MHO_IntervalLabelInterface()
Definition: MHO_IntervalLabelInterface.hh:25
#define min(a, b)
Definition: max555.c:9
#define max(a, b)
Definition: max555.c:10
Definition: MHO_ChannelLabeler.hh:17