MemoryQueryProcessorBase.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
10
12
13
14
16{
17
18 template <class _MemoryT, class _ResultMemoryT, class _ChildProcessorT>
20 public BaseQueryProcessorBase<_MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery>
21 {
22 protected:
23 using Base =
26 public:
27 using MemoryT = _MemoryT;
28 using CoreSegmentT = typename MemoryT::CoreSegmentT;
29
30 using ResultMemoryT = _ResultMemoryT;
31 using ResultCoreSegmentT = typename ResultMemoryT::CoreSegmentT;
32
33 using ChildProcessorT = _ChildProcessorT;
34
35
36 public:
40
44
45 using Base::process;
46
48 process(const armem::query::data::Input& input, const MemoryT& memory) const
49 {
51
52 return this->process(input.memoryQueries, memory);
53 }
54
55 virtual void
57 const armem::query::data::MemoryQuery& query,
58 const MemoryT& memory) const override
59 {
61
62 if (auto q = dynamic_cast<const armem::query::data::memory::All*>(&query))
63 {
64 process(result, *q, memory);
65 }
66 else if (auto q = dynamic_cast<const armem::query::data::memory::Single*>(&query))
67 {
68 process(result, *q, memory);
69 }
70 else if (auto q = dynamic_cast<const armem::query::data::memory::Regex*>(&query))
71 {
72 process(result, *q, memory);
73 }
74 else
75 {
76 throw armem::error::UnknownQueryType(MemoryT::getLevelName(), query);
77 }
78 }
79
80 virtual void
82 const armem::query::data::memory::All& query,
83 const MemoryT& memory) const
84 {
86
87 memory.forEachCoreSegment([this, &result, &query](const CoreSegmentT& coreSegment)
88 { this->_processResult(result, coreSegment, query); });
89 }
90
91 virtual void
93 const armem::query::data::memory::Single& query,
94 const MemoryT& memory) const
95 {
97
98 if (auto coreSegment = memory.findCoreSegment(query.coreSegmentName))
99 {
100 this->_processResult(result, *coreSegment, query);
101 }
102 }
103
104 virtual void
106 const armem::query::data::memory::Regex& query,
107 const MemoryT& memory) const
108 {
110
111 const std::regex regex(query.coreSegmentNameRegex);
112 memory.forEachCoreSegment(
113 [this, &result, &query, &regex](const CoreSegmentT& coreSegment)
114 {
115 if (std::regex_search(coreSegment.name(), regex))
116 {
117 this->_processResult(result, coreSegment, query);
118 }
119 });
120 }
121
122
123 protected:
124 virtual bool
125 _processAllowed(const armem::query::data::MemoryQuery& query) const
126 {
127 // always execute query. Override if you want to execute the quey only if a special condition is fulfilled (e.g. querytargets)
128 return true;
129 }
130
131 void
133 const CoreSegmentT& coreSegment,
134 const armem::query::data::MemoryQuery& query) const
135 {
136 ResultCoreSegmentT* child = result.findCoreSegment(coreSegment.name());
137
138 if (child == nullptr)
139 {
140 child = &result.addCoreSegment(coreSegment.name(), coreSegment.aronType());
141 }
142
143 childProcessor.process(*child, query.coreSegmentQueries, coreSegment);
144 }
145
146
147 protected:
149 };
150} // namespace armarx::armem::server::query_proc::base
Indicates that an entity's history was queried, but is empty.
Definition ArMemError.h:174
_ResultMemoryT process(const armem::query::data::MemoryQuery &query, const _MemoryT &data) const
ResultMemoryT process(const armem::query::data::Input &input, const MemoryT &memory) const
virtual void process(ResultMemoryT &result, const armem::query::data::MemoryQuery &query, const MemoryT &memory) const override
Process the query and populate result.
BaseQueryProcessorBase< _MemoryT, _ResultMemoryT, armem::query::data::MemoryQuery > Base
virtual bool _processAllowed(const armem::query::data::MemoryQuery &query) const
void _processResult(ResultMemoryT &result, const CoreSegmentT &coreSegment, const armem::query::data::MemoryQuery &query) const
virtual void process(ResultMemoryT &result, const armem::query::data::memory::All &query, const MemoryT &memory) const
virtual void process(ResultMemoryT &result, const armem::query::data::memory::Regex &query, const MemoryT &memory) const
virtual void process(ResultMemoryT &result, const armem::query::data::memory::Single &query, const MemoryT &memory) const
Brief description of class memory.
Definition memory.h:39
#define q
#define ARMARX_TRACE
Definition trace.h:77