EntityBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 // BaseClass
9 
10 #include "EntitySnapshotBase.h"
11 #include "MemoryItem.h"
12 
14 {
15  /// @brief Interface functions for the longterm memory classes
16  template <class _EntitySnapshotT>
17  class EntityBase : public MemoryItem
18  {
19  public:
20  struct Statistics
21  {
23  };
24 
25  public:
26  using EntitySnapshotT = _EntitySnapshotT;
27 
29 
30  /// return the full sub-ltm as a wm::Entity with only references
31  /// the ltm may be huge, use with caution
32  void
34  {
36  }
37 
38  void
40  {
42  }
43 
44  /// convert the references of the input into a wm::Memory
45  void
47  {
48  _resolve(e);
49  }
50 
51  /// encode the content of a wm::Memory and store
52  void
54  {
55  _store(e);
56  }
57 
58  /// statistics
59  void
61  {
63  }
64 
65  Statistics
66  getStatistics() const
67  {
68  return statistics;
69  }
70 
71  /// iterate over all entity snapshots of this ltm
72  virtual bool forEachSnapshot(std::function<void(EntitySnapshotT&)> func) const = 0;
73  virtual bool
74  forEachSnapshotInIndexRange(long first,
75  long last,
76  std::function<void(EntitySnapshotT&)> func) const = 0;
77  virtual bool
79  const Time& max,
80  std::function<void(EntitySnapshotT&)> func) const = 0;
81  virtual bool
82  forEachSnapshotBeforeOrAt(const Time& time,
83  std::function<void(EntitySnapshotT&)> func) const = 0;
84  virtual bool forEachSnapshotBefore(const Time& time,
85  std::function<void(EntitySnapshotT&)> func) const = 0;
86 
87  /// check if snapshot segment exists
88  virtual bool hasSnapshot(const Time&) const = 0;
89 
90  /// find entity snapshot segment
91  virtual std::shared_ptr<EntitySnapshotT> findSnapshot(const Time&) const = 0;
92  virtual std::shared_ptr<EntitySnapshotT> findLatestSnapshot() const = 0;
93  virtual std::shared_ptr<EntitySnapshotT>
94  findLatestSnapshotBefore(const Time& time) const = 0;
95  virtual std::shared_ptr<EntitySnapshotT>
96  findLatestSnapshotBeforeOrAt(const Time& time) const = 0;
97  virtual std::shared_ptr<EntitySnapshotT> findFirstSnapshotAfter(const Time& time) const = 0;
98  virtual std::shared_ptr<EntitySnapshotT>
99  findFirstSnapshotAfterOrAt(const Time& time) const = 0;
100 
101  static std::string
103  {
104  return "LT-Entity";
105  }
106 
107  protected:
108  virtual void _loadAllReferences(armem::wm::Entity&) = 0;
109  virtual void _loadLatestNReferences(int n, armem::wm::Entity& e) = 0;
110  virtual void _resolve(armem::wm::Entity&) = 0;
111  virtual void _store(const armem::wm::Entity&) = 0;
112 
113  protected:
114  mutable std::recursive_mutex ltm_mutex;
115 
116  Statistics statistics;
117  };
118 } // namespace armarx::armem::server::ltm::detail
armarx::armem::server::ltm::detail::EntityBase::forEachSnapshotInIndexRange
virtual bool forEachSnapshotInIndexRange(long first, long last, std::function< void(EntitySnapshotT &)> func) const =0
armarx::armem::server::ltm::detail
Definition: CoreSegmentBase.cpp:3
armarx::armem::server::ltm::detail::EntityBase::getLevelName
static std::string getLevelName()
Definition: EntityBase.h:102
armarx::armem::server::ltm::detail::EntityBase::resolve
void resolve(armem::wm::Entity &e)
convert the references of the input into a wm::Memory
Definition: EntityBase.h:46
armarx::armem::server::ltm::detail::EntityBase::EntitySnapshotT
_EntitySnapshotT EntitySnapshotT
Definition: EntityBase.h:26
armarx::armem::server::ltm::detail::EntityBase::_store
virtual void _store(const armem::wm::Entity &)=0
armarx::armem::server::ltm::detail::EntityBase::findSnapshot
virtual std::shared_ptr< EntitySnapshotT > findSnapshot(const Time &) const =0
find entity snapshot segment
MemoryID.h
armarx::armem::server::ltm::detail::EntityBase::resetStatistics
void resetStatistics()
statistics
Definition: EntityBase.h:60
armarx::armem::server::ltm::detail::EntityBase::loadLatestNReferences
void loadLatestNReferences(int n, armem::wm::Entity &e)
Definition: EntityBase.h:39
armarx::max
std::vector< T > max(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:267
armarx::armem::server::ltm::detail::EntityBase::findFirstSnapshotAfter
virtual std::shared_ptr< EntitySnapshotT > findFirstSnapshotAfter(const Time &time) const =0
armarx::armem::server::ltm::detail::MemoryItem::MemoryItem
MemoryItem(const std::string &exportName, const MemoryID &)
Definition: MemoryItem.cpp:10
aron_conversions.h
armarx::armem::server::ltm::detail::EntityBase::getStatistics
Statistics getStatistics() const
Definition: EntityBase.h:66
armarx::armem::server::ltm::detail::EntityBase::findLatestSnapshotBefore
virtual std::shared_ptr< EntitySnapshotT > findLatestSnapshotBefore(const Time &time) const =0
EntitySnapshotBase.h
armarx::armem::server::ltm::detail::EntityBase::_loadAllReferences
virtual void _loadAllReferences(armem::wm::Entity &)=0
armarx::armem::server::ltm::detail::EntityBase::Statistics
Definition: EntityBase.h:20
armarx::armem::server::ltm::detail::EntityBase::hasSnapshot
virtual bool hasSnapshot(const Time &) const =0
check if snapshot segment exists
armarx::armem::server::ltm::detail::EntityBase::_loadLatestNReferences
virtual void _loadLatestNReferences(int n, armem::wm::Entity &e)=0
armarx::armem::server::ltm::detail::EntityBase::store
void store(const armem::wm::Entity &e)
encode the content of a wm::Memory and store
Definition: EntityBase.h:53
armarx::armem::server::ltm::detail::EntityBase::findFirstSnapshotAfterOrAt
virtual std::shared_ptr< EntitySnapshotT > findFirstSnapshotAfterOrAt(const Time &time) const =0
armarx::armem::server::ltm::detail::EntityBase::forEachSnapshotBeforeOrAt
virtual bool forEachSnapshotBeforeOrAt(const Time &time, std::function< void(EntitySnapshotT &)> func) const =0
armarx::armem::server::ltm::detail::EntityBase::findLatestSnapshot
virtual std::shared_ptr< EntitySnapshotT > findLatestSnapshot() const =0
armarx::armem::server::ltm::detail::EntityBase::ltm_mutex
std::recursive_mutex ltm_mutex
Definition: EntityBase.h:114
armarx::armem::server::ltm::detail::EntityBase::forEachSnapshotBefore
virtual bool forEachSnapshotBefore(const Time &time, std::function< void(EntitySnapshotT &)> func) const =0
armarx::armem::server::ltm::detail::EntityBase::Statistics::recordedSnapshots
long recordedSnapshots
Definition: EntityBase.h:22
armarx::armem::server::ltm::detail::EntityBase::loadAllReferences
void loadAllReferences(armem::wm::Entity &e)
return the full sub-ltm as a wm::Entity with only references the ltm may be huge, use with caution
Definition: EntityBase.h:33
armarx::armem::server::ltm::detail::EntityBase::findLatestSnapshotBeforeOrAt
virtual std::shared_ptr< EntitySnapshotT > findLatestSnapshotBeforeOrAt(const Time &time) const =0
memory_definitions.h
armarx::armem::server::ltm::detail::EntityBase::forEachSnapshot
virtual bool forEachSnapshot(std::function< void(EntitySnapshotT &)> func) const =0
iterate over all entity snapshots of this ltm
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::armem::server::ltm::detail::EntityBase
Interface functions for the longterm memory classes.
Definition: EntityBase.h:17
armarx::armem::server::ltm::detail::EntityBase::statistics
Statistics statistics
Definition: EntityBase.h:116
armarx::min
std::vector< T > min(const std::vector< T > &v1, const std::vector< T > &v2)
Definition: VectorHelpers.h:294
armarx::armem::server::ltm::detail::EntityBase::_resolve
virtual void _resolve(armem::wm::Entity &)=0
armarx::armem::wm::Entity
Client-side working memory entity.
Definition: memory_definitions.h:93
armarx::armem::server::ltm::detail::EntityBase::forEachSnapshotInTimeRange
virtual bool forEachSnapshotInTimeRange(const Time &min, const Time &max, std::function< void(EntitySnapshotT &)> func) const =0
armarx::armem::server::ltm::EntitySnapshot
Definition: EntitySnapshot.h:14
armarx::armem::server::ltm::detail::MemoryItem
Interface functions for the longterm memory classes.
Definition: MemoryItem.h:13
MemoryItem.h