Go to the documentation of this file.
6 #include <SimoxUtility/algorithm/get_map_keys_values.h>
42 template <
class _EntitySnapshotT,
class _Derived>
98 inline const std::string&
108 return not this->
empty();
295 typename ContainerT::const_iterator greaterEq = this->
_container.lower_bound(time);
307 typename ContainerT::const_iterator less = std::prev(greaterEq);
310 return &less->second;
334 typename ContainerT::const_iterator greaterEq = this->
_container.lower_bound(time);
340 return &greaterEq->second;
358 return snapshot ? snapshot->findInstance(instanceIndex) :
nullptr;
365 return snapshot ? snapshot->findInstance(instanceIndex) :
nullptr;
369 #if 0 // Do not offer this yet.
370 auto* findLatestInstanceData(
int instanceIndex = 0)
373 return instance ? &instance->data() :
nullptr;
375 const auto* findLatestInstanceData(
int instanceIndex = 0)
const
378 return instance ? &instance->data() :
nullptr;
388 template <
class SnapshotFunctionT>
398 template <
class SnapshotFunctionT>
408 template <
class SnapshotFunctionT>
418 template <
class SnapshotFunctionT>
422 if (
id.hasTimestamp())
426 child->forEachChild(func);
440 template <
class FunctionT>
444 for (
const auto& [timestamp, snapshot] : this->
_container)
446 if (timestamp >= time)
450 if (not
call(func, snapshot))
462 template <
class FunctionT>
475 template <
class FunctionT>
488 if (not
call(func, it->second))
505 template <
class FunctionT>
520 std::advance(it, first_);
522 size_t num = last_ - first_ + 1;
523 for (
size_t i = 0; i < num; ++i, ++it)
525 if (not
call(func, it->second))
536 template <
class InstanceFunctionT>
551 template <
class InstanceFunctionT>
568 return simox::alg::get_keys(this->
_container);
596 snapshot = &it->second;
601 ret.id = snapshot->id();
606 template <
class OtherDerivedT>
610 other.forEachSnapshot(
611 [
this](
const auto& snapshot)
613 auto it = this->
_container.find(snapshot.time());
616 EntitySnapshotT copy{snapshot};
617 copy.id() = this->id().withTimestamp(
619 this->_container.emplace(snapshot.time(),
copy);
645 Time timestamp = snapshot.time();
646 return this->addSnapshot(timestamp, std::move(snapshot));
650 template <
class... Args>
654 auto it = this->_container.emplace_hint(this->_container.end(), timestamp, args...);
655 it->second.id() = this->id().withTimestamp(timestamp);
665 if (this->size() != other.size())
669 for (
const auto& [key, snapshot] : this->_container)
671 if (not other.hasSnapshot(key))
675 if (not snapshot.equalsDeep(other.getSnapshot(key)))
686 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< 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.