ppap4lmp  0.7.2
sta_custom.cpp
Go to the documentation of this file.
1 
9 #include "sta_custom.h"
10 #include "../utils/runtime_error.h"
11 
12 namespace ut = utils;
13 
14 /* ------------------------------------------------------------------ */
15 
17  const Json &json_)
18 {
19  json = json_;
20 }
21 
22 /* ------------------------------------------------------------------ */
23 
25  Json &data,
26  JsonToVoidFunc check_required_keys,
27  JsonToBoolFunc check_optional_keys)
28 {
29  if (json.is_array())
30  {
31  Vec<Str> jsonkeys;
32 
33  for (const auto &el : json.front().items())
34  {
35  jsonkeys.push_back(el.key());
36  }
37 
38  for (const auto &j : json)
39  {
40  for (auto it = j.cbegin(); it != j.cend(); ++it)
41  {
42  if (it.key() != jsonkeys[std::distance(j.cbegin(), it)])
43  {
44  ut::runtime_error("Invalid key(s) in array data");
45  }
46  }
47  }
48  }
49 
50  data = json;
51 }
This file has a definition of StaCustom class, which is a subclass of Starter class.
std::function< bool(const Json &)> JsonToBoolFunc
An alias for a function accepts a Json object and returns a bool.
Definition: updater.h:20
Json json
Definition: sta_custom.h:29
StaCustom(const Json &json_)
Constructor of StaCustom class.
Definition: sta_custom.cpp:16
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
Definition: std.h:27
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
Namespace for utility functions.
Definition: join.h:14
std::function< void(const Json &)> JsonToVoidFunc
An alias for a function accepts a Json object.
Definition: updater.h:18
virtual void compute_impl(Json &data, JsonToVoidFunc check_required_keys, JsonToBoolFunc check_optional_keys) override
This method overrides Updater::compute_impl.
Definition: sta_custom.cpp:24