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  {
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
armarx::aron::data::filter
Definition: WhitelistFilter.cpp:5
armarx::aron::make_dict
aron::data::DictPtr make_dict(_Args &&... args)
Definition: Dict.h:107
armarx::aron::data::LongPtr
std::shared_ptr< Long > LongPtr
Definition: forward_declarations.h:26
armarx::aron::data::NDArrayPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition: NDArray.h:46
armarx::aron::data::DoublePtr
std::shared_ptr< Double > DoublePtr
Definition: forward_declarations.h:32
armarx::aron::make_list
aron::data::ListPtr make_list(_Args &&... args)
Definition: List.h:99
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:43
armarx::aron::Path
The Path class.
Definition: Path.h:36
WhitelistFilter.h
armarx::aron::data::filter::WhitelistFilter
Definition: WhitelistFilter.h:33
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::data::filter::WhitelistFilter::visitAronVariant
void visitAronVariant(const data::DictPtr &) override
Definition: WhitelistFilter.cpp:48
armarx::aron::data::filter::WhitelistFilter::data
aron::data::VariantPtr data
Definition: WhitelistFilter.h:79
armarx::aron::data::filter::WhitelistFilter::WhitelistFilter
WhitelistFilter(const std::vector< std::string > &whitelist, const std::map< std::string, Normalization > &normalization={})
Definition: WhitelistFilter.cpp:7
armarx::aron::data::visit
requires isVisitor< VisitorImplementation, typename VisitorImplementation::Input > void visit(VisitorImplementation &v, typename VisitorImplementation::Input &o)
Definition: Visitor.h:124
armarx::aron::data::FloatPtr
std::shared_ptr< Float > FloatPtr
Definition: forward_declarations.h:29
armarx::aron::data::StringPtr
std::shared_ptr< String > StringPtr
Definition: forward_declarations.h:35
armarx::aron::data::IntPtr
std::shared_ptr< Int > IntPtr
Definition: forward_declarations.h:23
armarx::aron::data::ListPtr
std::shared_ptr< List > ListPtr
Definition: List.h:40
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125
armarx::aron::data::BoolPtr
std::shared_ptr< Bool > BoolPtr
Definition: forward_declarations.h:38