diff --git a/Python/Bindings/CMakeLists.txt b/Python/Bindings/CMakeLists.txt index c64a4e2..653f918 100644 --- a/Python/Bindings/CMakeLists.txt +++ b/Python/Bindings/CMakeLists.txt @@ -14,6 +14,7 @@ include_directories( BEFORE # Python binding headers set( PYBINDING_HEADERFILES + NymphBindingHelpers.hh Data/DataPybind.hh Processor/ProcessorPybind.hh Processor/ProcessorRegistrar.hh diff --git a/Python/Bindings/NymphBindingHelpers.hh b/Python/Bindings/NymphBindingHelpers.hh index 5d47ffe..175e148 100644 --- a/Python/Bindings/NymphBindingHelpers.hh +++ b/Python/Bindings/NymphBindingHelpers.hh @@ -3,6 +3,10 @@ #include "pybind11/iostream.h" +//************ +// Call guards +//************ + #define NYMPH_BIND_CALL_GUARD_STREAMS \ pybind11::call_guard< pybind11::scoped_ostream_redirect, pybind11::scoped_estream_redirect >() @@ -12,4 +16,54 @@ #define NYMPH_BIND_CALL_GUARD_STREAMS_AND_GIL \ pybind11::call_guard< pybind11::scoped_ostream_redirect, pybind11::scoped_estream_redirect, pybind11::gil_scoped_release >() +//**************** +// Memvar Bindings +//**************** + +#define PROPERTY( name, getter, setter ) \ + property( name, &getter, &setter ) + + +//Accessibles begin +#define MEMVAR_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property(#PYNAME, &CLNAME::Get##MEMNAME, &CLNAME::Set##MEMNAME) + +#define MEMVAR_NOSET_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property_readonly(#PYNAME, &CLNAME::##MEMNAME) + +#define MEMVAR_STATIC_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property_static(#PYNAME, &CLNAME::##MEMNAME) + +#define MEMVAR_STATIC_NOSET_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property_readonly_static(#PYNAME, &CLNAME::##MEMNAME) + +// The following macros assumes that MEMVAR_MUTABLE == MEMVAR and MEMVAR_MUTABLE_NOSET == MEMVAR_NOSET for pythonic purposes +#define MEMVAR_MUTABLE_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property(#PYNAME, &CLNAME::Get##MEMNAME, &CLNAME::Set##MEMNAME) + +#define MEMVAR_MUTABLE_NOSET_PY(PYNAME, MEMNAME, CLNAME) \ + .def_property_readonly(#PYNAME, &CLNAME::##MEMNAME) + +//Accessibles begin + +//Referrables begin +#define MEMVAR_REF_PY(PYNAME, MEMNAME, RETTYPE, CLNAME) \ + .def_property(#PYNAME, static_cast< const RETTYPE& (CLNAME::*)() const>(&CLNAME::MEMNAME),\ + [](CLNAME& anObject, const RETTYPE& aMember){anObject.MEMNAME() = aMember;} ) + +#define MEMVAR_REF_CONST_PY(PYNAME, MEMNAME, RETTYPE, CLNAME) \ + .def_property_readonly(PYNAME, static_cast< const RETTYPE& (CLNAME::*)() const>(&CLNAME::MEMNAME)) + +#define MEMVAR_REF_STATIC_PY(PYNAME, MEMNAME, RETTYPE, CLNAME) \ + .def_property_readonly_static(PYNAME, static_cast< RETTYPE& (CLNAME::*)()>(&CLNAME::MEMNAME)) + +// The following macro assumes that MEMVAR_REF_MUTABLE macro is equivalent to MEMVAR_REF for pythonic purposes +#define MEMVAR_REF_MUTABLE_PY(PYNAME, MEMNAME, RETTYPE, CLNAME) \ + .def_property(#PYNAME, static_cast< RETTYPE& (CLNAME::*)() const>(&CLNAME::MEMNAME),\ + [](CLNAME& anObject, const RETTYPE& aMember){anObject.MEMNAME() = aMember;} ) + +#define MEMVAR_REF_MUTABLE_CONST_PY(PYNAME, MEMNAME, RETTYPE, CLNAME) \ + .def_property_readonly(PYNAME, static_cast< RETTYPE& (CLNAME::*)() const>(&CLNAME::MEMNAME)) +//Referrables end + #endif /* NYMPH_PYBIND_BINDING_HELPERS */ diff --git a/Python/Bindings/Processor/SignalPybind.hh b/Python/Bindings/Processor/SignalPybind.hh index 188a56b..2811cd2 100644 --- a/Python/Bindings/Processor/SignalPybind.hh +++ b/Python/Bindings/Processor/SignalPybind.hh @@ -65,7 +65,19 @@ namespace NymphPybind .def(py::init()) .def(py::init()) .def("emit", &Nymph::Signal< XArgs... >::Emit, NYMPH_BIND_CALL_GUARD_STREAMS) - .def("__call__", &Nymph::Signal< XArgs... >::operator(), NYMPH_BIND_CALL_GUARD_STREAMS); + .def("__call__", &Nymph::Signal< XArgs... >::operator(), NYMPH_BIND_CALL_GUARD_STREAMS) + .def("connect", &Nymph::Signal< XArgs...>::Connect, NYMPH_BIND_CALL_GUARD_STREAMS) + .def("disconnect", &Nymph::Signal< XArgs... >::Disconnect) + .def("disconnect_all", &Nymph::Signal< XArgs... >::DisconnectAll) + MEMVAR_REF_MUTABLE_CONST_PY("connections", Connections, std::set< Nymph::SlotBase* >, Nymph::Signal< XArgs... >) + // .def_property_readonly("connections", static_cast< std::set< Nymph::SlotBase* >& (Nymph::Signal< XArgs... >::*)() const>(&Nymph::Signal< XArgs... >::Connections)) + MEMVAR_REF_PY("name", Name, std::string, Nymph::Signal< XArgs... >) + // .def_property("name", static_cast< const std::string& (Nymph::Signal< XArgs... >::*)() const>(&Nymph::Signal< XArgs... >::Name), + // [](Nymph::Signal< XArgs... >& aName, const std::string& name){aName.Name() = name;} ) + MEMVAR_PY("do_breakpoint", DoBreakpoint, Nymph::Signal< XArgs... >); + // .def_PROPERTY("do_breakpoint", Nymph::SignalBase::GetDoBreakpoint, Nymph::SignalBase::SetDoBreakpoint); + // MEMVAR(bool, DoBreakpoint) + // MEMVAR_Py(DoBreakpoint, ) }