Go to the documentation of this file.
3 #include <forward_list>
5 #include <boost/algorithm/string.hpp>
7 #include <SimoxUtility/algorithm/advanced.h>
8 #include <SimoxUtility/algorithm/string/string_tools.h>
18 const std::string MemoryID::delimiter =
"/";
28 std::forward_list<std::string> items;
29 boost::split(items,
string, boost::is_any_of(delimiter));
32 for (
auto it = items.begin(); it != items.end(); ++it)
34 while (it->size() > 0 && it->back() ==
'\\')
37 auto next = simox::alg::advanced(it, 1);
38 if (next != items.end())
41 *it = it->substr(0, it->size() - 1) + delimiter + *next;
42 items.erase_after(it);
47 auto it = items.begin();
48 if (it == items.end())
54 if (++it == items.end())
60 if (++it == items.end())
66 if (++it == items.end())
72 if (++it == items.end())
78 if (++it == items.end())
87 const std::string& coreSegmentName,
88 const std::string& providerSegmentName,
89 const std::string& entityName,
93 coreSegmentName(coreSegmentName),
94 providerSegmentName(providerSegmentName),
95 entityName(entityName),
97 instanceIndex(instanceIndex)
104 return str(delimiter, escapeDelimiters);
108 MemoryID::str(
const std::string& delimiter,
bool escapeDelimiter)
const
110 std::vector<std::string> items =
getAllItems(escapeDelimiter);
111 while (items.size() > 0 && items.back().empty())
115 return simox::alg::join(items, delimiter,
false,
false);
122 for (
auto it = items.rbegin(); it != items.rend(); ++it)
134 std::vector<std::string> allItems = this->
getAllItems(
true);
135 std::string newID =
"";
136 for(std::size_t i = 0; i < allItems.size(); i++){
137 if(!allItems.at(i).empty()){
138 std::string toAppend = allItems.at(i);
139 if(allItems.at(i).find(delimiter) != std::string::npos){
142 while ((pos = toAppend.find(delimiter)) != std::string::npos) {
143 token = toAppend.substr(0, pos);
144 toAppend.erase(0, pos + delimiter.length());
147 newID.append(toAppend);
148 if(i < allItems.size() - 1 && !allItems.at(i+1).empty()){
149 newID.append(delimiter);
160 bool emptyFound =
false;
194 if (i < items.size())
199 if (i < items.size())
201 id.coreSegmentName = items[i];
204 if (i < items.size())
206 id.providerSegmentName = items[i];
209 if (i < items.size())
211 id.entityName = items[i];
214 if (i < items.size())
219 if (i < items.size())
227 std::vector<std::string>
230 std::vector<std::string> items;
232 items.push_back(escape(
memoryName, escapeDelimiters));
250 items.push_back(escape(
entityName, escapeDelimiters));
267 std::vector<std::string>
464 return int(parseInteger(
string,
"instance index"));
512 MemoryID::parseInteger(
const std::string&
string,
const std::string& semanticName)
520 return std::stoll(
string);
522 catch (
const std::invalid_argument&)
524 throw error::ParseIntegerError(
string, semanticName);
526 catch (
const std::out_of_range&)
528 throw error::ParseIntegerError(
string, semanticName);
533 MemoryID::escapeDelimiter(
const std::string& name)
535 return simox::alg::replace_all(name, delimiter,
"\\" + delimiter);
539 MemoryID::escape(
const std::string& name,
bool escapeDelimiters)
541 if (escapeDelimiters)
543 return escapeDelimiter(name);
554 return os <<
"'" <<
id.str() <<
"'";
562 std::stringstream ss;
563 ss <<
"\nGeneral ID " << general <<
" is not well-defined, which is required for `"
564 << __FUNCTION__ <<
"()`.";
569 std::stringstream ss;
570 ss <<
"\nSpecific ID " << specific <<
" is not well-defined, which is required for `"
571 << __FUNCTION__ <<
"()`.";
bool isWellDefined() const
Indicate whether this ID is well-defined.
void setCoreSegmentID(const MemoryID &id)
MemoryID getEntityInstanceID() const
static Time timestampFromStr(const std::string ×tamp)
Reconstruct a timestamp from a string as returned by timestampStr().
std::string providerSegmentName
MemoryID removeLeafItem() const
MemoryID withMemoryName(const std::string &name) const
std::string str(bool escapeDelimiters=true) const
Get a string representation of this memory ID.
bool contains(const MemoryID &general, const MemoryID &specific)
Indicates whether general is "less specific" than, or equal to, specific, i.e.
bool operator==(const MemoryID &other) const
std::string coreSegmentName
bool empty(const std::string &s)
std::ostream & operator<<(std::ostream &os, const EntityUpdate &rhs)
MemoryID withProviderSegmentName(const std::string &name) const
MemoryID withCoreSegmentName(const std::string &name) const
bool operator<(const MemoryID &rhs) const
MemoryID getEntitySnapshotID() const
void setProviderSegmentID(const MemoryID &id)
static MemoryID fromItems(const std::vector< std::string > &items)
Constructor memory ID from items as returned by getItems().
MemoryID()
Construct a default (empty) memory ID.
bool hasTimestamp() const
void setEntitySnapshotID(const MemoryID &id)
bool hasInstanceIndex() const
MemoryID getProviderSegmentID() const
bool hasGap() const
Indicate whether this ID has a gap such as in 'Memory//MyProvider' (no core segment name).
std::int64_t toMicroSecondsSinceEpoch() const
std::vector< std::string > getAllItems(bool escapeDelimiters=false) const
Get all levels as strings.
armarx::core::time::DateTime Time
const std::string & to_string(const std::string &s)
void setMemoryID(const MemoryID &id)
bool hasEntityName() const
static MemoryID fromString(const std::string &string)
Alias for constructor from string.
Represents a point in time.
MemoryID getCoreSegmentID() const
MemoryID getEntityID() const
Indicates that a memory ID is invalid, e.g.
void setEntityInstanceID(const MemoryID &id)
MemoryID withEntityName(const std::string &name) const
MemoryID getMemoryID() const
const std::string memoryName
bool hasProviderSegmentName() const
bool hasCoreSegmentName() const
MemoryID withTimestamp(Time time) const
std::vector< std::string > getItems(bool escapeDelimiters=false) const
Get the levels from root to first not defined level (excluding).
MemoryID withInstanceIndex(int index) const
void setEntityID(const MemoryID &id)
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
std::string getLeafItem() const
Get the lowest defined level (or empty string if there is none).
std::string instanceIndexStr() const
Get the instance index as string.
std::vector< std::string > split(const std::string &source, const std::string &splitBy, bool trimElements=false, bool removeEmptyElements=false)
std::string timestampStr() const
Get the timestamp as string.
static int instanceIndexFromStr(const std::string &index)
Reconstruct an instance index from a string as returned by instanceIndexStr().