CoreSegmentBase.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <functional>
4 
5 // BaseClass
9 
10 #include "MemoryItem.h"
11 #include "ProviderSegmentBase.h"
12 
14 {
15  /// @brief Interface functions for the longterm memory classes
16  template <class _ProviderSegmentT>
17  class CoreSegmentBase : public MemoryItem
18  {
19  public:
20  struct Statistics
21  {
23  };
24 
25  public:
26  using ProviderSegmentT = _ProviderSegmentT;
27 
29 
30  /// return the full sub-ltm as a wm::CoreSegment with only references
31  /// the ltm may be huge, use with caution
32  void
34  {
35  _loadAllReferences(coreSeg);
36  }
37 
38  void
40  {
41  _loadLatestNReferences(n, coreSeg);
42  }
43 
44  /// convert the references of the input into a wm::Memory
45  void
47  {
48  _resolve(coreSeg);
49  }
50 
51  /// encode the content of a wm::Memory and store
52  void
53  store(const armem::wm::CoreSegment& coreSeg)
54  {
55  _store(coreSeg);
56  }
57 
58  /// statistics
59  void
61  {
63  }
64 
65  Statistics
66  getStatistics() const
67  {
68  return statistics;
69  }
70 
71  /// iterate over all provider segments of this ltm
72  virtual bool forEachProviderSegment(std::function<void(ProviderSegmentT&)> func) const = 0;
73 
74  /// check if provider segment exists
75  virtual bool hasProviderSegment(const std::string&) const = 0;
76 
77  /// find provider segment
78  virtual std::shared_ptr<ProviderSegmentT> findProviderSegment(const std::string&) const = 0;
79 
80  /// get aron type
82  aronType() const
83  {
84  return nullptr;
85  }
86 
87  /// get level name
88  static std::string
90  {
91  return "LT-CoreSegment";
92  }
93 
94  protected:
95  virtual void _loadAllReferences(armem::wm::CoreSegment&) = 0;
96  virtual void _loadLatestNReferences(int n, armem::wm::CoreSegment& c) = 0;
97  virtual void _resolve(armem::wm::CoreSegment&) = 0;
98  virtual void _store(const armem::wm::CoreSegment&) = 0;
99 
100  protected:
101  mutable std::recursive_mutex ltm_mutex;
102 
103  Statistics statistics;
104  };
105 } // namespace armarx::armem::server::ltm::detail
armarx::armem::server::ltm::detail
Definition: CoreSegmentBase.cpp:3
armarx::armem::server::ltm::ProviderSegment
Definition: ProviderSegment.h:13
armarx::armem::server::ltm::detail::CoreSegmentBase::ltm_mutex
std::recursive_mutex ltm_mutex
Definition: CoreSegmentBase.h:101
MemoryID.h
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::armem::server::ltm::detail::MemoryItem::MemoryItem
MemoryItem(const std::string &exportName, const MemoryID &)
Definition: MemoryItem.cpp:10
armarx::armem::server::ltm::detail::CoreSegmentBase::ProviderSegmentT
_ProviderSegmentT ProviderSegmentT
Definition: CoreSegmentBase.h:26
armarx::armem::server::ltm::detail::CoreSegmentBase::resolve
void resolve(armem::wm::CoreSegment &coreSeg)
convert the references of the input into a wm::Memory
Definition: CoreSegmentBase.h:46
aron_conversions.h
armarx::armem::server::ltm::detail::CoreSegmentBase::_resolve
virtual void _resolve(armem::wm::CoreSegment &)=0
armarx::armem::server::ltm::detail::CoreSegmentBase
Interface functions for the longterm memory classes.
Definition: CoreSegmentBase.h:17
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::armem::server::ltm::detail::CoreSegmentBase::hasProviderSegment
virtual bool hasProviderSegment(const std::string &) const =0
check if provider segment exists
armarx::armem::server::ltm::detail::CoreSegmentBase::statistics
Statistics statistics
Definition: CoreSegmentBase.h:103
memory_definitions.h
armarx::armem::server::ltm::detail::CoreSegmentBase::_loadAllReferences
virtual void _loadAllReferences(armem::wm::CoreSegment &)=0
armarx::armem::server::ltm::detail::CoreSegmentBase::forEachProviderSegment
virtual bool forEachProviderSegment(std::function< void(ProviderSegmentT &)> func) const =0
iterate over all provider segments of this ltm
armarx::armem::server::ltm::detail::CoreSegmentBase::getStatistics
Statistics getStatistics() const
Definition: CoreSegmentBase.h:66
armarx::armem::server::ltm::detail::CoreSegmentBase::loadAllReferences
void loadAllReferences(armem::wm::CoreSegment &coreSeg)
return the full sub-ltm as a wm::CoreSegment with only references the ltm may be huge,...
Definition: CoreSegmentBase.h:33
armarx::armem::server::ltm::detail::CoreSegmentBase::Statistics::recordedProviderSegments
long recordedProviderSegments
Definition: CoreSegmentBase.h:22
armarx::armem::server::ltm::detail::CoreSegmentBase::Statistics
Definition: CoreSegmentBase.h:20
armarx::armem::server::ltm::detail::CoreSegmentBase::aronType
aron::type::ObjectPtr aronType() const
get aron type
Definition: CoreSegmentBase.h:82
armarx::armem::server::ltm::detail::CoreSegmentBase::findProviderSegment
virtual std::shared_ptr< ProviderSegmentT > findProviderSegment(const std::string &) const =0
find provider segment
armarx::aron::type::ObjectPtr
std::shared_ptr< Object > ObjectPtr
Definition: Object.h:36
armarx::armem::server::ltm::detail::CoreSegmentBase::loadLatestNReferences
void loadLatestNReferences(int n, armem::wm::CoreSegment &coreSeg)
Definition: CoreSegmentBase.h:39
ProviderSegmentBase.h
armarx::armem::server::ltm::detail::CoreSegmentBase::_loadLatestNReferences
virtual void _loadLatestNReferences(int n, armem::wm::CoreSegment &c)=0
armarx::armem::server::ltm::detail::MemoryItem
Interface functions for the longterm memory classes.
Definition: MemoryItem.h:13
MemoryItem.h
armarx::armem::server::ltm::detail::CoreSegmentBase::store
void store(const armem::wm::CoreSegment &coreSeg)
encode the content of a wm::Memory and store
Definition: CoreSegmentBase.h:53
armarx::armem::server::ltm::detail::CoreSegmentBase::_store
virtual void _store(const armem::wm::CoreSegment &)=0
armarx::armem::server::ltm::detail::CoreSegmentBase::resetStatistics
void resetStatistics()
statistics
Definition: CoreSegmentBase.h:60
armarx::armem::server::ltm::detail::CoreSegmentBase::getLevelName
static std::string getLevelName()
get level name
Definition: CoreSegmentBase.h:89