Directory: | ./ |
---|---|
File: | src/python-module.cc |
Date: | 2024-08-13 12:13:25 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 39 | 63 | 61.9% |
Branches: | 44 | 144 | 30.6% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | #include <sot/core/device.hh> | ||
2 | #include <sot/core/flags.hh> | ||
3 | |||
4 | #include "dynamic-graph/python/module.hh" | ||
5 | #include "dynamic-graph/python/signal.hh" | ||
6 | |||
7 | namespace dg = dynamicgraph; | ||
8 | namespace dgs = dynamicgraph::sot; | ||
9 | |||
10 | typedef bp::return_value_policy<bp::reference_existing_object> | ||
11 | reference_existing_object; | ||
12 | |||
13 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
|
28 | BOOST_PYTHON_MODULE(wrap) { |
14 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | bp::import("dynamic_graph"); |
15 | |||
16 | using dgs::PeriodicCall; | ||
17 | 14 | bp::class_<PeriodicCall, boost::noncopyable>("PeriodicCall", bp::no_init) | |
18 | 28 | .def("addSignal", | |
19 | static_cast<void (PeriodicCall::*)(const std::string &, | ||
20 | dg::SignalBase<int> &)>( | ||
21 | &PeriodicCall::addSignal), | ||
22 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
28 | "Add the signal to the refresh list", (bp::arg("name"), "signal")) |
23 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("addSignal", |
24 | static_cast<void (PeriodicCall::*)(const std::string &)>( | ||
25 | &PeriodicCall::addSignal), | ||
26 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
28 | "Add the signal to the refresh list", (bp::arg("signal_name"))) |
27 | |||
28 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("addDownsampledSignal", |
29 | static_cast<void (PeriodicCall::*)( | ||
30 | const std::string &, dg::SignalBase<int> &, | ||
31 | const unsigned int &)>(&PeriodicCall::addDownsampledSignal), | ||
32 | "Add the signal to the refresh list\n" | ||
33 | "The downsampling factor: 1 means every time, " | ||
34 | "2 means every other time, etc...", | ||
35 |
3/6✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 7 times.
✗ Branch 8 not taken.
|
28 | (bp::arg("name"), "signal", "factor")) |
36 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("addDownsampledSignal", |
37 | static_cast<void (PeriodicCall::*)(const std::string &, | ||
38 | const unsigned int &)>( | ||
39 | &PeriodicCall::addDownsampledSignal), | ||
40 | "Add the signal to the refresh list\n" | ||
41 | "The downsampling factor: 1 means every time, " | ||
42 | "2 means every other time, etc...", | ||
43 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
28 | (bp::arg("signal_name"), "factor")) |
44 | |||
45 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
28 | .def("rmSignal", &PeriodicCall::rmSignal, |
46 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
28 | "Remove the signal to the refresh list", bp::arg("name")) |
47 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("clear", &PeriodicCall::clear, |
48 | "Clear all signals and commands from the refresh list.") | ||
49 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def( |
50 | ✗ | "__str__", +[](const PeriodicCall &e) { | |
51 | ✗ | std::ostringstream os; | |
52 | ✗ | e.display(os); | |
53 | ✗ | return os.str(); | |
54 | ✗ | }); | |
55 | |||
56 | 14 | dynamicgraph::python::exposeEntity<dgs::Device>() | |
57 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .add_property("after", bp::make_function(&dgs::Device::periodicCallAfter, |
58 | 14 | reference_existing_object())) | |
59 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .add_property("before", |
60 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
28 | bp::make_function(&dgs::Device::periodicCallBefore, |
61 | 14 | reference_existing_object())); | |
62 | |||
63 | using dgs::Flags; | ||
64 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | bp::class_<Flags>("Flags", bp::init<>()) |
65 |
2/4✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 7 times.
✗ Branch 5 not taken.
|
14 | .def(bp::init<const char *>()) |
66 |
2/4✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
|
28 | .def("__init__", bp::make_constructor(+[](bp::list bools) { |
67 | ✗ | std::vector<bool> flags(bp::len(bools)); | |
68 | ✗ | for (std::size_t i = 0; i < flags.size(); ++i) | |
69 | ✗ | flags[i] = bp::extract<bool>(bools[i]); | |
70 | ✗ | return new Flags(flags); | |
71 | ✗ | })) | |
72 |
2/4✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
|
28 | .def("__init__", bp::make_constructor(+[](bp::tuple bools) { |
73 | ✗ | std::vector<bool> flags(bp::len(bools)); | |
74 | ✗ | for (std::size_t i = 0; i < flags.size(); ++i) | |
75 | ✗ | flags[i] = bp::extract<bool>(bools[i]); | |
76 | ✗ | return new Flags(flags); | |
77 | ✗ | })) | |
78 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("add", &Flags::add) |
79 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("set", &Flags::set) |
80 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("unset", &Flags::unset) |
81 | |||
82 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def(bp::self & bp::self) |
83 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def(bp::self | bp::self) |
84 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def(bp::self &= bp::self) |
85 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def(bp::self |= bp::self) |
86 | |||
87 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("__call__", &Flags::operator()) |
88 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("__bool__", &Flags::operator bool) |
89 |
1/2✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
|
14 | .def("reversed", &Flags::operator!) |
90 | |||
91 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def( |
92 | "set", | ||
93 | ✗ | +[](Flags &f, const std::string &s) { | |
94 | ✗ | std::istringstream is(s); | |
95 | ✗ | is >> f; | |
96 | ✗ | }) | |
97 |
1/2✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
|
14 | .def( |
98 | ✗ | "__str__", +[](const Flags &f) { | |
99 | ✗ | std::ostringstream os; | |
100 | ✗ | os << f; | |
101 | ✗ | return os.str(); | |
102 | ✗ | }); | |
103 | |||
104 |
2/4✓ Branch 2 taken 7 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 7 times.
✗ Branch 6 not taken.
|
14 | dg::python::exposeSignalsOfType<Flags, int>("Flags"); |
105 | 14 | } | |
106 |