EntityBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 
6 #include <SimoxUtility/algorithm/get_map_keys_values.h>
7 
10 
13 
14 #include "EntitySnapshotBase.h"
17 #include "detail/lookup_mixins.h"
19 
20 namespace armarx::armem::base
21 {
22 
23  /**
24  * @brief An entity over a period of time.
25  *
26  * An entity should be a physical thing or abstract concept existing
27  * (and potentially evolving) over time.
28  *
29  * Examples are:
30  * - objects (the green box)
31  * - agents (robot, human)
32  * - locations (frige, sink)
33  * - grasp affordances (general, or for a specific object)
34  * - images
35  * - point clouds
36  * - other sensory values
37  *
38  * At each point in time (`EntitySnapshot`), the entity can have a
39  * (potentially variable) number of instances (`EntityInstance`),
40  * each containing a single `AronData` object of a specific `AronType`.
41  */
42  template <class _EntitySnapshotT, class _Derived>
43  class EntityBase :
44  public detail::MemoryContainerBase<std::map<Time, _EntitySnapshotT>, _Derived>,
45  public detail::ForEachEntityInstanceMixin<_Derived>,
46  public detail::GetFindInstanceMixin<_Derived>,
47  public detail::GetLatestInstanceMixin<_Derived>,
48  public detail::GetLatestSnapshotMixin<_Derived>
49  {
51 
52  public:
53  using typename Base::ContainerT;
54  using typename Base::DerivedT;
55 
56  using EntitySnapshotT = _EntitySnapshotT;
57  using EntityInstanceT = typename EntitySnapshotT::EntityInstanceT;
58 
60 
61  struct UpdateResult
62  {
65  std::vector<EntitySnapshotT> removedSnapshots;
66  std::vector<EntitySnapshotT> updatedSnapshots;
67 
68  UpdateResult() = default;
69  };
70 
71  public:
73  {
74  }
75 
76  explicit EntityBase(const std::string& name, const MemoryID& parentID = {}) :
77  EntityBase(parentID.withEntityName(name))
78  {
79  }
80 
81  explicit EntityBase(const MemoryID& id) : Base(id)
82  {
83  }
84 
85  EntityBase(const EntityBase& other) = default;
86  EntityBase(EntityBase&& other) = default;
87  EntityBase& operator=(const EntityBase& other) = default;
88  EntityBase& operator=(EntityBase&& other) = default;
89 
90  // READING
91 
92  // Get key
93  inline std::string&
94  name()
95  {
96  return this->id().entityName;
97  }
98 
99  inline const std::string&
100  name() const
101  {
102  return this->id().entityName;
103  }
104 
105  /// Indicate whether the entity has any snapshots.
106  bool
107  hasSnapshots() const
108  {
109  return not this->empty();
110  }
111 
112  // Has child with key
113  /// Indicate whether a snapshot at the given time exists.
114  bool
115  hasSnapshot(const Time& time) const
116  {
117  return this->findSnapshot(time) != nullptr;
118  }
119 
120  // Has child with MemoryID
121  /// Indicate whether a snapshot with the given ID exists.
122  bool
123  hasSnapshot(const MemoryID& snapshotID) const
124  {
125  return this->findSnapshot(snapshotID) != nullptr;
126  }
127 
128  // Find child via key
131  {
133  }
134 
135  const EntitySnapshotT*
137  {
139  }
140 
141  // Get child via key
142  /**
143  * @brief Get a snapshot.
144  * @param time The time.
145  * @return The snapshot, if it exists.
146  *
147  * @throws `armem::error::MissingEntry` If there is no such entry.
148  */
150  getSnapshot(const Time& time)
151  {
152  return detail::getChildByKey(time,
153  this->_container,
154  *this,
155  [](const Time& time)
156  { return toDateTimeMilliSeconds(time); });
157  }
158 
159  const EntitySnapshotT&
160  getSnapshot(const Time& time) const
161  {
162  return detail::getChildByKey(time,
163  this->_container,
164  *this,
165  [](const Time& time)
166  { return toDateTimeMilliSeconds(time); });
167  }
168 
169  // Find child via MemoryID
171  findSnapshot(const MemoryID& snapshotID)
172  {
173  detail::checkHasTimestamp(snapshotID);
174  return this->findSnapshot(snapshotID.timestamp);
175  }
176 
177  const EntitySnapshotT*
178  findSnapshot(const MemoryID& snapshotID) const
179  {
180  detail::checkHasTimestamp(snapshotID);
181  return this->findSnapshot(snapshotID.timestamp);
182  }
183 
184  // Get child via MemoryID
186  getSnapshot(const MemoryID& snapshotID)
187  {
188  detail::checkHasTimestamp(snapshotID);
189  return this->getSnapshot(snapshotID.timestamp);
190  }
191 
192  const EntitySnapshotT&
193  getSnapshot(const MemoryID& snapshotID) const
194  {
195  detail::checkHasTimestamp(snapshotID);
196  return this->getSnapshot(snapshotID.timestamp);
197  }
198 
199  // get/findInstance are provided by GetFindInstanceMixin
200 
201 
202  // More getter/finder for snapshots
203 
204  /**
205  * @brief Get the latest timestamp.
206  * @throw `armem::error::EntityHistoryEmpty` If the history is empty.
207  */
208  Time
210  {
211  return this->getLatestSnapshot().time();
212  }
213 
214  /**
215  * @brief Get the oldest timestamp.
216  * @throw `armem::error::EntityHistoryEmpty` If the history is empty.
217  */
218  Time
220  {
221  return this->getFirstSnapshot().time();
222  }
223 
224  /**
225  * @brief Return the snapshot with the most recent timestamp.
226  * @return The latest snapshot or nullptr if the entity is empty.
227  */
230  {
231  return this->empty() ? nullptr : &this->_container.rbegin()->second;
232  }
233 
234  const EntitySnapshotT*
236  {
237  return this->empty() ? nullptr : &this->_container.rbegin()->second;
238  }
239 
240  /**
241  * @brief Return the snapshot with the least recent timestamp.
242  * @return The first snapshot or nullptr if the entity is empty.
243  */
246  {
247  return this->empty() ? nullptr : &this->_container.begin()->second;
248  }
249 
250  const EntitySnapshotT*
252  {
253  return this->empty() ? nullptr : &this->_container.begin()->second;
254  }
255 
256  /**
257  * @brief Return the snapshot with the least recent timestamp.
258  * @return The first snapshot.
259  * @throw `armem::error::EntityHistoryEmpty` If the history is empty.
260  */
263  {
264  return const_cast<EntitySnapshotT&>(
265  const_cast<const EntityBase*>(this)->getFirstSnapshot());
266  }
267 
268  const EntitySnapshotT&
270  {
271  if (const EntitySnapshotT* snapshot = this->findFirstSnapshot())
272  {
273  return *snapshot;
274  }
275  else
276  {
277  throw armem::error::EntityHistoryEmpty(name(), "when getting the first snapshot.");
278  }
279  }
280 
281  /**
282  * @brief Return the lastest snapshot before time.
283  * @param time The time.
284  * @return The latest snapshot < time or nullptr if none was found.
285  */
286  const EntitySnapshotT*
287  findLatestSnapshotBefore(const Time& time) const
288  {
289  if (this->empty())
290  {
291  return nullptr;
292  }
293 
294  // We want the rightmost element < time
295  // lower_bound() gives us the the leftmost >= time, which is probably the right neighbour
296  typename ContainerT::const_iterator greaterEq = this->_container.lower_bound(time);
297  // Special cases:
298  // refIt = begin() => no element < time
299  if (greaterEq == this->_container.begin())
300  {
301  return nullptr;
302  }
303 
304  // end(): No element >= time, we can still have one < time (rbegin()) => std::prev(end())
305  // empty has been checked above
306 
307  // std::prev of end() is ok
308  typename ContainerT::const_iterator less = std::prev(greaterEq);
309 
310  // we return the element before if possible
311  return &less->second;
312  }
313 
314  /**
315  * @brief Return the latest snapshot before or at time.
316  * @param time The time.
317  * @return The latest snapshot <= time or nullptr if none was found.
318  */
319  const EntitySnapshotT*
321  {
323  }
324 
325  /**
326  * @brief Return first snapshot after or at time.
327  * @param time The time.
328  * @return The first snapshot >= time or nullptr if none was found.
329  */
330  const EntitySnapshotT*
331  findFirstSnapshotAfterOrAt(const Time& time) const
332  {
333  // We want the leftmost element >= time.
334  // That's lower bound.
335  typename ContainerT::const_iterator greaterEq = this->_container.lower_bound(time);
336 
337  if (greaterEq == this->_container.end())
338  {
339  return nullptr;
340  }
341  return &greaterEq->second;
342  }
343 
344  /**
345  * @brief Return first snapshot after time.
346  * @param time The time.
347  * @return The first snapshot >= time or nullptr if none was found.
348  */
349  const EntitySnapshotT*
350  findFirstSnapshotAfter(const Time& time) const
351  {
353  }
354 
355  auto*
356  findLatestInstance(int instanceIndex = 0)
357  {
358  auto* snapshot = this->findLatestSnapshot();
359  return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
360  }
361 
362  const auto*
363  findLatestInstance(int instanceIndex = 0) const
364  {
365  auto* snapshot = this->findLatestSnapshot();
366  return snapshot ? snapshot->findInstance(instanceIndex) : nullptr;
367  }
368 
369 
370 #if 0 // Do not offer this yet.
371  auto* findLatestInstanceData(int instanceIndex = 0)
372  {
373  auto* instance = this->findLatestInstance(instanceIndex);
374  return instance ? &instance->data() : nullptr;
375  }
376  const auto* findLatestInstanceData(int instanceIndex = 0) const
377  {
378  auto* instance = this->findLatestInstance(instanceIndex);
379  return instance ? &instance->data() : nullptr;
380  }
381 #endif
382 
383 
384  // ITERATION
385 
386  /**
387  * @param func Function like: bool process(EntitySnapshotT& snapshot)
388  */
389  template <class SnapshotFunctionT>
390  bool
391  forEachSnapshot(SnapshotFunctionT&& func)
392  {
393  return this->forEachChild(func);
394  }
395 
396  /**
397  * @param func Function like void process(const EntitySnapshotT& snapshot)
398  */
399  template <class SnapshotFunctionT>
400  bool
401  forEachSnapshot(SnapshotFunctionT&& func) const
402  {
403  return this->forEachChild(func);
404  }
405 
406  /**
407  * @param func Function like: bool process(EntitySnapshotT& snapshot)
408  */
409  template <class SnapshotFunctionT>
410  bool
411  forEachSnapshotIn(const MemoryID& id, SnapshotFunctionT&& func)
412  {
413  return this->forEachChild(func);
414  }
415 
416  /**
417  * @param func Function like void process(const EntitySnapshotT& snapshot)
418  */
419  template <class SnapshotFunctionT>
420  bool
421  forEachSnapshotIn(const MemoryID& id, SnapshotFunctionT&& func) const
422  {
423  if (id.hasTimestamp())
424  {
425  if (const auto* child = findSnapshot(id.timestamp))
426  {
427  child->forEachChild(func);
428  }
429  }
430  return this->forEachChild(func);
431  }
432 
433  // forEachInstance() is provided by ForEachEntityInstanceMixin.
434 
435 
436  /**
437  * @brief Return all snapshots before (excluding) time.
438  * @param time The time.
439  * @return The latest snapshots.
440  */
441  template <class FunctionT>
442  void
443  forEachSnapshotBefore(const Time& time, FunctionT&& func) const
444  {
445  for (const auto& [timestamp, snapshot] : this->_container)
446  {
447  if (timestamp >= time)
448  {
449  break;
450  }
451  if (not call(func, snapshot))
452  {
453  break;
454  }
455  }
456  }
457 
458  /**
459  * @brief Return all snapshots before or at time.
460  * @param time The time.
461  * @return The latest snapshots.
462  */
463  template <class FunctionT>
464  void
465  forEachSnapshotBeforeOrAt(const Time& time, FunctionT&& func) const
466  {
467  getSnapshotsBefore(time + Duration::MicroSeconds(1), func);
468  }
469 
470  /**
471  * @brief Return all snapshots between, including, min and max.
472  * @param min The lowest time to include.
473  * @param min The highest time to include.
474  * @return The snapshots in [min, max].
475  */
476  template <class FunctionT>
477  void
478  forEachSnapshotInTimeRange(const Time& min, const Time& max, FunctionT&& func) const
479  {
480  // Returns an iterator pointing to the first element that is not less than (i.e. greater or equal to) key.
481  auto begin = min.toMicroSecondsSinceEpoch() > 0 ? this->_container.lower_bound(min)
482  : this->_container.begin();
483  // Returns an iterator pointing to the first element that is *greater than* key.
484  auto end = max.toMicroSecondsSinceEpoch() > 0 ? this->_container.upper_bound(max)
485  : this->_container.end();
486 
487  for (auto it = begin; it != end && it != this->_container.end(); ++it)
488  {
489  if (not call(func, it->second))
490  {
491  break;
492  }
493  }
494  }
495 
496  /**
497  * @brief Return all snapshots from first to last index.
498  *
499  * Negative index are counted from the end, e.g.
500  * last == -1 results in getting all queries until the end.
501  *
502  * @param first The first index to include.
503  * @param first The last index to include.
504  * @return The snapshots in [first, last].
505  */
506  template <class FunctionT>
507  void
508  forEachSnapshotInIndexRange(long first, long last, FunctionT&& func) const
509  {
510  if (this->empty())
511  {
512  return;
513  }
514 
515  const size_t first_ = detail::negativeIndexSemantics(first, this->size());
516  const size_t last_ = detail::negativeIndexSemantics(last, this->size());
517 
518  if (first_ <= last_)
519  {
520  auto it = this->_container.begin();
521  std::advance(it, first_);
522 
523  size_t num = last_ - first_ + 1; // +1 to make last inclusive
524  for (size_t i = 0; i < num; ++i, ++it)
525  {
526  if (not call(func, it->second))
527  {
528  break;
529  }
530  }
531  }
532  }
533 
534  /**
535  * @param func Function like void process(EntityInstanceT& instance)>
536  */
537  template <class InstanceFunctionT>
538  bool
539  forEachInstanceIn(const MemoryID& id, InstanceFunctionT&& func)
540  {
541  return detail::forEachInstanceIn(id,
542  func,
543  *this,
544  id.hasTimestamp(),
545  id.hasTimestamp() ? this->findSnapshot(id.timestamp)
546  : nullptr);
547  }
548 
549  /**
550  * @param func Function like void process(EntityInstanceT& instance)>
551  */
552  template <class InstanceFunctionT>
553  bool
554  forEachInstanceIn(const MemoryID& id, InstanceFunctionT&& func) const
555  {
556  return detail::forEachInstanceIn(id,
557  func,
558  *this,
559  id.hasTimestamp(),
560  id.hasTimestamp() ? this->findSnapshot(id.timestamp)
561  : nullptr);
562  }
563 
564  // Get child keys
565  /// @brief Get all timestamps in the history.
566  std::vector<Time>
568  {
569  return simox::alg::get_keys(this->_container);
570  }
571 
572  // MODIFICATION
573 
574  /**
575  * @brief Add the given update to this entity's history.
576  * @param update The update.
577  * @return The snapshot ID of the update.
578  */
579  UpdateResult
581  {
582  this->_checkContainerName(update.entityID.entityName, this->name());
583  UpdateResult ret;
584 
585  EntitySnapshotT* snapshot;
586 
587  auto it = this->_container.find(update.referencedTime);
588  if (it == this->_container.end())
589  {
590  // Insert into history.
591  snapshot = &addSnapshot(update.referencedTime);
592  // ret.removedSnapshots = this->truncate();
593  ret.entityUpdateType = UpdateType::InsertedNew;
594  }
595  else
596  {
597  snapshot = &it->second;
598  ret.entityUpdateType = UpdateType::UpdatedExisting;
599  }
600  // Update entry.
601  snapshot->update(update);
602  ret.id = snapshot->id();
603 
604  ret.updatedSnapshots = {*snapshot};
605 
606  return ret;
607  }
608 
609  template <class OtherDerivedT>
610  void
611  append(const OtherDerivedT& other)
612  {
613  other.forEachSnapshot(
614  [this](const auto& snapshot)
615  {
616  auto it = this->_container.find(snapshot.time());
617  if (it == this->_container.end())
618  {
619  EntitySnapshotT copy{snapshot};
620  copy.id() = this->id().withTimestamp(
621  snapshot.time()); // update id (e.g. memory name) if necessary
622  this->_container.emplace(snapshot.time(), copy);
623  }
624  // else: snapshot already exists
625  // We assume that a snapshot does not change, so ignore
626  return true;
627  });
628  }
629 
630  /// Add a snapshot at the given time.
631  EntitySnapshotT&
633  {
634  return this->addSnapshot(timestamp, EntitySnapshotT(timestamp));
635  }
636 
637  /// Copy and insert a snapshot
638  EntitySnapshotT&
639  addSnapshot(const EntitySnapshotT& snapshot)
640  {
641  return this->addSnapshot(snapshot.time(), EntitySnapshotT(snapshot));
642  }
643 
644  /// Move and insert a snapshot
645  EntitySnapshotT&
647  {
648  Time timestamp = snapshot.time(); // Copy before move.
649  return this->addSnapshot(timestamp, std::move(snapshot));
650  }
651 
652  /// Insert a snapshot in-place.
653  template <class... Args>
654  EntitySnapshotT&
655  addSnapshot(const Time& timestamp, Args... args)
656  {
657  auto it = this->_container.emplace_hint(this->_container.end(), timestamp, args...);
658  it->second.id() = this->id().withTimestamp(timestamp);
659  return it->second;
660  }
661 
662  // MISC
663 
664  bool
665  equalsDeep(const DerivedT& other) const
666  {
667  //std::cout << "Entity::equalsDeep" << std::endl;
668  if (this->size() != other.size())
669  {
670  return false;
671  }
672  for (const auto& [key, snapshot] : this->_container)
673  {
674  if (not other.hasSnapshot(key))
675  {
676  return false;
677  }
678  if (not snapshot.equalsDeep(other.getSnapshot(key)))
679  {
680  return false;
681  }
682  }
683  return true;
684  }
685 
686  std::string
687  getKeyString() const
688  {
689  return this->id().entityName;
690  }
691 
692  static std::string
694  {
695  return "entity";
696  }
697  };
698 
699 } // namespace armarx::armem::base
armarx::armem::base::detail::GetFindInstanceMixin
Definition: lookup_mixins.h:81
armarx::armem::base
Definition: CoreSegmentBase.h:15
EntitySnapshotBase.h
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::empty
bool empty() const
Definition: MemoryContainerBase.h:41
armarx::armem::MemoryID::timestamp
Time timestamp
Definition: MemoryID.h:54
armarx::armem::base::EntityBase::forEachSnapshot
bool forEachSnapshot(SnapshotFunctionT &&func) const
Definition: EntityBase.h:401
armarx::armem::base::EntityBase::hasSnapshots
bool hasSnapshots() const
Indicate whether the entity has any snapshots.
Definition: EntityBase.h:107
armarx::armem::base::EntityBase::getSnapshot
const EntitySnapshotT & getSnapshot(const Time &time) const
Definition: EntityBase.h:160
armarx::aron::ret
ReaderT::InputType T & ret
Definition: rw.h:13
armarx::armem::base::EntityBase::equalsDeep
bool equalsDeep(const DerivedT &other) const
Definition: EntityBase.h:665
MemoryContainerBase.h
armarx::armem::base::EntityBase::forEachSnapshotBeforeOrAt
void forEachSnapshotBeforeOrAt(const Time &time, FunctionT &&func) const
Return all snapshots before or at time.
Definition: EntityBase.h:465
armarx::armem::base::EntityBase::EntityBase
EntityBase(const std::string &name, const MemoryID &parentID={})
Definition: EntityBase.h:76
armarx::armem::base::EntityBase::append
void append(const OtherDerivedT &other)
Definition: EntityBase.h:611
armarx::armem::base::EntityBase::UpdateResult::removedSnapshots
std::vector< EntitySnapshotT > removedSnapshots
Definition: EntityBase.h:65
armarx::armem::base::EntityBase::forEachSnapshotBefore
void forEachSnapshotBefore(const Time &time, FunctionT &&func) const
Return all snapshots before (excluding) time.
Definition: EntityBase.h:443
armarx::armem::base::EntityBase::findFirstSnapshotAfterOrAt
const EntitySnapshotT * findFirstSnapshotAfterOrAt(const Time &time) const
Return first snapshot after or at time.
Definition: EntityBase.h:331
armarx::armem::base::EntityBase::operator=
EntityBase & operator=(const EntityBase &other)=default
armarx::armem::base::EntityBase::findLatestInstance
const auto * findLatestInstance(int instanceIndex=0) const
Definition: EntityBase.h:363
armarx::armem::base::detail::GetLatestSnapshotMixin< _Derived >::getLatestSnapshot
auto & getLatestSnapshot(int snapshotIndex=0)
Retrieve the latest entity snapshot.
Definition: lookup_mixins.h:199
armarx::armem::base::detail::MemoryItem
Base class of memory classes on different levels.
Definition: MemoryItem.h:13
MemoryID.h
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::forEachChild
bool forEachChild(ChildFunctionT &&func)
Definition: MemoryContainerBase.h:65
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:297
armarx::armem::base::EntityBase::forEachSnapshotInIndexRange
void forEachSnapshotInIndexRange(long first, long last, FunctionT &&func) const
Return all snapshots from first to last index.
Definition: EntityBase.h:508
armarx::armem::base::EntityBase::forEachSnapshotIn
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func)
Definition: EntityBase.h:411
armarx::armem::base::detail::MemoryContainerBase
Provides default implmentations of MemoryContainer, as well as iterators (which requires a template).
Definition: MemoryContainerBase.h:15
armarx::armem::base::EntityBase::hasSnapshot
bool hasSnapshot(const MemoryID &snapshotID) const
Indicate whether a snapshot with the given ID exists.
Definition: EntityBase.h:123
armarx::armem::base::EntityBase::UpdateResult
Definition: EntityBase.h:61
armarx::armem::base::EntityBase::update
UpdateResult update(const EntityUpdate &update)
Add the given update to this entity's history.
Definition: EntityBase.h:580
armarx::armem::base::EntityBase
An entity over a period of time.
Definition: EntityBase.h:43
lookup_mixins.h
armarx::armem::base::EntityBase::getSnapshot
const EntitySnapshotT & getSnapshot(const MemoryID &snapshotID) const
Definition: EntityBase.h:193
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(const Time &timestamp)
Add a snapshot at the given time.
Definition: EntityBase.h:632
armarx::armem::UpdateType::UpdatedExisting
@ UpdatedExisting
armarx::armem::base::EntityBase::getSnapshot
EntitySnapshotT & getSnapshot(const MemoryID &snapshotID)
Definition: EntityBase.h:186
armarx::armem::base::EntityBase::findFirstSnapshot
EntitySnapshotT * findFirstSnapshot()
Return the snapshot with the least recent timestamp.
Definition: EntityBase.h:245
armarx::armem::base::EntityBase::EntityBase
EntityBase()
Definition: EntityBase.h:72
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::size
std::size_t size() const
Definition: MemoryContainerBase.h:47
armarx::armem::base::EntityBase::UpdateResult::updatedSnapshots
std::vector< EntitySnapshotT > updatedSnapshots
Definition: EntityBase.h:66
armarx::armem::base::EntityBase::getTimestamps
std::vector< Time > getTimestamps() const
Get all timestamps in the history.
Definition: EntityBase.h:567
armarx::armem::base::EntityBase::UpdateResult::UpdateResult
UpdateResult()=default
armarx::armem::base::EntityBase< EntitySnapshot, Entity >::EntitySnapshotT
EntitySnapshot EntitySnapshotT
Definition: EntityBase.h:56
armarx::armem::base::detail::negativeIndexSemantics
size_t negativeIndexSemantics(long index, size_t size)
Definition: negative_index_semantics.cpp:6
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::base::EntityBase::findFirstSnapshot
const EntitySnapshotT * findFirstSnapshot() const
Definition: EntityBase.h:251
armarx::armem::base::EntityBase::getSnapshot
EntitySnapshotT & getSnapshot(const Time &time)
Get a snapshot.
Definition: EntityBase.h:150
copy
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
Definition: license.txt:39
armarx::armem::base::EntityBase::getFirstTimestamp
Time getFirstTimestamp() const
Get the oldest timestamp.
Definition: EntityBase.h:219
armarx::armem::UpdateType
UpdateType
The type of an update.
Definition: Commit.h:16
armarx::armem::base::EntityBase::findLatestSnapshot
EntitySnapshotT * findLatestSnapshot()
Return the snapshot with the most recent timestamp.
Definition: EntityBase.h:229
if
if(!yyvaluep)
Definition: Grammar.cpp:645
armarx::armem::toDateTimeMilliSeconds
std::string toDateTimeMilliSeconds(const Time &time, int decimals=6)
Returns timeas e.g.
Definition: Time.cpp:35
armarx::armem::base::EntityBase::findSnapshot
const EntitySnapshotT * findSnapshot(const MemoryID &snapshotID) const
Definition: EntityBase.h:178
armarx::armem::base::EntityBase::UpdateResult::entityUpdateType
armarx::armem::UpdateType entityUpdateType
Definition: EntityBase.h:63
armarx::armem::base::detail::findChildByKey
auto * findChildByKey(const KeyT &key, ContainerT &&container)
Find a child in a container by its key.
Definition: lookup_mixins.h:32
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::begin
ContainerT::const_iterator begin() const
Definition: MemoryContainerBase.h:82
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::end
ContainerT::const_iterator end() const
Definition: MemoryContainerBase.h:96
armarx::armem::base::detail::checkHasTimestamp
void checkHasTimestamp(const MemoryID &snapshotID)
Throw armem::error::InvalidMemoryID if the given ID has no timestamp.
Definition: lookup_mixins.cpp:18
armarx::armem::base::EntityBase::forEachSnapshotIn
bool forEachSnapshotIn(const MemoryID &id, SnapshotFunctionT &&func) const
Definition: EntityBase.h:421
armarx::armem::base::EntityBase< EntitySnapshot, Entity >::ChildT
EntitySnapshotT ChildT
Definition: EntityBase.h:59
armarx::armem::EntityUpdate
An update of an entity for a specific point in time.
Definition: Commit.h:25
armarx::armem::base::EntityBase::getFirstSnapshot
const EntitySnapshotT & getFirstSnapshot() const
Definition: EntityBase.h:269
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(EntitySnapshotT &&snapshot)
Move and insert a snapshot.
Definition: EntityBase.h:646
iteration_mixins.h
timestamp
std::string timestamp()
Definition: CartographerAdapter.cpp:85
armarx::armem::base::EntityBase::getFirstSnapshot
EntitySnapshotT & getFirstSnapshot()
Return the snapshot with the least recent timestamp.
Definition: EntityBase.h:262
armarx::armem::base::detail::getChildByKey
auto & getChildByKey(const KeyT &key, ContainerT &&container, const ParentT &owner, KeyStringFn &&keyStringFn)
Retrieve a child in a container by its key.
Definition: lookup_mixins.h:49
armarx::armem::base::EntityBase::findLatestInstance
auto * findLatestInstance(int instanceIndex=0)
Definition: EntityBase.h:356
armarx::armem::base::detail::GetLatestSnapshotMixin
Definition: lookup_mixins.h:188
armarx::armem::base::EntityBase::findLatestSnapshot
const EntitySnapshotT * findLatestSnapshot() const
Definition: EntityBase.h:235
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::DerivedT
_Derived DerivedT
Definition: MemoryContainerBase.h:20
armarx::core::time::DateTime::toMicroSecondsSinceEpoch
std::int64_t toMicroSecondsSinceEpoch() const
Definition: DateTime.cpp:87
armarx::armem::base::detail::MemoryItem::id
MemoryID & id()
Definition: MemoryItem.h:25
negative_index_semantics.h
armarx::armem::base::EntityBase::findFirstSnapshotAfter
const EntitySnapshotT * findFirstSnapshotAfter(const Time &time) const
Return first snapshot after time.
Definition: EntityBase.h:350
armarx::armem::base::detail::forEachInstanceIn
bool forEachInstanceIn(const MemoryID &id, FunctionT &&func, ParentT &parent, bool single, ChildT *child)
Definition: iteration_mixins.h:117
armarx::armem::base::EntityBase< EntitySnapshot, Entity >::EntityInstanceT
typename EntitySnapshotT::EntityInstanceT EntityInstanceT
Definition: EntityBase.h:57
armarx::armem::MemoryID::entityName
std::string entityName
Definition: MemoryID.h:53
armarx::armem::base::EntityBase::findSnapshot
EntitySnapshotT * findSnapshot(const Time &timestamp)
Definition: EntityBase.h:130
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::ContainerT
std::map< Time, _EntitySnapshotT > ContainerT
Definition: MemoryContainerBase.h:21
armarx::armem::base::EntityBase::UpdateResult::id
MemoryID id
Definition: EntityBase.h:64
armarx::armem::base::EntityBase::findLatestSnapshotBefore
const EntitySnapshotT * findLatestSnapshotBefore(const Time &time) const
Return the lastest snapshot before time.
Definition: EntityBase.h:287
ExpressionException.h
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::EntityUpdate::referencedTime
Time referencedTime
Time when this entity update was created (e.g.
Definition: Commit.h:37
armarx::armem::base::EntityBase::findSnapshot
const EntitySnapshotT * findSnapshot(const Time &timestamp) const
Definition: EntityBase.h:136
armarx::armem::base::EntityBase::forEachSnapshotInTimeRange
void forEachSnapshotInTimeRange(const Time &min, const Time &max, FunctionT &&func) const
Return all snapshots between, including, min and max.
Definition: EntityBase.h:478
armarx::armem::error::EntityHistoryEmpty
Indicates that an entity's history was queried, but is empty.
Definition: ArMemError.h:162
armarx::armem::base::EntityBase::forEachInstanceIn
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func) const
Definition: EntityBase.h:554
armarx::armem::base::detail::ForEachEntityInstanceMixin
Definition: iteration_mixins.h:138
armarx::armem::UpdateType::InsertedNew
@ InsertedNew
armarx::armem::base::EntityBase::hasSnapshot
bool hasSnapshot(const Time &time) const
Indicate whether a snapshot at the given time exists.
Definition: EntityBase.h:115
armarx::armem::base::EntityBase::name
const std::string & name() const
Definition: EntityBase.h:100
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:327
armarx::armem::base::EntityBase::forEachInstanceIn
bool forEachInstanceIn(const MemoryID &id, InstanceFunctionT &&func)
Definition: EntityBase.h:539
Time.h
armarx::armem::base::EntityBase::findLatestSnapshotBeforeOrAt
const EntitySnapshotT * findLatestSnapshotBeforeOrAt(const Time &time) const
Return the latest snapshot before or at time.
Definition: EntityBase.h:320
armarx::armem::base::EntityBase::getLatestTimestamp
Time getLatestTimestamp() const
Get the latest timestamp.
Definition: EntityBase.h:209
armarx::armem::base::detail::call
bool call(FunctionT &&func, ChildT &&child)
Definition: iteration_mixins.h:40
armarx::armem::base::EntityBase::forEachSnapshot
bool forEachSnapshot(SnapshotFunctionT &&func)
Definition: EntityBase.h:391
Logging.h
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::_container
ContainerT _container
Definition: MemoryContainerBase.h:164
armarx::armem::base::EntityBase::findSnapshot
EntitySnapshotT * findSnapshot(const MemoryID &snapshotID)
Definition: EntityBase.h:171
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:24
armarx::armem::EntityUpdate::entityID
MemoryID entityID
The entity's ID.
Definition: Commit.h:28
armarx::armem::base::EntityBase::EntityBase
EntityBase(const MemoryID &id)
Definition: EntityBase.h:81
armarx::armem::base::EntityBase::getKeyString
std::string getKeyString() const
Definition: EntityBase.h:687
armarx::armem::base::EntityBase::getLevelName
static std::string getLevelName()
Definition: EntityBase.h:693
armarx::armem::base::detail::GetLatestInstanceMixin
Definition: lookup_mixins.h:152
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(const EntitySnapshotT &snapshot)
Copy and insert a snapshot.
Definition: EntityBase.h:639
armarx::armem::base::detail::MemoryContainerBase< std::map< Time, _EntitySnapshotT >, _Derived >::_checkContainerName
void _checkContainerName(const std::string &gottenName, const std::string &actualName, bool emptyOk=true) const
Definition: MemoryContainerBase.h:138
armarx::armem::base::EntityBase::name
std::string & name()
Definition: EntityBase.h:94
armarx::armem::base::EntityBase::addSnapshot
EntitySnapshotT & addSnapshot(const Time &timestamp, Args... args)
Insert a snapshot in-place.
Definition: EntityBase.h:655