From a8112a37054387df92f7de0aa648bdfe48e876cd Mon Sep 17 00:00:00 2001 From: Noah Oblath Date: Wed, 15 Jun 2022 20:01:30 -0400 Subject: [PATCH 1/3] Added a macro to bind a MEMVAR --- Python/Bindings/NymphBindingHelpers.hh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Python/Bindings/NymphBindingHelpers.hh b/Python/Bindings/NymphBindingHelpers.hh index 5d47ffe..c06030c 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,11 @@ #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_MEMVAR( name, getter, setter ) \ + property( name, &getter, &setter ) + #endif /* NYMPH_PYBIND_BINDING_HELPERS */ From a2aebab3839a0601175aea5c44a5b645c8bdf719 Mon Sep 17 00:00:00 2001 From: Pranava Teja Surukuchi Date: Tue, 21 Jun 2022 17:00:36 -0400 Subject: [PATCH 2/3] Added binding for MEMVARS --- Python/Bindings/CMakeLists.txt | 1 + Python/Bindings/NymphBindingHelpers.hh | 45 ++++++++++++++++++++++- Python/Bindings/Processor/SignalPybind.hh | 13 +++++-- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Python/Bindings/CMakeLists.txt b/Python/Bindings/CMakeLists.txt index 6a97dea..62b7244 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 c06030c..7dc6f76 100644 --- a/Python/Bindings/NymphBindingHelpers.hh +++ b/Python/Bindings/NymphBindingHelpers.hh @@ -20,7 +20,50 @@ // Memvar Bindings //**************** -#define PROPERTY_MEMVAR( name, getter, setter ) \ +#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 663f590..f61af61 100644 --- a/Python/Bindings/Processor/SignalPybind.hh +++ b/Python/Bindings/Processor/SignalPybind.hh @@ -35,10 +35,15 @@ namespace NymphPybind .def("connect", &Nymph::Signal< XArgs...>::Connect, NYMPH_BIND_CALL_GUARD_STREAMS) .def("disconnect", &Nymph::Signal< XArgs... >::Disconnect) .def("disconnect_all", &Nymph::Signal< XArgs... >::DisconnectAll) - .def_property_readonly("connections", static_cast< std::set< Nymph::SlotBase* >& (Nymph::Signal< XArgs... >::*)() const>(&Nymph::Signal< XArgs... >::Connections)) - .def_property("name", static_cast< const std::string& (Nymph::Signal< XArgs... >::*)() const>(&Nymph::Signal< XArgs... >::Name), - [](Nymph::Signal< XArgs... >& signal, const std::string& name){signal.Name() = name;} ) - .def_property("do_breakpoint", &Nymph::Signal< XArgs... >::GetDoBreakpoint, &Nymph::Signal< XArgs... >::SetDoBreakpoint); + 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, ) } From b491ba70376bf08c4a59805d97a0d6c59133fb23 Mon Sep 17 00:00:00 2001 From: Pranava Teja Surukuchi Date: Tue, 21 Jun 2022 17:21:10 -0400 Subject: [PATCH 3/3] Mmevar implementation for Accessibles and Referrables --- Python/Bindings/NymphBindingHelpers.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/Bindings/NymphBindingHelpers.hh b/Python/Bindings/NymphBindingHelpers.hh index 7dc6f76..175e148 100644 --- a/Python/Bindings/NymphBindingHelpers.hh +++ b/Python/Bindings/NymphBindingHelpers.hh @@ -65,5 +65,5 @@ #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 */