WhitelistFilter.cpp
Go to the documentation of this file.
1#include "WhitelistFilter.h"
2
3#include <SimoxUtility/algorithm/string.h>
4
6{
7 WhitelistFilter::WhitelistFilter(const std::vector<std::string>& whitelist,
8 const std::map<std::string, Normalization>& normalization) :
9 whitelist(whitelist), normalization(normalization)
10 {
11 }
12
13 bool
14 WhitelistFilter::pathInWhitelist(const aron::Path& p) const
15 {
16 for (const auto& w : whitelist)
17 {
18 if (simox::alg::starts_with(p.toString(), w))
19 {
20 return true;
21 }
22 }
23 return false;
24 }
25
26 void
28 {
29 auto l = aron::make_list(aron->getPath());
30 for (const auto& el : aron->getElements())
31 {
32 WhitelistFilter v(whitelist, normalization);
33 aron::data::visit(v, el);
34
35 if (v.data)
36 {
37 l->addElement(v.data);
38 }
39 }
40
41 if (l->getElements().size() || pathInWhitelist(aron->getPath()))
42 {
43 data = l;
44 }
45 }
46
47 void
49 {
50 auto l = aron::make_dict(aron->getPath());
51 for (const auto& [k, el] : aron->getElements())
52 {
53 WhitelistFilter v(whitelist, normalization);
54 aron::data::visit(v, el);
55
56 if (v.data)
57 {
58 l->addElement(k, v.data);
59 }
60 }
61
62 if (l->getElements().size() || pathInWhitelist(aron->getPath()))
63 {
64 data = l;
65 }
66 }
67
68 void
70 {
71 if (pathInWhitelist(aron->getPath()))
72 {
73 data = aron->clone();
74 }
75 }
76
77 void
79 {
80 if (pathInWhitelist(aron->getPath()))
81 {
82 auto e = aron->clone();
83 int v = checkForNormalization(aron->getPath(), e->getValue());
84 e->setValue(v);
85 data = e;
86 }
87 }
88
89 void
91 {
92 if (pathInWhitelist(aron->getPath()))
93 {
94 auto e = aron->clone();
95 long v = checkForNormalization(aron->getPath(), e->getValue());
96 e->setValue(v);
97 data = e;
98 }
99 }
100
101 void
103 {
104 if (pathInWhitelist(aron->getPath()))
105 {
106 auto e = aron->clone();
107 float v = checkForNormalization(aron->getPath(), e->getValue());
108 e->setValue(v);
109 data = e;
110 }
111 }
112
113 void
115 {
116 if (pathInWhitelist(aron->getPath()))
117 {
118 auto e = aron->clone();
119 double v = checkForNormalization(aron->getPath(), e->getValue());
120 e->setValue(v);
121 data = e;
122 }
123 }
124
125 void
127 {
128 if (pathInWhitelist(aron->getPath()))
129 {
130 auto e = aron->clone();
131 bool v = checkForNormalization(aron->getPath(), e->getValue());
132 e->setValue(v);
133 data = e;
134 }
135 }
136
137 void
139 {
140 if (pathInWhitelist(aron->getPath()))
141 {
142 data = aron->clone();
143 }
144 }
145} // namespace armarx::aron::data::filter
The Path class.
Definition Path.h:36
std::string toString() const
Definition Path.cpp:127
void visitAronVariant(const data::DictPtr &) override
WhitelistFilter(const std::vector< std::string > &whitelist, const std::map< std::string, Normalization > &normalization={})
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< List > ListPtr
Definition List.h:41
std::shared_ptr< Bool > BoolPtr
std::shared_ptr< Float > FloatPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition NDArray.h:46
std::shared_ptr< Long > LongPtr
std::shared_ptr< Int > IntPtr
void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition Visitor.h:136
std::shared_ptr< Double > DoublePtr
std::shared_ptr< String > StringPtr
aron::data::ListPtr make_list(_Args &&... args)
Definition List.h:99
aron::data::DictPtr make_dict(_Args &&... args)
Definition Dict.h:107