ppap4lmp  0.7.2
fil_set.cpp
Go to the documentation of this file.
1 
9 #include "fil_set.h"
10 
11 /* ------------------------------------------------------------------ */
12 
14  const Map<Str,Set<Json>> &acceptable_value_sets_)
15 {
16  acceptable_value_sets = acceptable_value_sets_;
17 }
18 
19 /* ------------------------------------------------------------------ */
20 
22  const Json &elem_in_data)
23 {
24  for (const auto &item : acceptable_value_sets)
25  {
26  auto &set = item.second;
27 
28  if (set.find(elem_in_data[item.first]) == set.cend()) return false;
29  }
30 
31  return true;
32 }
33 
34 /* ------------------------------------------------------------------ */
35 
37  Json &data,
38  JsonToVoidFunc check_required_keys,
39  JsonToBoolFunc check_optional_keys)
40 {
41  for (const auto &item : acceptable_value_sets)
42  {
43  check_required_keys(item.first);
44  }
45 
46  Json remaining_data = Json::array();
47 
48  for (const auto &d : data)
49  {
51  {
52  remaining_data.push_back(d);
53  }
54  }
55 
56  data.swap(remaining_data);
57 }
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
Definition: updater.h:20
FilSet(const Map< Str, Set< Json >> &acceptable_value_sets_)
Constructor of FilSet class.
Definition: fil_set.cpp:13
std::string Str
Str is an alias for string.
Definition: std.h:21
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
std::unordered_set< T > Set
Set is an alias for unordered set (same as set in Python).
Definition: std.h:49
const bool check_if_pass_data_elem(const Json &elem_in_data)
Check if an element in data array can pass this filter.
Definition: fil_set.cpp:21
This file has a definition of FilSet class, which is a subclass of Filter class.
virtual void compute_impl(Json &data, JsonToVoidFunc check_required_keys, JsonToBoolFunc check_optional_keys) override
This method overrides Updater::compute_impl.
Definition: fil_set.cpp:36
Map< Str, Set< Json > > acceptable_value_sets
Definition: fil_set.h:34
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.
Definition: updater.h:18
std::unordered_map< T, U > Map
Map is an alias for unordered map (same as dict in Python).
Definition: std.h:38