Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nymph2 2/memvarbindings #64

Open
wants to merge 5 commits into
base: nymph2_2/workshop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Python/Bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ include_directories( BEFORE

# Python binding headers
set( PYBINDING_HEADERFILES
NymphBindingHelpers.hh
Data/DataPybind.hh
Processor/ProcessorPybind.hh
Processor/ProcessorRegistrar.hh
Expand Down
54 changes: 54 additions & 0 deletions Python/Bindings/NymphBindingHelpers.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 >()

Expand All @@ -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 */
14 changes: 13 additions & 1 deletion Python/Bindings/Processor/SignalPybind.hh
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,19 @@ namespace NymphPybind
.def(py::init<const std::string& >())
.def(py::init<const std::string&, Nymph::Processor* >())
.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, )

}

Expand Down