ProviderSegmentQueryProcessorBase.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
7 #include <RobotAPI/interface/armem/query.h>
8 
9 #include <regex>
10 
11 
13 {
14 
15  template <class _ProviderSegmentT, class _ResultProviderSegmentT, class _ChildProcessorT>
17  public BaseQueryProcessorBase<_ProviderSegmentT, _ResultProviderSegmentT, armem::query::data::ProviderSegmentQuery>
18  {
19  protected:
20 
22 
23 
24  public:
25 
26  using ProviderSegmentT = _ProviderSegmentT;
28 
29  using ResultProviderSegmentT = _ResultProviderSegmentT;
31 
32  using ChildProcessorT = _ChildProcessorT;
33 
34 
35  public:
36 
38  {
39  }
42  {
43  }
44 
45  using Base::process;
46  virtual void process(ResultProviderSegmentT& result,
47  const armem::query::data::ProviderSegmentQuery& query,
48  const ProviderSegmentT& providerSegment) const override
49  {
50  if (auto q = dynamic_cast<const armem::query::data::provider::All*>(&query))
51  {
52  process(result, *q, providerSegment);
53  }
54  else if (auto q = dynamic_cast<const armem::query::data::provider::Single*>(&query))
55  {
56  process(result, *q, providerSegment);
57  }
58  else if (auto q = dynamic_cast<const armem::query::data::provider::Regex*>(&query))
59  {
60  process(result, *q, providerSegment);
61  }
62  else
63  {
64  throw armem::error::UnknownQueryType(ProviderSegmentT::getLevelName(), query);
65  }
66  }
67 
68  virtual void process(ResultProviderSegmentT& result,
69  const armem::query::data::provider::All& query,
70  const ProviderSegmentT& providerSegment) const
71  {
72  providerSegment.forEachEntity([this, &result, &query](const EntityT& entity)
73  {
74  this->_processResult(result, entity, query);
75  });
76  }
77 
78  virtual void process(ResultProviderSegmentT& result,
79  const armem::query::data::provider::Single& query,
80  const ProviderSegmentT& providerSegment) const
81  {
82  if (auto entity = providerSegment.findEntity(query.entityName))
83  {
84  this->_processResult(result, *entity, query);
85  }
86  }
87 
88  virtual void process(ResultProviderSegmentT& result,
89  const armem::query::data::provider::Regex& query,
90  const ProviderSegmentT& providerSegment) const
91  {
92  const std::regex regex(query.entityNameRegex);
93  providerSegment.forEachEntity([this, &result, &query, &regex](const EntityT& entity)
94  {
95  if (std::regex_search(entity.name(), regex))
96  {
97  this->_processResult(result, entity, query);
98  }
99  return true;
100  });
101  }
102 
103 
104  protected:
105 
107  const EntityT& entity,
108  const armem::query::data::ProviderSegmentQuery& query) const
109  {
110  ResultEntityT* child = result.findEntity(entity.name());
111  if (child == nullptr)
112  {
113  child = &result.addEntity(entity.name());
114  }
115  childProcessor.process(*child, query.entityQueries, entity);
116  }
117 
118 
119  protected:
120 
122 
123  };
124 }
armarx::armem::server::query_proc::base
Definition: BaseQueryProcessorBase.cpp:6
BaseQueryProcessorBase.h
armarx::armem::wm::ProviderSegment
Client-side working memory provider segment.
Definition: memory_definitions.h:105
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::process
virtual void process(ResultProviderSegmentT &result, const armem::query::data::provider::Single &query, const ProviderSegmentT &providerSegment) const
Definition: ProviderSegmentQueryProcessorBase.h:78
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::process
virtual void process(ResultProviderSegmentT &result, const armem::query::data::ProviderSegmentQuery &query, const ProviderSegmentT &providerSegment) const override
Process the query and populate result.
Definition: ProviderSegmentQueryProcessorBase.h:46
armarx::armem::server::query_proc::base::BaseQueryProcessorBase
Base class for memory query processors.
Definition: BaseQueryProcessorBase.h:21
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase< server::wm::ProviderSegment, armem::wm::ProviderSegment, EntityQueryProcessor >::ChildProcessorT
EntityQueryProcessor ChildProcessorT
Definition: ProviderSegmentQueryProcessorBase.h:32
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::process
virtual void process(ResultProviderSegmentT &result, const armem::query::data::provider::All &query, const ProviderSegmentT &providerSegment) const
Definition: ProviderSegmentQueryProcessorBase.h:68
error.h
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase< server::wm::ProviderSegment, armem::wm::ProviderSegment, EntityQueryProcessor >::EntityT
typename ProviderSegmentT::EntityT EntityT
Definition: ProviderSegmentQueryProcessorBase.h:27
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::childProcessor
ChildProcessorT childProcessor
Definition: ProviderSegmentQueryProcessorBase.h:121
q
#define q
armarx::armem::server::wm::ProviderSegment
Definition: memory_definitions.h:60
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::ProviderSegmentQueryProcessorBase
ProviderSegmentQueryProcessorBase(ChildProcessorT &&childProcessor)
Definition: ProviderSegmentQueryProcessorBase.h:40
armarx::armem::base::ProviderSegmentBase::forEachEntity
bool forEachEntity(EntityFunctionT &&func)
Definition: ProviderSegmentBase.h:189
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::_processResult
void _processResult(ResultProviderSegmentT &result, const EntityT &entity, const armem::query::data::ProviderSegmentQuery &query) const
Definition: ProviderSegmentQueryProcessorBase.h:106
armarx::armem::server::query_proc::base::BaseQueryProcessorBase< _ProviderSegmentT, _ResultProviderSegmentT, armem::query::data::ProviderSegmentQuery >::process
_ResultProviderSegmentT process(const armem::query::data::ProviderSegmentQuery &query, const _ProviderSegmentT &data) const
Definition: BaseQueryProcessorBase.h:33
armarx::armem::base::ProviderSegmentBase::addEntity
EntityT & addEntity(const std::string &name)
Add an empty entity with the given name.
Definition: ProviderSegmentBase.h:298
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase< server::wm::ProviderSegment, armem::wm::ProviderSegment, EntityQueryProcessor >::ResultEntityT
typename ResultProviderSegmentT::EntityT ResultEntityT
Definition: ProviderSegmentQueryProcessorBase.h:30
armarx::armem::base::ProviderSegmentBase::findEntity
EntityT * findEntity(const std::string &name)
Definition: ProviderSegmentBase.h:122
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::process
virtual void process(ResultProviderSegmentT &result, const armem::query::data::provider::Regex &query, const ProviderSegmentT &providerSegment) const
Definition: ProviderSegmentQueryProcessorBase.h:88
armarx::armem::base::ProviderSegmentBase< Entity, ProviderSegment >::EntityT
Entity EntityT
Definition: ProviderSegmentBase.h:37
armarx::armem::error::UnknownQueryType
Indicates that an entity's history was queried, but is empty.
Definition: ArMemError.h:173
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase::ProviderSegmentQueryProcessorBase
ProviderSegmentQueryProcessorBase()
Definition: ProviderSegmentQueryProcessorBase.h:37
armarx::armem::server::query_proc::base::ProviderSegmentQueryProcessorBase
Definition: ProviderSegmentQueryProcessorBase.h:16