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