ppap4lmp  0.7.2
py_element.cpp
Go to the documentation of this file.
1 
8 #include "py_element.h"
9 #include "../core/updater.h"
10 #include "../starters/sta_copy.h"
11 #include "../starters/sta_custom.h"
12 
13 void pybind::py_element(py::module &m)
14 {
15  /* NOTE:
16  The below function is required to make an UpdatePair object
17  from shared pointers of the created Element object
18  and the taken Starter's subclass object;
19  because a constructor cannot call shared_from_this()
20  and therefore cannot make an UpdatePair object.
21  */
22  m.def(
23  "create",
24  [](ShPtr<Updater> upd)
25  {
26  return ElPtr(new Element())->append_updater(upd);
27  }
28  );
29 
30  m.def(
31  "create",
32  [](ElPtr elem)
33  {
34  return ElPtr(new Element())->append_updater(
35  ShPtr<Updater>(new StaCopy(elem)));
36  }
37  );
38 
39  m.def(
40  "create",
41  [](Json object)
42  {
43  return ElPtr(new Element())->append_updater(
44  ShPtr<Updater>(new StaCustom(object)));
45  }
46  );
47 
48  py::class_<
49  Element,PyElement,ElPtr>(m, "Element")
50  .def(py::init<>())
51  .def(
52  "append_updater",
54  .def(
55  "get_data",
57  .def(
58  "get_keys",
60  .def(
61  "get_1d_int",
63  .def(
64  "get_1d_float",
66  .def(
67  "get_2d_int",
69  .def(
70  "get_2d_float",
72 }
ArrayXd get_1d_float_py(const Str &key)
Get float values stored in Element::data of this object as a one-dimensional Numpy-Array.
Definition: element.cpp:366
Set< Str > get_keys_py()
Get keys of the data of this object.
Definition: element.cpp:342
ShPtr< Element > ElPtr
An alias for a shared pointer of Element class.
Definition: element.h:378
This file is for binding Element class to Python.
const Json & get_data_py()
Get a reference to data of this object.
Definition: element.cpp:333
void py_element(py::module &m)
Bind Element class to Python.
Definition: py_element.cpp:13
ArrayXXd get_2d_float_py(const py::args &args)
Get float values stored in Element::data of this object as a two-dimensional Numpy-Array.
Definition: element.cpp:399
nlohmann::json Json
Json is an alias for nlohmann::json.
Definition: json.h:22
Element inherits Generator class and contains data element (or entity) as a Json object.
Definition: element.h:42
ShPtr< Element > append_updater(const ShPtr< Updater > &upd)
Append an Updater object to this Element object: the only way to extend an updating process associate...
Definition: element.cpp:157
StaCustom sets an user-defined Json object to a new Element object as its Element::data.
Definition: sta_custom.h:24
ArrayXXi get_2d_int_py(const py::args &args)
Get integer values stored in Element::data of this object as a two-dimensional Numpy-Array.
Definition: element.cpp:381
StaCopy copies Element::data of an existing Element object and sets it to a new Element object...
Definition: sta_copy.h:25
Trampoline class to bind Element class to Python.
Definition: py_element.h:20
std::shared_ptr< T > ShPtr
ShPtr is an alias for shared pointer.
Definition: std.h:16
ArrayXi get_1d_int_py(const Str &key)
Get integer values stored in Element::data of this object as a one-dimensional Numpy-Array.
Definition: element.cpp:351