Skip to content

Commit 78ee4f1

Browse files
jmirabelnim65s
authored andcommitted
[Python] Expose Flags and signal of Flags
1 parent 182c7fa commit 78ee4f1

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/python-module.cc

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "dynamic-graph/python/module.hh"
2+
#include "dynamic-graph/python/signal.hh"
23

34
#include <sot/core/device.hh>
5+
#include <sot/core/flags.hh>
46

57
namespace dg = dynamicgraph;
68
namespace dgs = dynamicgraph::sot;
@@ -44,4 +46,35 @@ BOOST_PYTHON_MODULE(wrap)
4446
.def_readonly("before",
4547
bp::make_function(&dgs::Device::periodicCallBefore, reference_existing_object()))
4648
;
49+
50+
using dgs::Flags;
51+
bp::class_<Flags>("Flags", bp::init<const bool&>())
52+
.def(bp::init<const char&>())
53+
.def(bp::init<const int &>())
54+
.def("add", static_cast<void(Flags::*)(const char&)>(&Flags::add))
55+
.def("add", static_cast<void(Flags::*)(const int &)>(&Flags::add))
56+
.def("set", &Flags::set)
57+
.def("unset", &Flags::unset)
58+
59+
.def(bp::self & bool())
60+
.def(bp::self | bool())
61+
.def(bp::self &= bool())
62+
.def(bp::self |= bool())
63+
64+
.def("__call__", &Flags::operator())
65+
.def("__bool__", &Flags::operator bool)
66+
.def("reversed", &Flags::operator!)
67+
68+
.def("set", +[](Flags& f, const std::string& s) {
69+
std::istringstream is (s);
70+
is >> f;
71+
})
72+
.def("__str__", +[](const Flags& f) {
73+
std::ostringstream os;
74+
os << f;
75+
return os.str();
76+
})
77+
;
78+
79+
dg::python::exposeSignalsOfType<Flags, int>("Flags");
4780
}

0 commit comments

Comments
 (0)