Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === header core.h ===
- class CoreImpl
- class Core
- {
- private:
- CoreImpl* impl; // Maybe even smart pointer
- public:
- Core();
- ~Core();
- // Note: Needs to handle copying correctly as well, or forbid it
- void foo();
- // more functions
- };
- ===== source core.cpp ======
- #include "core.h"
- #include <functional>
- #include <iostream>
- #include <string>
- #include <vector>
- #include <pybind11/pybind11.h>
- #include <pybind11/embed.h>
- #include <pybind11/stl.h>
- #include <pybind11/functional.h>
- #include <pybind11/numpy.h>
- namespace py = pybind11;
- using namespace py::literals;
- typedef void(*CallbackFn)(bool, std::string, py::array_t<uint8_t>&);
- typedef std::function<void(std::string)> LogFunction;
- class CoreImpl
- {
- private:
- py::scoped_interpreter guard{};
- py::object cls;
- py::object obj;
- py::object startFunc;
- py::object stopFunc;
- py::object setCpuAffinityFunc;
- py::object addCallbackFunc;
- py::object removeCallbackFunc;
- py::object getCallbacksFunc;
- py::dict kwargs;
- py::list callbackList;
- public:
- CoreImpl();
- void foo();
- // more functions
- };
- Core::Core()
- : impl(new CoreImpl())
- {
- }
- Core::~Core()
- {
- delete impl;
- }
- Core::foo()
- {
- impl->foo();
- }
- // And so on, forward all the interface calls to matching implementations
- CoreImpl::CoreImpl()
- {
- // all the code that was originally in Core
- }
- // And the rest of the member implementation -- none of this is visible to client.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement