1
1
#include " fibonacci_embedding.h"
2
2
3
- PYBIND11_EMBEDDED_MODULE (fibonacci_interface, m) { }
3
+ PYBIND11_EMBEDDED_MODULE (fibonacci_interface, m)
4
+ {
5
+ pybind11::class_<Fibonacci::Embedding::FibonacciExecutionContext, std::shared_ptr<Fibonacci::Embedding::FibonacciExecutionContext>, MoniLogger::MoniLoggerExecutionContext>(m, " FibonacciExecutionContext" )
6
+ // Defining the properties exposed by the FibonacciExecutionContext.
7
+ .def_property_readonly (" n" , &Fibonacci::Embedding::FibonacciExecutionContext::get_n)
8
+ .def_property_readonly (" current_number" , &Fibonacci::Embedding::FibonacciExecutionContext::get_current_number)
9
+ .def_property_readonly (" previous_number" , &Fibonacci::Embedding::FibonacciExecutionContext::get_previous_number)
10
+ .def_property_readonly (" iteration" , &Fibonacci::Embedding::FibonacciExecutionContext::get_iteration)
11
+ // Defining legible __str__ and __repr__ functions for FibonacciExecutionContext.
12
+ .def (" __str__" , [](Fibonacci::Embedding::FibonacciExecutionContext &self)
13
+ {
14
+ std::ostringstream oss;
15
+ oss << " [" << self.name << " ]\n "
16
+ << " previous number: " << self.previous_number << " \n "
17
+ << " current number: " << self.current_number << " \n "
18
+ << " iteration: " << self.iteration << " \n " ;
19
+ return oss.str ();
20
+ })
21
+ .def (" __repr__" , [](Fibonacci::Embedding::FibonacciExecutionContext &self)
22
+ {
23
+ std::ostringstream oss;
24
+ oss << " [" << self.name << " ]\n "
25
+ << " previous number: " << self.previous_number << " \n "
26
+ << " current number: " << self.current_number << " \n "
27
+ << " iteration: " << self.iteration << " \n " ;
28
+ return oss.str ();
29
+ });
30
+ }
4
31
5
- void initialize_embedding (std::vector<std::string> python_path, std::vector<std::string> python_scripts)
32
+ namespace Fibonacci ::Embedding
6
33
{
7
- // Name of the interface module (here, an embedded module declared above) exposing the execution context of the application.
8
- std::string interface_module = " fibonacci_interface" ;
9
34
10
- // Initialization function for the interface module.
11
- std::function<void (pybind11::module_, pybind11::object)> interface_module_initializer =
12
- [](pybind11::module_ interface_module, pybind11::object context_class) {
13
- pybind11::class_<FibonacciExecutionContext, std::shared_ptr<FibonacciExecutionContext>>(interface_module, " FibonacciExecutionContext" , context_class)
14
- // Defining the properties exposed by the FibonacciExecutionContext.
15
- .def_property_readonly (" n" , &FibonacciExecutionContext::get_n)
16
- .def_property_readonly (" current_number" , &FibonacciExecutionContext::get_current_number)
17
- .def_property_readonly (" previous_number" , &FibonacciExecutionContext::get_previous_number)
18
- .def_property_readonly (" iteration" , &FibonacciExecutionContext::get_iteration)
19
- // Defining legible __str__ and __repr__ functions for FibonacciExecutionContext.
20
- .def (" __str__" , [](FibonacciExecutionContext &self)
21
- {
22
- std::ostringstream oss;
23
- oss << " [" << self.name << " ]\n "
24
- << " previous number: " << self.previous_number << " \n "
25
- << " current number: " << self.current_number << " \n "
26
- << " iteration: " << self.iteration << " \n " ;
27
- return oss.str ();
28
- })
29
- .def (" __repr__" , [](FibonacciExecutionContext &self)
30
- {
31
- std::ostringstream oss;
32
- oss << " [" << self.name << " ]\n "
33
- << " previous number: " << self.previous_number << " \n "
34
- << " current number: " << self.current_number << " \n "
35
- << " iteration: " << self.iteration << " \n " ;
36
- return oss.str ();
37
- });
38
- };
35
+ size_t INITIALIZE_ID = MoniLogger::register_base_event(INITIALIZE);
36
+ size_t ITERATE_ID = MoniLogger::register_base_event(ITERATE);
37
+ size_t FINALIZE_ID = MoniLogger::register_base_event(FINALIZE);
39
38
40
- // Define base execution events emitted by the application, to which moniloggers can register.
41
- MoniLogger::register_base_event (INITIALIZE);
42
- MoniLogger::register_base_event (ITERATE);
43
- MoniLogger::register_base_event (FINALIZE) ;
39
+ void initialize (std::vector<std::string> python_path, std::vector<std::string> python_scripts)
40
+ {
41
+ // Name of the interface module (here, an embedded module declared above) exposing the execution context of the application.
42
+ std::string interface_module = " fibonacci_interface " ;
44
43
45
- // Bootstrapping monilogger, consisting of starting the Python interpreter, initializing
46
- // the monilogger module, and evaluating the provided scripts.
47
- MoniLogger::initialize_monilogger (python_path, python_scripts, interface_module, interface_module_initializer);
48
- }
44
+ // Bootstrapping monilogger, consisting of starting the Python interpreter, initializing
45
+ // the monilogger module, and evaluating the provided scripts.
46
+ MoniLogger::initialize_monilogger (python_path, python_scripts, interface_module);
47
+ }
48
+ }
0 commit comments