SelectorOps.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <vector>
4 
5 #include <Ice/Handle.h>
6 
8 #include <RobotAPI/interface/armem/query.h>
9 
10 
12 {
13 
14  template <class _DerivedT, class _QueryT>
16  {
17  public:
18  using DerivedT = _DerivedT;
19  using QueryT = _QueryT;
20 
21  ChildSelectorOps() = default;
22  virtual ~ChildSelectorOps() = default;
23 
24 
25  virtual DerivedT& all() = 0;
26  virtual DerivedT& withID(const MemoryID& id) = 0;
27 
28 
30  {
31  _queries.push_back(query);
32  }
33  void addQueries(const std::vector<IceInternal::Handle<QueryT>>& queries)
34  {
35  for (auto q : queries)
36  {
37  addQuery(q);
38  }
39  }
40 
41 
42  protected:
43 
44  template <class DerivedQueryT>
45  DerivedQueryT& _addQuery()
46  {
47  IceInternal::Handle<DerivedQueryT> query(new DerivedQueryT);
48  _queries.push_back(query);
49  return *query;
50  }
51 
52  std::vector<QueryT> _queries;
53 
54 
55  // Only friends have access to these.
56 
57  template <class ParentDerivedT, class ParentChildT>
58  friend class ParentSelectorOps;
59 
60  template <class T>
61  inline void _apply(T arg)
62  {
63  arg(dynamic_cast<DerivedT&>(*this));
64  }
65  template <class T, class ...Ts>
66  inline void _apply(T arg, Ts... args)
67  {
68  _apply(arg);
69  _apply(args...);
70  }
71 
72 
73 
74  };
75 
76 
77 
78  template <class _DerivedT, class _ChildT>
80  {
81  public:
82  using DerivedT = _DerivedT;
83  using ChildT = _ChildT;
84 
85 
86  public:
87  virtual ~ParentSelectorOps() = default;
88 
89  protected:
90 
92  {
93  return _children.emplace_back();
94  }
95  ChildT& _addChild(const ChildT& child)
96  {
97  return _children.emplace_back(child);
98  }
99 
100  template <class ...Ts>
101  ChildT& _addChild(Ts... args)
102  {
103  ChildT& sel = _addChild();
104  sel._apply(args...);
105  return sel;
106  }
107 
108 
109  std::vector<ChildT> _children;
110  };
111 
112 
113 
114  template <class DerivedT, class QueryT, class ChildT>
116  public ParentSelectorOps<DerivedT, ChildT>,
117  public ChildSelectorOps<DerivedT, QueryT>
118  {
119  public:
120 
121  InnerSelectorOps() = default;
122 
123  virtual std::vector<QueryT> buildQueries() const
124  {
125  std::vector<typename ChildT::QueryT> childQueries;
126  for (const auto& child : this->_children)
127  {
128  for (auto& query : child.buildQueries())
129  {
130  childQueries.push_back(query);
131  }
132  }
133 
134  std::vector<QueryT> queries = this->_queries;
135  for (auto& query : queries)
136  {
137  this->_setChildQueries(query, childQueries);
138  }
139  return queries;
140  }
141 
142 
143  protected:
144 
145  virtual void _setChildQueries(QueryT& query, const std::vector<typename ChildT::QueryT>& childQueries) const = 0;
146 
147  };
148 
149 }
armarx::armem::client::query::detail
Definition: NameSelectorOps.h:7
armarx::armem::client::query::detail::ChildSelectorOps::withID
virtual DerivedT & withID(const MemoryID &id)=0
armarx::armem::client::query::detail::ChildSelectorOps::_addQuery
DerivedQueryT & _addQuery()
Definition: SelectorOps.h:45
MemoryID.h
armarx::armem::client::query::detail::ParentSelectorOps::_addChild
ChildT & _addChild(const ChildT &child)
Definition: SelectorOps.h:95
armarx::armem::client::query::detail::InnerSelectorOps::buildQueries
virtual std::vector< QueryT > buildQueries() const
Definition: SelectorOps.h:123
armarx::armem::client::query::detail::ParentSelectorOps::~ParentSelectorOps
virtual ~ParentSelectorOps()=default
armarx::armem::client::query::detail::ChildSelectorOps::_queries
std::vector< QueryT > _queries
Definition: SelectorOps.h:52
armarx::armem::client::query::detail::ChildSelectorOps::~ChildSelectorOps
virtual ~ChildSelectorOps()=default
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::armem::client::query::SnapshotSelector
Definition: selectors.h:13
armarx::armem::client::query::detail::ChildSelectorOps::addQueries
void addQueries(const std::vector< IceInternal::Handle< QueryT >> &queries)
Definition: SelectorOps.h:33
armarx::armem::MemoryID
A memory ID.
Definition: MemoryID.h:47
armarx::armem::client::query::detail::InnerSelectorOps::InnerSelectorOps
InnerSelectorOps()=default
armarx::armem::client::query::detail::InnerSelectorOps::_setChildQueries
virtual void _setChildQueries(QueryT &query, const std::vector< typename ChildT::QueryT > &childQueries) const =0
armarx::armem::client::query::detail::InnerSelectorOps
Definition: SelectorOps.h:115
armarx::armem::client::query::detail::ChildSelectorOps< SnapshotSelector, armem::query::data::EntityQueryPtr >::QueryT
armem::query::data::EntityQueryPtr QueryT
Definition: SelectorOps.h:19
armarx::armem::client::query::detail::ChildSelectorOps::addQuery
void addQuery(const IceInternal::Handle< QueryT > &query)
Definition: SelectorOps.h:29
q
#define q
armarx::armem::client::query::detail::ChildSelectorOps::ChildSelectorOps
ChildSelectorOps()=default
armarx::armem::client::query::detail::ChildSelectorOps::_apply
void _apply(T arg)
Definition: SelectorOps.h:61
armarx::armem::client::query::detail::ChildSelectorOps::_apply
void _apply(T arg, Ts... args)
Definition: SelectorOps.h:66
armarx::armem::client::query::detail::ChildSelectorOps::all
virtual DerivedT & all()=0
armarx::armem::client::query::detail::ParentSelectorOps
Definition: SelectorOps.h:79
armarx::armem::client::query::CoreSegmentSelector
Definition: selectors.h:117
armarx::armem::client::query::Builder
The query::Builder class provides a fluent-style specification of hierarchical queries.
Definition: Builder.h:22
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
armarx::armem::client::query::detail::ParentSelectorOps::_addChild
ChildT & _addChild(Ts... args)
Definition: SelectorOps.h:101
armarx::armem::client::query::detail::ParentSelectorOps::_addChild
ChildT & _addChild()
Definition: SelectorOps.h:91
armarx::armem::client::query::detail::ChildSelectorOps
Definition: SelectorOps.h:15
armarx::armem::client::query::detail::ParentSelectorOps::_children
std::vector< ChildT > _children
Definition: SelectorOps.h:109