ProviderSegmentBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
8 
9 #include "EntityBase.h"
10 #include "MemoryItem.h"
11 
13 {
14  /// @brief Interface functions for the longterm memory classes
15  template <class _EntityT>
17  {
18  public:
19  struct Statistics
20  {
21  long recordedEntities = 0;
22  };
23 
24  public:
25  using EntityT = _EntityT;
26 
28 
29  /// return the full sub-ltm as a wm::ProviderSegment with only references
30  /// the ltm may be huge, use with caution
31  void
33  {
34  _loadAllReferences(provSeg);
35  }
36 
38  {
39  _loadLatestNReferences(n, provSeg);
40  }
41 
42  /// convert the references of the input into a wm::Memory
43  void
45  {
46  _resolve(provSeg);
47  }
48 
49  /// encode the content of a wm::Memory and store
50  void
52  {
53  _store(provSeg);
54  }
55 
56  /// statistics
57  void
59  {
61  }
62 
63  Statistics
64  getStatistics() const
65  {
66  return statistics;
67  }
68 
69  /// iterate over all core segments of this ltm
70  virtual bool forEachEntity(std::function<void(EntityT&)> func) const = 0;
71 
72  /// check if entity segment exists
73  virtual bool hasEntity(const std::string&) const = 0;
74 
75  /// find entity segment
76  virtual std::shared_ptr<EntityT> findEntity(const std::string&) const = 0;
77 
78  ///get aron type
80  {
81  return nullptr;
82  }
83 
84  static std::string
86  {
87  return "LT-ProviderSegment";
88  }
89 
90  protected:
92  virtual void _loadLatestNReferences(int n, armem::wm::ProviderSegment& p) = 0;
93  virtual void _resolve(armem::wm::ProviderSegment&) = 0;
94  virtual void _store(const armem::wm::ProviderSegment&) = 0;
95 
96  protected:
97  mutable std::recursive_mutex ltm_mutex;
98 
99  Statistics statistics;
100  };
101 } // namespace armarx::armem::server::ltm::detail
EntityBase.h
armarx::armem::server::ltm::detail
Definition: CoreSegmentBase.cpp:3
armarx::armem::server::ltm::detail::ProviderSegmentBase::resetStatistics
void resetStatistics()
statistics
Definition: ProviderSegmentBase.h:58
armarx::armem::server::ltm::detail::ProviderSegmentBase::hasEntity
virtual bool hasEntity(const std::string &) const =0
check if entity segment exists
armarx::armem::wm::ProviderSegment
Client-side working memory provider segment.
Definition: memory_definitions.h:105
armarx::armem::server::ltm::detail::ProviderSegmentBase::aronType
aron::type::ObjectPtr aronType() const
get aron type
Definition: ProviderSegmentBase.h:79
MemoryID.h
armarx::armem::server::ltm::Entity
A memory storing data in mongodb (needs 'armarx memory start' to start the mongod instance)
Definition: Entity.h:14
armarx::armem::server::ltm::detail::ProviderSegmentBase::ltm_mutex
std::recursive_mutex ltm_mutex
Definition: ProviderSegmentBase.h:97
armarx::armem::server::ltm::detail::ProviderSegmentBase::getStatistics
Statistics getStatistics() const
Definition: ProviderSegmentBase.h:64
armarx::armem::server::ltm::detail::ProviderSegmentBase::_loadAllReferences
virtual void _loadAllReferences(armem::wm::ProviderSegment &)=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::ProviderSegmentBase::findEntity
virtual std::shared_ptr< EntityT > findEntity(const std::string &) const =0
find entity segment
armarx::armem::server::ltm::detail::ProviderSegmentBase::loadAllReferences
void loadAllReferences(armem::wm::ProviderSegment &provSeg)
return the full sub-ltm as a wm::ProviderSegment with only references the ltm may be huge,...
Definition: ProviderSegmentBase.h:32
armarx::armem::server::ltm::detail::ProviderSegmentBase::loadLatestNReferences
void loadLatestNReferences(int n, armem::wm::ProviderSegment &provSeg)
Definition: ProviderSegmentBase.h:37
armarx::armem::server::ltm::detail::ProviderSegmentBase::forEachEntity
virtual bool forEachEntity(std::function< void(EntityT &)> func) const =0
iterate over all core segments of this ltm
armarx::armem::server::ltm::detail::ProviderSegmentBase::Statistics::recordedEntities
long recordedEntities
Definition: ProviderSegmentBase.h:21
armarx::armem::server::ltm::detail::ProviderSegmentBase::EntityT
_EntityT EntityT
Definition: ProviderSegmentBase.h:25
armarx::armem::server::ltm::detail::ProviderSegmentBase::_resolve
virtual void _resolve(armem::wm::ProviderSegment &)=0
armarx::armem::server::ltm::detail::ProviderSegmentBase::statistics
Statistics statistics
Definition: ProviderSegmentBase.h:99
armarx::armem::server::ltm::detail::ProviderSegmentBase::getLevelName
static std::string getLevelName()
Definition: ProviderSegmentBase.h:85
armarx::armem::server::ltm::detail::ProviderSegmentBase::Statistics
Definition: ProviderSegmentBase.h:19
memory_definitions.h
armarx::armem::server::ltm::detail::ProviderSegmentBase::resolve
void resolve(armem::wm::ProviderSegment &provSeg)
convert the references of the input into a wm::Memory
Definition: ProviderSegmentBase.h:44
armarx::armem::server::ltm::detail::ProviderSegmentBase::_loadLatestNReferences
virtual void _loadLatestNReferences(int n, armem::wm::ProviderSegment &p)=0
armarx::armem::server::ltm::detail::ProviderSegmentBase
Interface functions for the longterm memory classes.
Definition: ProviderSegmentBase.h:16
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::armem::server::ltm::detail::ProviderSegmentBase::store
void store(const armem::wm::ProviderSegment &provSeg)
encode the content of a wm::Memory and store
Definition: ProviderSegmentBase.h:51
armarx::armem::server::ltm::detail::ProviderSegmentBase::_store
virtual void _store(const armem::wm::ProviderSegment &)=0
armarx::armem::server::ltm::detail::MemoryItem
Interface functions for the longterm memory classes.
Definition: MemoryItem.h:13
MemoryItem.h