User Guide
pyembed.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2023 Blue Brain Project, EPFL.
3  * See the top-level LICENSE file for details.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #pragma once
9 
10 #include "wrapper.hpp"
11 
12 namespace nmodl {
13 namespace pybind_wrappers {
14 
15 /**
16  * A singleton class handling access to the pybind_wrap_api struct
17  *
18  * This class manages the runtime loading of the libpython so/dylib file and the python binding
19  * wrapper library and provides access to the API wrapper struct that can be used to access the
20  * pybind11 embedded python functionality.
21  */
23  public:
24  /**
25  * Construct (if not already done) and get the only instance of this class
26  *
27  * @return the EmbeddedPythonLoader singleton instance
28  */
30  static EmbeddedPythonLoader instance;
31 
32  return instance;
33  }
34 
36  void operator=(const EmbeddedPythonLoader&) = delete;
37 
38 
39  /**
40  * Get a pointer to the pybind_wrap_api struct
41  *
42  * Get access to the container struct for the pointers to the functions in the wrapper library.
43  * @return a pybind_wrap_api pointer
44  */
45  const pybind_wrap_api& api();
46 
48  unload();
49  }
50 
51  private:
53 
54  void* pylib_handle = nullptr;
55  void* pybind_wrapper_handle = nullptr;
56 
57  bool have_wrappers();
58  void load_libraries();
59  void populate_symbols();
60  void unload();
61 
63  if (!have_wrappers()) {
66  }
67  }
68 };
69 
70 
71 } // namespace pybind_wrappers
72 } // namespace nmodl
wrapper.hpp
nmodl::pybind_wrappers::EmbeddedPythonLoader::get_instance
static EmbeddedPythonLoader & get_instance()
Construct (if not already done) and get the only instance of this class.
Definition: pyembed.hpp:29
nmodl::pybind_wrappers::EmbeddedPythonLoader
A singleton class handling access to the pybind_wrap_api struct.
Definition: pyembed.hpp:22
nmodl
encapsulates code generation backend implementations
Definition: ast_common.hpp:26
nmodl::pybind_wrappers::EmbeddedPythonLoader::~EmbeddedPythonLoader
~EmbeddedPythonLoader()
Definition: pyembed.hpp:47
nmodl::pybind_wrappers::EmbeddedPythonLoader::pylib_handle
void * pylib_handle
Definition: pyembed.hpp:54
nmodl::pybind_wrappers::EmbeddedPythonLoader::load_libraries
void load_libraries()
Definition: pyembed.cpp:66
nmodl::pybind_wrappers::EmbeddedPythonLoader::populate_symbols
void populate_symbols()
Definition: pyembed.cpp:105
nmodl::pybind_wrappers::EmbeddedPythonLoader::operator=
void operator=(const EmbeddedPythonLoader &)=delete
nmodl::pybind_wrappers::EmbeddedPythonLoader::api
const pybind_wrap_api & api()
Get a pointer to the pybind_wrap_api struct.
Definition: pyembed.cpp:135
nmodl::pybind_wrappers::EmbeddedPythonLoader::unload
void unload()
Definition: pyembed.cpp:124
nmodl::pybind_wrappers::EmbeddedPythonLoader::pybind_wrapper_handle
void * pybind_wrapper_handle
Definition: pyembed.hpp:55
nmodl::pybind_wrappers::EmbeddedPythonLoader::EmbeddedPythonLoader
EmbeddedPythonLoader()
Definition: pyembed.hpp:62
nmodl::pybind_wrappers::pybind_wrap_api
Definition: wrapper.hpp:60
nmodl::pybind_wrappers::EmbeddedPythonLoader::wrappers
pybind_wrap_api wrappers
Definition: pyembed.hpp:52
nmodl::pybind_wrappers::EmbeddedPythonLoader::have_wrappers
bool have_wrappers()
Definition: pyembed.cpp:29