GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/sot/core/latch.hh Lines: 0 29 0.0 %
Date: 2023-03-13 12:09:37 Branches: 0 62 0.0 %

Line Branch Exec Source
1
/*
2
 * Copyright 2017-, Rohan Budhiraja, Joseph Mirabel, CNRS
3
 *
4
 */
5
6
#ifndef __SOT_LATCH_H__
7
#define __SOT_LATCH_H__
8
9
/* --------------------------------------------------------------------- */
10
/* --- INCLUDE --------------------------------------------------------- */
11
/* --------------------------------------------------------------------- */
12
13
/* SOT */
14
#include <dynamic-graph/all-signals.h>
15
#include <dynamic-graph/command-bind.h>
16
#include <dynamic-graph/entity.h>
17
18
#include <sot/core/pool.hh>
19
20
/* STD */
21
#include <string>
22
23
namespace dynamicgraph {
24
namespace sot {
25
26
/* --------------------------------------------------------------------- */
27
/* --- CLASS ----------------------------------------------------------- */
28
/* --------------------------------------------------------------------- */
29
using dynamicgraph::Entity;
30
using dynamicgraph::command::docCommandVoid0;
31
using dynamicgraph::command::makeCommandVoid0;
32
33
class Latch : public Entity {
34
 public: /* --- SIGNAL --- */
35
  DYNAMIC_GRAPH_ENTITY_DECL();
36
  Signal<bool, int> outSOUT;
37
  Signal<bool, int> turnOnSOUT;
38
  Signal<bool, int> turnOffSOUT;
39
40
 protected:
41
  bool signalOutput;
42
  void turnOn() { signalOutput = true; }
43
  bool &turnOnLatch(bool &res, int) {
44
    res = signalOutput = true;
45
    return res;
46
  }
47
48
  void turnOff() { signalOutput = false; }
49
  bool &turnOffLatch(bool &res, int) {
50
    res = signalOutput = false;
51
    return res;
52
  }
53
54
  bool &latchOutput(bool &res, int) {
55
    res = signalOutput;
56
    return res;
57
  }
58
59
 public:
60
  Latch(const std::string &name)
61
      : Entity(name),
62
        outSOUT("Latch(" + name + ")::output(bool)::out"),
63
        turnOnSOUT("Latch(" + name + ")::output(bool)::turnOnSout"),
64
        turnOffSOUT("Latch(" + name + ")::output(bool)::turnOffSout") {
65
    outSOUT.setFunction(boost::bind(&Latch::latchOutput, this, _1, _2));
66
    turnOnSOUT.setFunction(boost::bind(&Latch::turnOnLatch, this, _1, _2));
67
    turnOffSOUT.setFunction(boost::bind(&Latch::turnOffLatch, this, _1, _2));
68
    signalOutput = false;
69
    signalRegistration(outSOUT << turnOnSOUT << turnOffSOUT);
70
    addCommand("turnOn",
71
               makeCommandVoid0(*this, &Latch::turnOn,
72
                                docCommandVoid0("Turn on the latch")));
73
    addCommand("turnOff",
74
               makeCommandVoid0(*this, &Latch::turnOff,
75
                                docCommandVoid0("Turn off the latch")));
76
  }
77
78
  virtual ~Latch(void){};
79
};
80
} /* namespace sot */
81
} /* namespace dynamicgraph */
82
83
#endif  // #ifndef __SOT_LATCH_H__