GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/python/signal.hh Lines: 19 19 100.0 %
Date: 2022-09-30 08:22:45 Branches: 7 14 50.0 %

Line Branch Exec Source
1
// Copyright 2020, Joseph Mirabel, LAAS-CNRS.
2
3
#include <dynamic-graph/signal-base.h>
4
#include <dynamic-graph/signal-ptr.h>
5
#include <dynamic-graph/signal-time-dependent.h>
6
#include <dynamic-graph/signal.h>
7
8
#include <boost/python.hpp>
9
#include <sstream>
10
11
#include "dynamic-graph/python/signal-wrapper.hh"
12
13
namespace dynamicgraph {
14
namespace python {
15
16
template <typename T, typename Time>
17
44
auto exposeSignal(const std::string& name) {
18
  namespace bp = boost::python;
19
20
  typedef Signal<T, Time> S_t;
21
44
  bp::class_<S_t, bp::bases<SignalBase<Time> >, boost::noncopyable> obj(
22
      name.c_str(), bp::init<std::string>());
23

44
  obj.add_property(
24
      "value",
25
      bp::make_function(&S_t::accessCopy,
26
                        bp::return_value_policy<bp::copy_const_reference>()),
27
      &S_t::setConstant,  // TODO check the setter
28
      "the signal value.\n"
29
      "warning: for Eigen objects, sig.value[0] = 1. may not work).");
30
44
  return obj;
31
}
32
33
template <typename T, typename Time>
34
48
auto exposeSignalWrapper(const std::string& name) {
35
  namespace bp = boost::python;
36
37
  typedef SignalWrapper<T, Time> S_t;
38
48
  bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
39
      name.c_str(), bp::no_init);
40
48
  return obj;
41
}
42
43
template <typename T, typename Time>
44
48
auto exposeSignalPtr(const std::string& name) {
45
  namespace bp = boost::python;
46
47
  typedef SignalPtr<T, Time> S_t;
48
48
  bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
49
      name.c_str(), bp::no_init);
50
48
  return obj;
51
}
52
53
template <typename T, typename Time>
54
48
auto exposeSignalTimeDependent(const std::string& name) {
55
  namespace bp = boost::python;
56
57
  typedef SignalTimeDependent<T, Time> S_t;
58
48
  bp::class_<S_t, bp::bases<Signal<T, Time> >, boost::noncopyable> obj(
59
      name.c_str(), bp::no_init);
60
48
  return obj;
61
}
62
63
template <typename T, typename Time>
64
48
void exposeSignalsOfType(const std::string& name) {
65
48
  exposeSignal<T, Time>("Signal" + name);
66
48
  exposeSignalPtr<T, Time>("SignalPtr" + name);
67
48
  exposeSignalWrapper<T, Time>("SignalWrapper" + name);
68
48
  exposeSignalTimeDependent<T, Time>("SignalTimeDependent" + name);
69
48
}
70
71
}  // namespace python
72
}  // namespace dynamicgraph