Go to the documentation of this file.
6 #include <SimoxUtility/algorithm/get_map_keys_values.h>
42 template <
class _EntitySnapshotT,
class _Derived>
99 inline const std::string&
109 return not this->
empty();
296 typename ContainerT::const_iterator greaterEq = this->
_container.lower_bound(time);
308 typename ContainerT::const_iterator less = std::prev(greaterEq);
311 return &less->second;
335 typename ContainerT::const_iterator greaterEq = this->
_container.lower_bound(time);
341 return &greaterEq->second;
359 return snapshot ? snapshot->findInstance(instanceIndex) :
nullptr;
366 return snapshot ? snapshot->findInstance(instanceIndex) :
nullptr;
370 #if 0 // Do not offer this yet.
371 auto* findLatestInstanceData(
int instanceIndex = 0)
374 return instance ? &instance->data() :
nullptr;
376 const auto* findLatestInstanceData(
int instanceIndex = 0)
const
379 return instance ? &instance->data() :
nullptr;
389 template <
class SnapshotFunctionT>
399 template <
class SnapshotFunctionT>
409 template <
class SnapshotFunctionT>
419 template <
class SnapshotFunctionT>
423 if (
id.hasTimestamp())
427 child->forEachChild(func);
441 template <
class FunctionT>
451 if (not
call(func, snapshot))
463 template <
class FunctionT>
476 template <
class FunctionT>
489 if (not
call(func, it->second))
506 template <
class FunctionT>
521 std::advance(it, first_);
523 size_t num = last_ - first_ + 1;
524 for (
size_t i = 0; i < num; ++i, ++it)
526 if (not
call(func, it->second))
537 template <
class InstanceFunctionT>
552 template <
class InstanceFunctionT>
569 return simox::alg::get_keys(this->
_container);
597 snapshot = &it->second;
602 ret.id = snapshot->id();
604 ret.updatedSnapshots = {*snapshot};
609 template <
class OtherDerivedT>
613 other.forEachSnapshot(
614 [
this](
const auto& snapshot)
616 auto it = this->
_container.find(snapshot.time());
619 EntitySnapshotT copy{snapshot};
620 copy.id() = this->id().withTimestamp(
622 this->_container.emplace(snapshot.time(),
copy);
649 return this->addSnapshot(
timestamp, std::move(snapshot));
653 template <
class... Args>
657 auto it = this->_container.emplace_hint(this->_container.end(),
timestamp, args...);
658 it->second.id() = this->id().withTimestamp(
timestamp);
668 if (this->size() != other.size())
672 for (
const auto& [key, snapshot] : this->_container)
674 if (not other.hasSnapshot(key))
678 if (not snapshot.equalsDeep(other.getSnapshot(key)))
689 return this->id().entityName;
bool forEachSnapshot(SnapshotFunctionT &&func) const
bool hasSnapshots() const
Indicate whether the entity has any snapshots.
const EntitySnapshotT & getSnapshot(const Time &time) const
ReaderT::InputType T & ret
bool equalsDeep(const DerivedT &other) const
void forEachSnapshotBeforeOrAt(const Time &time, FunctionT &&func) const
Return all snapshots before or at time.
EntityBase(const std::string &name, const MemoryID &parentID={})
void append(const OtherDerivedT &other)
std::vector< EntitySnapshotT > removedSnapshots
void forEachSnapshotBefore(const Time &time, FunctionT &&func) const
Return all snapshots before (excluding) time.
const EntitySnapshotT * findFirstSnapshotAfterOrAt(const Time &time) const
Return first snapshot after or at time.
EntityBase & operator=(const EntityBase &other)=default
const auto * findLatestInstance(int instanceIndex=0) const
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
Base class of memory classes on different levels.
bool forEachChild(ChildFunctionT &&func)
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
void forEachSnapshotInIndexRange(long first, long last, FunctionT &&func) const
Return all snapshots from first to last index.
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func)
Provides default implmentations of MemoryContainer, as well as iterators (which requires a template).
bool hasSnapshot(const MemoryID &snapshotID) const
Indicate whether a snapshot with the given ID exists.
UpdateResult update(const EntityUpdate &update)
Add the given update to this entity's history.
An entity over a period of time.
const EntitySnapshotT & getSnapshot(const MemoryID &snapshotID) const
EntitySnapshotT & addSnapshot(const Time ×tamp)
Add a snapshot at the given time.
EntitySnapshotT & getSnapshot(const MemoryID &snapshotID)
EntitySnapshotT * findFirstSnapshot()
Return the snapshot with the least recent timestamp.
std::vector< EntitySnapshotT > updatedSnapshots
std::vector< Time > getTimestamps() const
Get all timestamps in the history.
EntitySnapshot EntitySnapshotT
size_t negativeIndexSemantics(long index, size_t size)
const EntitySnapshotT * findFirstSnapshot() const
EntitySnapshotT & getSnapshot(const Time &time)
Get a snapshot.
Use of this software is granted under one of the following two to be chosen freely by the user Boost Software License Version Marcin Kalicinski Permission is hereby free of to any person or organization obtaining a copy of the software and accompanying documentation covered by this and transmit the and to prepare derivative works of the and to permit third parties to whom the Software is furnished to do all subject to the including the above license this restriction and the following must be included in all copies of the in whole or in and all derivative works of the unless such copies or derivative works are solely in the form of machine executable object code generated by a source language processor THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF FITNESS FOR A PARTICULAR TITLE AND NON INFRINGEMENT IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN TORT OR ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE The MIT Marcin Kalicinski Permission is hereby free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to copy
Time getFirstTimestamp() const
Get the oldest timestamp.
UpdateType
The type of an update.
EntitySnapshotT * findLatestSnapshot()
Return the snapshot with the most recent timestamp.
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
const EntitySnapshotT * findSnapshot(const MemoryID &snapshotID) const
armarx::armem::UpdateType entityUpdateType
auto * findChildByKey(const KeyT &key, ContainerT &&container)
Find a child in a container by its key.
ContainerT::const_iterator begin() const
ContainerT::const_iterator end() const
void checkHasTimestamp(const MemoryID &snapshotID)
Throw armem::error::InvalidMemoryID if the given ID has no timestamp.
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func) const
An update of an entity for a specific point in time.
const EntitySnapshotT & getFirstSnapshot() const
EntitySnapshotT & addSnapshot(EntitySnapshotT &&snapshot)
Move and insert a snapshot.
EntitySnapshotT & getFirstSnapshot()
Return the snapshot with the least recent timestamp.
auto & getChildByKey(const KeyT &key, ContainerT &&container, const ParentT &owner, KeyStringFn &&keyStringFn)
Retrieve a child in a container by its key.
auto * findLatestInstance(int instanceIndex=0)
const EntitySnapshotT * findLatestSnapshot() const
std::int64_t toMicroSecondsSinceEpoch() const
const EntitySnapshotT * findFirstSnapshotAfter(const Time &time) const
Return first snapshot after time.
bool forEachInstanceIn(const MemoryID &id, FunctionT &&func, ParentT &parent, bool single, ChildT *child)
typename EntitySnapshotT::EntityInstanceT EntityInstanceT
EntitySnapshotT * findSnapshot(const Time ×tamp)
std::map< Time, _EntitySnapshotT > ContainerT
const EntitySnapshotT * findLatestSnapshotBefore(const Time &time) const
Return the lastest snapshot before time.
Represents a point in time.
Time referencedTime
Time when this entity update was created (e.g.
const EntitySnapshotT * findSnapshot(const Time ×tamp) const
void forEachSnapshotInTimeRange(const Time &min, const Time &max, FunctionT &&func) const
Return all snapshots between, including, min and max.
Indicates that an entity's history was queried, but is empty.
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func) const
bool hasSnapshot(const Time &time) const
Indicate whether a snapshot at the given time exists.
const std::string & name() const
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func)
const EntitySnapshotT * findLatestSnapshotBeforeOrAt(const Time &time) const
Return the latest snapshot before or at time.
Time getLatestTimestamp() const
Get the latest timestamp.
bool call(FunctionT &&func, ChildT &&child)
bool forEachSnapshot(SnapshotFunctionT &&func)
EntitySnapshotT * findSnapshot(const MemoryID &snapshotID)
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
MemoryID entityID
The entity's ID.
EntityBase(const MemoryID &id)
std::string getKeyString() const
static std::string getLevelName()
EntitySnapshotT & addSnapshot(const EntitySnapshotT &snapshot)
Copy and insert a snapshot.
void _checkContainerName(const std::string &gottenName, const std::string &actualName, bool emptyOk=true) const
EntitySnapshotT & addSnapshot(const Time ×tamp, Args... args)
Insert a snapshot in-place.