ppap4lmp  0.7.2
gen_list.cpp
Go to the documentation of this file.
1 
8 #include "gen_list.h"
9 #include "../utils/runtime_error.h"
10 
11 namespace ut = utils;
12 
13 /* ------------------------------------------------------------------ */
14 
16  const Vec<ShPtr<Generator>> &generator_list_)
17 {
18  generator_list = generator_list_;
19 
20  for (const auto &gen : generator_list)
21  {
22  merge_update_chain(gen->get_update_chain());
23  }
24 }
25 
26 /* ------------------------------------------------------------------ */
27 
29  const Json &name)
30 {
31  if (!name.is_number_integer())
32  {
33  ut::runtime_error("Rejection of non-integer Json");
34  }
35 
36  return std::dynamic_pointer_cast<Element>(
37  generator_list[name.get<int>()]);
38 }
39 
40 /* ------------------------------------------------------------------ */
41 
43  const Json &name)
44 {
45  if (!name.is_number_integer())
46  {
47  ut::runtime_error("Rejection of non-integer Json");
48  }
49 
50  return generator_list[name.get<int>()];
51 }
52 
53 /* ------------------------------------------------------------------ */
54 
56  const Str &classname)
57 {
58  for (const auto &gen : generator_list)
59  {
60  gen->accessed_by_instance_of(classname);
61  }
62 }
63 
64 /* ------------------------------------------------------------------ */
65 
67 {
68  return generator_list.size();
69 }
virtual void accessed_by_instance_of(const Str &classname) override
Set class name of an instance calling Element::check_required_keys.
Definition: gen_list.cpp:55
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
Vec< ShPtr< Generator > > generator_list
Definition: gen_list.h:26
std::string Str
Str is an alias for string.
Definition: std.h:21
GenList(const Vec< ShPtr< Generator >> &generator_list_)
Constructor of GenList class.
Definition: gen_list.cpp:15
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
void merge_update_chain(const Vec< UpdatePair > &new_chain)
Definition: generator.cpp:15
std::vector< T > Vec
Vec is an alias for vector (same as list in Python).
Definition: std.h:27
virtual ShPtr< Generator > get_generator(const Json &name=nullptr) override
Get an element of generator_list as a shared pointer of Generator class.
Definition: gen_list.cpp:42
Element inherits Generator class and contains data element (or entity) as a Json object.
Definition: element.h:42
void runtime_error(const Str &msg)
Raise (for Python) and throw (for C++) a runtime error.
This file has a definition of GenList class.
Namespace for utility functions.
Definition: join.h:14
virtual ElPtr get_element(const Json &name=nullptr) override
Get an element of generator_list as a shared pointer of Element class.
Definition: gen_list.cpp:28
std::shared_ptr< T > ShPtr
ShPtr is an alias for shared pointer.
Definition: std.h:16
int get_length()
Get a length of generator_list.
Definition: gen_list.cpp:66