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