GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/dynamic-graph/pool.h Lines: 1 1 100.0 %
Date: 2023-03-15 12:04:10 Branches: 0 0 - %

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_POOL_H
7
#define DYNAMIC_GRAPH_POOL_H
8
#include <dynamic-graph/dynamic-graph-api.h>
9
#include <dynamic-graph/exception-factory.h>
10
#include <dynamic-graph/signal-base.h>
11
12
#include <dynamic-graph/fwd.hh>
13
#include <map>
14
#include <sstream>
15
#include <string>
16
17
namespace dynamicgraph {
18
/*! @ingroup dgraph
19
  \brief Singleton that keeps track of all the entities.
20
21
  This class gives access to and remembers all the entities created
22
  during its life.
23
24
  This class provides the necessary operations to register, unregister each
25
  instance of thoses classes.
26
  As tasks and features derived from Entities, they should be registered
27
  as such.
28
29
  \note From the code it is not very clear why we should not unregister
30
  from the tasks and the features...
31
32
*/
33
class DYNAMIC_GRAPH_DLLAPI PoolStorage {
34
 public:
35
  /*! \name Define types to simplify the writing
36
    @{
37
  */
38
  /*! \brief Sorted set of entities with unique key (name). */
39
  typedef std::map<std::string, Entity *> Entities;
40
41
  /// \brief Get unique instance of the class.
42
  static PoolStorage *getInstance();
43
44
  /// \brief Destroy the unique instance of the class
45
  static void destroy();
46
47
  /*! @} */
48
49
  /*! \brief Default destructor */
50
  ~PoolStorage();
51
52
  /*! \name Method related to the handling of entities.
53
    @{
54
  */
55
  /*! \brief Register an entity.
56
    \par[in] entname: The name of the entity,
57
    \par[in] ent: Pointer towards the entity.
58
  */
59
  void registerEntity(const std::string &entname, Entity *ent);
60
61
  /*! \brief Unregister an entity.
62
    \par[in] entname: The name of the entity,
63
  */
64
  void deregisterEntity(const std::string &entname);
65
66
  /*! \brief Unregister an entity.
67
    \par[in] entity: iterator in the map,
68
  */
69
  void deregisterEntity(const Entities::iterator &entity);
70
  /*! \brief Get an entity.
71
    \par[in] entname: The name of the entity,
72
    \return Pointer towards the entity.
73
  */
74
  Entity &getEntity(const std::string &name);
75
76
  /// Const access to entity map
77
  const Entities &getEntityMap() const;
78
79
  /*! \brief Test if the entity exists. */
80
  bool existEntity(const std::string &name);
81
  /*! \brief Test if the entity exists. If it does, return a pointer on it. */
82
  bool existEntity(const std::string &name, Entity *&ptr);
83
84
  /*! \brief Disallocate an entity.
85
    \par[in] entname: The name of the entity,
86
  */
87
  void clearPlugin(const std::string &name);
88
  /*! @} */
89
90
  ///
91
  /// \brief Get a signal by name
92
  ///
93
  /// \param sigpath stream containing a string of the form "entity.signal"
94
  SignalBase<int> &getSignal(std::istringstream &sigpath);
95
96
  /*! \brief This method write a graph description on the file named
97
      FileName. */
98
  void writeGraph(const std::string &aFileName);
99
  void writeCompletionList(std::ostream &os);
100
101
 protected:
102
  /*! \name Fields of the class to manage the three entities.
103
    Also the name is singular, those are true sets.
104
    @{
105
  */
106
  /*! \brief Set of basic objects of the SoT */
107
  Entities entityMap;
108
109
 private:
110
11
  PoolStorage() {}
111
  static PoolStorage *instance_;
112
};
113
114
inline PoolStorage &g_pool() { return *PoolStorage::getInstance(); }
115
116
}  // end of namespace dynamicgraph.
117
118
#endif  //! DYNAMIC_GRAPH_POOL_H