GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/entity.h Lines: 14 14 100.0 %
Date: 2023-03-15 12:04:10 Branches: 3 8 37.5 %

Line Branch Exec Source
1
// -*- mode: c++ -*-
2
// Copyright 2010, François Bleibel, Thomas Moulard, Olivier Stasse,
3
// JRL, CNRS/AIST.
4
//
5
6
#ifndef DYNAMIC_GRAPH_ENTITY_H
7
#define DYNAMIC_GRAPH_ENTITY_H
8
#include <dynamic-graph/dynamic-graph-api.h>
9
#include <dynamic-graph/exception-factory.h>
10
#include <dynamic-graph/logger.h>
11
#include <dynamic-graph/signal-array.h>
12
#include <dynamic-graph/signal-base.h>
13
14
#include <boost/noncopyable.hpp>
15
#include <dynamic-graph/fwd.hh>
16
#include <iosfwd>
17
#include <map>
18
#include <sstream>
19
#include <string>
20
21
/// \brief Helper macro for entity declaration.
22
///
23
/// This macro should be called in the declaration of all entities.
24
/// Example:
25
/// <code>
26
/// class A : public dynamicgraph::entity
27
/// {
28
///   DYNAMIC_GRAPH_ENTITY_DECL();
29
///
30
///   public:
31
//      // your class here
32
/// };
33
/// </code>
34
///
35
/// Caution: you *MUST* call DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN in the
36
/// associated source file to ensure that the attributes generated by
37
/// this macro are correctly initialized.
38
#define DYNAMIC_GRAPH_ENTITY_DECL()                                      \
39
 public:                                                                 \
40
  virtual const std::string &getClassName() const { return CLASS_NAME; } \
41
  static const std::string CLASS_NAME
42
43
namespace dynamicgraph {
44
/// \ingroup dgraph
45
///
46
/// \brief This class represents an entity, i.e. a generic
47
/// computational unit that provides input and output signals.
48
///
49
/// These signals link the entities together to form a complete
50
/// computation graph.  To declare a new entity, please see the
51
/// DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN macro in factory.h.
52
class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable {
53
 public:
54
  typedef std::map<std::string, SignalBase<int> *> SignalMap;
55
  typedef std::map<const std::string, command::Command *> CommandMap_t;
56
57
  explicit Entity(const std::string &name);
58
  virtual ~Entity();
59
60
10
  const std::string &getName() const { return name; }
61
1
  virtual const std::string &getClassName() const {
62


1
    static std::string ret("Entity");
63
1
    return ret;
64
  }
65
  /** \brief Returns the Entity documentation
66
      \return The documentation is provided as std::string object.
67
   */
68
  virtual std::string getDocString() const;
69
70
  /** \brief Test if a signal of name signame is present.
71
      \return True if the signal is present, False otherwise
72
   */
73
  bool hasSignal(const std::string &signame) const;
74
75
  /** \brief Provides a reference to the signal named signalName.
76
      \param signalName: Name of the signal
77
      \return A reference to the signal with a temporal dependency.
78
   */
79
  SignalBase<int> &getSignal(const std::string &signalName);
80
81
  /** \brief Provides a const reference to the signal named signalName.
82
      \param signalName: Name of the signal
83
      \return A const reference to the signal with a temporal dependency.
84
   */
85
  const SignalBase<int> &getSignal(const std::string &signalName) const;
86
87
  /** \brief Display the list of signals of this entity in output stream os.
88
      \param os: the output stream where to display the list of signals.
89
      \returns The output stream given in parameter.
90
  */
91
  std::ostream &displaySignalList(std::ostream &os) const;
92
93
  /** \brief This method is used to write down in os the edges of the graph
94
      by calling the signals writeGraph method.
95
      \param os: The output stream where to write the informations.
96
      \return os: The output stream.
97
   */
98
  virtual std::ostream &writeGraph(std::ostream &os) const;
99
100
  /** \brief This method is used write in the output stream os the
101
      signals names and the commands of the entity.
102
      \param os: The output stream where to write the list of objects
103
      related to the entity.
104
   */
105
  virtual std::ostream &writeCompletionList(std::ostream &os) const;
106
107
  /** \brief Display information on the entity inside the output stream os.
108
   */
109
  virtual void display(std::ostream &os) const;
110
111
1
  virtual SignalBase<int> *test() { return 0; }
112
113
1
  virtual void test2(SignalBase<int> *) { return; }
114
115
  const std::string &getCommandList() const;
116
117
  /** \brief Provides the std::map where all the commands are registered
118
      \returns A map of pointers towards Command objects
119
  */
120
  CommandMap_t getNewStyleCommandMap();
121
  /** \brief Provides the pointer towards the Command object cmdName.
122
      \param cmdName: Name of the command
123
  */
124
  command::Command *getNewStyleCommand(const std::string &cmdName);
125
126
  /** \brief Provides a map of all the signals.
127
      \returns A copy of the map with all the pointers towards
128
      the entity signals.
129
   */
130
  SignalMap getSignalMap() const;
131
132
  /// \name Logger related methods
133
  /// \{
134
135
32000
  Logger &logger() { return logger_; };
136
  Logger const &logger() const { return logger_; };
137
138
  /// \brief Send messages \c msg with level \c t.
139
  /// Add string file and line to message.
140
  void sendMsg(const std::string &msg, MsgType t = MSG_TYPE_INFO,
141
               const std::string &lineId = "");
142
143
  /// \brief Specify the verbosity level of the logger.
144
8000
  void setLoggerVerbosityLevel(LoggerVerbosity lv) { logger_.setVerbosity(lv); }
145
146
  /// \brief Get the logger's verbosity level.
147
8000
  LoggerVerbosity getLoggerVerbosityLevel() { return logger_.getVerbosity(); }
148
149
  /// \brief Set the time sample.
150
1
  bool setTimeSample(double t) { return logger_.setTimeSample(t); }
151
152
  /// \brief Get the time sample.
153
1
  double getTimeSample() { return logger_.getTimeSample(); }
154
155
  /// \brief Set the period of the stream period
156
1
  bool setStreamPrintPeriod(double t) {
157
1
    return logger_.setStreamPrintPeriod(t);
158
  }
159
160
  /// \brief Get the period of the stream period
161
1
  double getStreamPrintPeriod() { return logger_.getStreamPrintPeriod(); }
162
163
  /// \}
164
165
 protected:
166
  void addCommand(const std::string &name, command::Command *command);
167
168
  void entityRegistration();
169
  void entityDeregistration();
170
171
  void signalRegistration(const SignalArray<int> &signals);
172
  void signalDeregistration(const std::string &name);
173
174
  std::string name;
175
  SignalMap signalMap;
176
  CommandMap_t commandMap;
177
  Logger logger_;
178
};
179
180
DYNAMIC_GRAPH_DLLAPI std::ostream &operator<<(std::ostream &os,
181
                                              const dynamicgraph::Entity &ent);
182
}  // end of namespace dynamicgraph
183
184
#endif  //! DYNAMIC_GRAPH_ENTITY_H