CoreSegmentQueryProcessorBase.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 #include <RobotAPI/interface/armem/query.h>
7 
8 #include <regex>
9 
10 
12 {
13 
14  /**
15  * @brief Handles memory queries.
16  */
17  template <class _CoreSegmentT, class _ResultCoreSegmentT, class _ChildProcessorT>
19  public BaseQueryProcessorBase<_CoreSegmentT, _ResultCoreSegmentT, armem::query::data::CoreSegmentQuery>
20  {
21  protected:
22 
24 
25  public:
26 
27  using CoreSegmentT = _CoreSegmentT;
29 
30  using ResultCoreSegmentT = _ResultCoreSegmentT;
32 
33  using ChildProcessorT = _ChildProcessorT;
34 
35 
36  public:
37 
39  {
40  }
43  {
44  }
45 
46 
47  using Base::process;
48  virtual void process(ResultCoreSegmentT& result,
49  const armem::query::data::CoreSegmentQuery& query,
50  const CoreSegmentT& coreSegment) const override
51  {
52  if (auto q = dynamic_cast<const armem::query::data::core::All*>(&query))
53  {
54  process(result, *q, coreSegment);
55  }
56  else if (auto q = dynamic_cast<const armem::query::data::core::Single*>(&query))
57  {
58  process(result, *q, coreSegment);
59  }
60  else if (auto q = dynamic_cast<const armem::query::data::core::Regex*>(&query))
61  {
62  process(result, *q, coreSegment);
63  }
64  else
65  {
66  throw armem::error::UnknownQueryType("core segment", query);
67  }
68  }
69 
70  virtual void process(ResultCoreSegmentT& result,
71  const armem::query::data::core::All& query,
72  const CoreSegmentT& coreSegment) const
73  {
74  coreSegment.forEachProviderSegment([this, &query, &result](const ProviderSegmentT & providerSegment)
75  {
76  this->_processResult(result, providerSegment, query);
77  });
78  }
79 
80  virtual void process(ResultCoreSegmentT& result,
81  const armem::query::data::core::Single& query,
82  const CoreSegmentT& coreSegment) const
83  {
84  if (auto providerSegment = coreSegment.findProviderSegment(query.providerSegmentName))
85  {
86  this->_processResult(result, *providerSegment, query);
87  }
88  }
89 
90  virtual void process(ResultCoreSegmentT& result,
91  const armem::query::data::core::Regex& query,
92  const CoreSegmentT& coreSegment) const
93  {
94  const std::regex regex(query.providerSegmentNameRegex);
95  coreSegment.forEachProviderSegment(
96  [this, &result, &query, &regex](const ProviderSegmentT & providerSegment)
97  {
98  if (std::regex_search(providerSegment.name(), regex))
99  {
100  this->_processResult(result, providerSegment, query);
101  }
102  });
103  }
104 
105 
106  protected:
107 
109  const ProviderSegmentT& providerSegment,
110  const armem::query::data::CoreSegmentQuery& query) const
111  {
112  ResultProviderSegmentT* child = result.findProviderSegment(providerSegment.name());
113  if (child == nullptr)
114  {
115  child = &result.addProviderSegment(providerSegment.name(), providerSegment.aronType());
116  }
117  childProcessor.process(*child, query.providerSegmentQueries, providerSegment);
118  }
119 
120 
121  protected:
122 
124 
125  };
126 }
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::process
virtual void process(ResultCoreSegmentT &result, const armem::query::data::core::Regex &query, const CoreSegmentT &coreSegment) const
Definition: CoreSegmentQueryProcessorBase.h:90
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::CoreSegmentQueryProcessorBase
CoreSegmentQueryProcessorBase(ChildProcessorT &&childProcessor)
Definition: CoreSegmentQueryProcessorBase.h:41
armarx::armem::server::query_proc::base
Definition: BaseQueryProcessorBase.cpp:6
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase< server::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor >::ChildProcessorT
ProviderSegmentQueryProcessor ChildProcessorT
Definition: CoreSegmentQueryProcessorBase.h:33
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase< server::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor >::ResultProviderSegmentT
typename ResultCoreSegmentT::ProviderSegmentT ResultProviderSegmentT
Definition: CoreSegmentQueryProcessorBase.h:31
BaseQueryProcessorBase.h
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::process
virtual void process(ResultCoreSegmentT &result, const armem::query::data::core::Single &query, const CoreSegmentT &coreSegment) const
Definition: CoreSegmentQueryProcessorBase.h:80
armarx::armem::server::query_proc::base::BaseQueryProcessorBase
Base class for memory query processors.
Definition: BaseQueryProcessorBase.h:21
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase
Handles memory queries.
Definition: CoreSegmentQueryProcessorBase.h:18
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::_processResult
void _processResult(ResultCoreSegmentT &result, const ProviderSegmentT &providerSegment, const armem::query::data::CoreSegmentQuery &query) const
Definition: CoreSegmentQueryProcessorBase.h:108
armarx::armem::base::CoreSegmentBase::findProviderSegment
ProviderSegmentT * findProviderSegment(const std::string &name)
Definition: CoreSegmentBase.h:130
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::process
virtual void process(ResultCoreSegmentT &result, const armem::query::data::core::All &query, const CoreSegmentT &coreSegment) const
Definition: CoreSegmentQueryProcessorBase.h:70
armarx::armem::base::CoreSegmentBase< ProviderSegment, CoreSegment >::ProviderSegmentT
ProviderSegment ProviderSegmentT
Definition: CoreSegmentBase.h:40
armarx::armem::wm::CoreSegment
Client-side working memory core segment.
Definition: memory_definitions.h:119
armarx::armem::base::CoreSegmentBase::forEachProviderSegment
bool forEachProviderSegment(ProviderSegmentFunctionT &&func)
Definition: CoreSegmentBase.h:217
error.h
armarx::armem::base::CoreSegmentBase::addProviderSegment
ProviderSegmentT & addProviderSegment(const std::string &name, aron::type::ObjectPtr providerSegmentType=nullptr, const std::vector< PredictionEngine > &predictionEngines={})
Add an empty provider segment with the given name, optional provider segment type and prediction engi...
Definition: CoreSegmentBase.h:344
q
#define q
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase< server::wm::CoreSegment, armem::wm::CoreSegment, ProviderSegmentQueryProcessor >::ProviderSegmentT
typename CoreSegmentT::ProviderSegmentT ProviderSegmentT
Definition: CoreSegmentQueryProcessorBase.h:28
armarx::armem::server::wm::CoreSegment
base::CoreSegmentBase
Definition: memory_definitions.h:86
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::childProcessor
ChildProcessorT childProcessor
Definition: CoreSegmentQueryProcessorBase.h:123
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::process
virtual void process(ResultCoreSegmentT &result, const armem::query::data::CoreSegmentQuery &query, const CoreSegmentT &coreSegment) const override
Process the query and populate result.
Definition: CoreSegmentQueryProcessorBase.h:48
armarx::armem::server::query_proc::base::BaseQueryProcessorBase< _CoreSegmentT, _ResultCoreSegmentT, armem::query::data::CoreSegmentQuery >::process
_ResultCoreSegmentT process(const armem::query::data::CoreSegmentQuery &query, const _CoreSegmentT &data) const
Definition: BaseQueryProcessorBase.h:33
armarx::armem::server::query_proc::base::CoreSegmentQueryProcessorBase::CoreSegmentQueryProcessorBase
CoreSegmentQueryProcessorBase()
Definition: CoreSegmentQueryProcessorBase.h:38
armarx::armem::error::UnknownQueryType
Indicates that an entity's history was queried, but is empty.
Definition: ArMemError.h:173