ppap4lmp  0.7.2
adder.cpp
Go to the documentation of this file.
1 
9 #include "adder.h"
10 #include "../utils/runtime_error.h"
11 
12 namespace ut = utils;
13 
14 /* ------------------------------------------------------------------ */
15 
17  const ElPtr &elem,
18  Json &data)
19 {
20  if (data == nullptr)
21  {
22  ut::runtime_error("Adder accepts nonempty data only");
23  }
24 
25  compute_common(elem, data);
26 
27  auto id_exists_before = elem->check_optional_keys("id");
28 
29  elem->update_keys();
30 
31  auto id_exists_after = elem->check_optional_keys("id");
32 
33  if (id_exists_before != id_exists_after)
34  {
35  ut::runtime_error("Adder cannot add 'id'");
36  }
37 }
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
virtual void compute_body(const ElPtr &elem, Json &data) override
Compute properties and add them to Element::data given as a mutable reference.
Definition: adder.cpp:16
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
This file has a definition of Adder class, which is a subclass of Updater class.
Namespace for utility functions.
Definition: join.h:14
virtual void compute_common(const ElPtr &elem, Json &data)
Common part of compute_body.
Definition: updater.cpp:47