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();
265 const_cast<const EntityBase*
>(
this)->getFirstSnapshot());
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;
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>
487 if (not call(func, it->second))
504 template <
class FunctionT>
517 template <
class FunctionT>
530 if (not call(func, it->second))
547 template <
class FunctionT>
562 std::advance(it, first_);
564 size_t num = last_ - first_ + 1;
565 for (
size_t i = 0; i < num; ++i, ++it)
567 if (not call(func, it->second))
578 template <
class InstanceFunctionT>
593 template <
class InstanceFunctionT>
610 return simox::alg::get_keys(this->
_container);
638 snapshot = &it->second;
643 ret.
id = snapshot->id();
650 template <
class OtherDerivedT>
654 other.forEachSnapshot(
655 [
this](
const auto& snapshot)
657 auto it = this->
_container.find(snapshot.time());
663 this->
_container.emplace(snapshot.time(), copy);
690 return this->
addSnapshot(timestamp, std::move(snapshot));
694 template <
class... Args>
709 if (this->
size() != other.size())
713 for (
const auto& [key, snapshot] : this->
_container)
715 if (not other.hasSnapshot(key))
719 if (not snapshot.equalsDeep(other.getSnapshot(key)))
MemoryID withTimestamp(Time time) const
An entity over a period of time.
std::vector< Time > getTimestamps() const
Get all timestamps in the history.
bool hasSnapshots() const
Indicate whether the entity has any snapshots.
void forEachSnapshotInTimeRange(const Time &min, const Time &max, FunctionT &&func) const
Return all snapshots between, including, min and max.
EntityBase(EntityBase &&other)=default
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func)
void forEachSnapshotInIndexRange(long first, long last, FunctionT &&func) const
Return all snapshots from first to last index.
EntityBase & operator=(const EntityBase &other)=default
const std::string & name() const
const EntitySnapshotT * findSnapshot(const Time ×tamp) const
EntitySnapshotT & getSnapshot(const MemoryID &snapshotID)
const EntitySnapshotT & getSnapshot(const MemoryID &snapshotID) const
EntitySnapshotT & getFirstSnapshot()
Return the snapshot with the least recent timestamp.
EntitySnapshotT & addSnapshot(const Time ×tamp)
Add a snapshot at the given time.
bool equalsDeep(const DerivedT &other) const
EntitySnapshotT & addSnapshot(const EntitySnapshotT &snapshot)
Copy and insert a snapshot.
bool forEachSnapshot(SnapshotFunctionT &&func)
EntitySnapshotT & addSnapshot(const Time ×tamp, Args... args)
Insert a snapshot in-place.
bool hasSnapshot(const MemoryID &snapshotID) const
Indicate whether a snapshot with the given ID exists.
const EntitySnapshotT & getSnapshot(const Time &time) const
EntitySnapshotT * findLatestSnapshot()
Return the snapshot with the most recent timestamp.
Time getFirstTimestamp() const
Get the oldest timestamp.
bool forEachSnapshot(SnapshotFunctionT &&func) const
EntityBase(const MemoryID &id)
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func) const
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func) const
Time getLatestTimestamp() const
Get the latest timestamp.
const EntitySnapshotT * findFirstSnapshotAfter(const Time &time) const
Return first snapshot after time.
const auto * findLatestInstance(int instanceIndex=0) const
static std::string getLevelName()
void forEachSnapshotBeforeOrAt(const Time &time, FunctionT &&func) const
Return all snapshots before or at time.
void append(const OtherDerivedT &other)
const EntitySnapshotT * findFirstSnapshotAfterOrAt(const Time &time) const
Return first snapshot after or at time.
EntitySnapshotT & getSnapshot(const Time &time)
Get a snapshot.
typename EntitySnapshotT::EntityInstanceT EntityInstanceT
EntitySnapshotT * findSnapshot(const MemoryID &snapshotID)
const EntitySnapshotT * findFirstSnapshot() const
const EntitySnapshotT * findSnapshot(const MemoryID &snapshotID) const
EntityBase(const EntityBase &other)=default
const EntitySnapshotT * findLatestSnapshotBeforeOrAt(const Time &time) const
Return the latest snapshot before or at time.
EntityBase & operator=(EntityBase &&other)=default
EntitySnapshotT * findFirstSnapshot()
Return the snapshot with the least recent timestamp.
bool hasSnapshot(const Time &time) const
Indicate whether a snapshot at the given time exists.
EntitySnapshotT * findSnapshot(const Time ×tamp)
_EntitySnapshotT EntitySnapshotT
void forEachSnapshotBefore(const Time &time, FunctionT &&func) const
Return all snapshots before (excluding) time.
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func)
void forEachSnapshotBeforeReverse(const Time &time, FunctionT &&func) const
Iterate over all snapshots before (excluding) time in reverse order (newest first).
std::string getKeyString() const
EntityBase(const std::string &name, const MemoryID &parentID={})
EntitySnapshotT & addSnapshot(EntitySnapshotT &&snapshot)
Move and insert a snapshot.
const EntitySnapshotT & getFirstSnapshot() const
const EntitySnapshotT * findLatestSnapshot() const
UpdateResult update(const EntityUpdate &update)
Add the given update to this entity's history.
const EntitySnapshotT * findLatestSnapshotBefore(const Time &time) const
Return the lastest snapshot before time.
auto * findLatestInstance(int instanceIndex=0)
Provides default implmentations of MemoryContainer, as well as iterators (which requires a template).
bool forEachChild(ChildFunctionT &&func)
std::map< Time, _EntitySnapshotT > ContainerT
ContainerT::const_iterator end() const
ContainerT::const_iterator begin() const
void _checkContainerName(const std::string &gottenName, const std::string &actualName, bool emptyOk=true) const
Indicates that an entity's history was queried, but is empty.
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
auto & getChildByKey(const KeyT &key, ContainerT &&container, const ParentT &owner, KeyStringFn &&keyStringFn)
Retrieve a child in a container by its key.
size_t negativeIndexSemantics(long index, size_t size)
bool forEachInstanceIn(const MemoryID &id, FunctionT &&func, ParentT &parent, bool single, ChildT *child)
void checkHasTimestamp(const MemoryID &snapshotID)
Throw armem::error::InvalidMemoryID if the given ID has no timestamp.
auto * findChildByKey(const KeyT &key, ContainerT &&container)
Find a child in a container by its key.
UpdateType
The type of an update.
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
armarx::core::time::DateTime Time
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
An update of an entity for a specific point in time.
MemoryID entityID
The entity's ID.
std::vector< EntitySnapshotT > updatedSnapshots
armarx::armem::UpdateType entityUpdateType
std::vector< EntitySnapshotT > removedSnapshots
auto & getLatestSnapshot(int snapshotIndex=0)