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>
16 const std::string MemoryID::delimiter =
"/";
24 std::forward_list<std::string> items;
25 boost::split(items,
string, boost::is_any_of(delimiter));
28 for (
auto it = items.begin(); it != items.end(); ++it)
30 while (it->size() > 0 && it->back() ==
'\\')
33 auto next = simox::alg::advanced(it, 1);
34 if (next != items.end())
37 *it = it->substr(0, it->size() - 1) + delimiter + *next;
38 items.erase_after(it);
43 auto it = items.begin();
44 if (it == items.end())
50 if (++it == items.end())
56 if (++it == items.end())
62 if (++it == items.end())
68 if (++it == items.end())
74 if (++it == items.end())
82 const std::string& coreSegmentName,
83 const std::string& providerSegmentName,
84 const std::string& entityName,
88 coreSegmentName(coreSegmentName),
89 providerSegmentName(providerSegmentName),
90 entityName(entityName),
92 instanceIndex(instanceIndex)
99 return str(delimiter, escapeDelimiters);
103 MemoryID::str(
const std::string& delimiter,
bool escapeDelimiter)
const
105 std::vector<std::string> items =
getAllItems(escapeDelimiter);
106 while (items.size() > 0 && items.back().empty())
110 return simox::alg::join(items, delimiter,
false,
false);
117 for (
auto it = items.rbegin(); it != items.rend(); ++it)
130 bool emptyFound =
false;
164 if (i < items.size())
169 if (i < items.size())
171 id.coreSegmentName = items[i];
174 if (i < items.size())
176 id.providerSegmentName = items[i];
179 if (i < items.size())
181 id.entityName = items[i];
184 if (i < items.size())
189 if (i < items.size())
197 std::vector<std::string>
200 std::vector<std::string> items;
202 items.push_back(escape(
memoryName, escapeDelimiters));
220 items.push_back(escape(
entityName, escapeDelimiters));
237 std::vector<std::string>
434 return int(parseInteger(
string,
"instance index"));
482 MemoryID::parseInteger(
const std::string&
string,
const std::string& semanticName)
490 return std::stoll(
string);
492 catch (
const std::invalid_argument&)
494 throw error::ParseIntegerError(
string, semanticName);
496 catch (
const std::out_of_range&)
498 throw error::ParseIntegerError(
string, semanticName);
503 MemoryID::escapeDelimiter(
const std::string& name)
505 return simox::alg::replace_all(name, delimiter,
"\\" + delimiter);
509 MemoryID::escape(
const std::string& name,
bool escapeDelimiters)
511 if (escapeDelimiters)
513 return escapeDelimiter(name);
524 return os <<
"'" <<
id.str() <<
"'";
532 std::stringstream ss;
533 ss <<
"\nGeneral ID " << general <<
" is not well-defined, which is required for `"
534 << __FUNCTION__ <<
"()`.";
539 std::stringstream ss;
540 ss <<
"\nSpecific ID " << specific <<
" is not well-defined, which is required for `"
541 << __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().