pool.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* --------------------------------------------------------------------- */
11 /* --- INCLUDE --------------------------------------------------------- */
12 /* --------------------------------------------------------------------- */
13 #include <list>
14 #ifdef WIN32
15 #include <time.h>
16 #endif /*WIN32*/
17 
18 /* --- SOT --- */
19 #include <dynamic-graph/entity.h>
20 
21 #include <sot/core/debug.hh>
23 #include <sot/core/pool.hh>
25 
26 namespace dynamicgraph {
27 namespace sot {
28 /* --------------------------------------------------------------------- */
29 /* --- CLASS ----------------------------------------------------------- */
30 /* --------------------------------------------------------------------- */
31 
33  sotDEBUGIN(15);
34 
35  sotDEBUGOUT(15);
36  return;
37 }
38 
39 /* --------------------------------------------------------------------- */
40 void PoolStorage::registerTask(const std::string &entname, TaskAbstract *ent) {
41  Tasks::iterator entkey = task.find(entname);
42  if (entkey != task.end()) // key does exist
43  {
45  "Another task already defined with the "
46  "same name. ",
47  "Task name is <%s>.", entname.c_str());
48  } else {
49  sotDEBUG(10) << "Register task <" << entname << "> in the pool."
50  << std::endl;
51  task[entname] = ent;
52  }
53 }
54 
55 TaskAbstract &PoolStorage::getTask(const std::string &name) {
56  Tasks::iterator entPtr = task.find(name);
57  if (entPtr == task.end()) {
59  "Unknown task.", " (while calling <%s>)",
60  name.c_str());
61  }
62  return *entPtr->second;
63 }
64 
65 /* --------------------------------------------------------------------- */
66 void PoolStorage::registerFeature(const std::string &entname,
67  FeatureAbstract *ent) {
68  Features::iterator entkey = feature.find(entname);
69  if (entkey != feature.end()) // key does exist
70  {
72  "Another feature already defined with the"
73  " same name. ",
74  "Feature name is <%s>.", entname.c_str());
75  } else {
76  sotDEBUG(10) << "Register feature <" << entname << "> in the pool."
77  << std::endl;
78  feature[entname] = ent;
79  }
80 }
81 
82 FeatureAbstract &PoolStorage::getFeature(const std::string &name) {
83  Features::iterator entPtr = feature.find(name);
84  if (entPtr == feature.end()) {
86  "Unknown feature.", " (while calling <%s>)",
87  name.c_str());
88  }
89  return *entPtr->second;
90 }
91 
92 void PoolStorage::writeGraph(const std::string &aFileName) {
93  size_t IdxPointFound = aFileName.rfind(".");
94  std::string tmp1 = aFileName.substr(0, IdxPointFound);
95  size_t IdxSeparatorFound = aFileName.rfind("/");
96  std::string GenericName;
97  if (IdxSeparatorFound != std::string::npos)
98  GenericName = tmp1.substr(IdxSeparatorFound, tmp1.length());
99  else
100  GenericName = tmp1;
101 
102  /* Reading local time */
103  time_t ltime;
104  ltime = time(NULL);
105  struct tm ltimeformatted;
106 #ifdef WIN32
107  localtime_s(&ltimeformatted, &ltime);
108 #else
109  localtime_r(&ltime, &ltimeformatted);
110 #endif /*WIN32*/
111 
112  /* Opening the file and writing the first comment. */
113  std::ofstream GraphFile;
114  GraphFile.open(aFileName.c_str(), std::ofstream::out);
115  GraphFile << "/* This graph has been automatically generated. " << std::endl;
116  GraphFile << " " << 1900 + ltimeformatted.tm_year
117  << " Month: " << 1 + ltimeformatted.tm_mon
118  << " Day: " << ltimeformatted.tm_mday
119  << " Time: " << ltimeformatted.tm_hour << ":"
120  << ltimeformatted.tm_min;
121  GraphFile << " */" << std::endl;
122  GraphFile << "digraph " << GenericName << " { ";
123  GraphFile << "\t graph [ label=\"" << GenericName
124  << "\" bgcolor = white rankdir=LR ]" << std::endl
125  << "\t node [ fontcolor = black, color = black, "
126  "fillcolor = gold1, style=filled, shape=box ] ; "
127  << std::endl;
128  GraphFile << "\tsubgraph cluster_Tasks { " << std::endl;
129  GraphFile << "\t\t color=blue; label=\"Tasks\";" << std::endl;
130 
131  for (Tasks::iterator iter = task.begin(); iter != task.end(); iter++) {
132  TaskAbstract *ent = iter->second;
133  GraphFile << "\t\t" << ent->getName() << " [ label = \"" << ent->getName()
134  << "\" ," << std::endl
135  << "\t\t fontcolor = black, color = black, "
136  "fillcolor = magenta, style=filled, shape=box ]"
137  << std::endl;
138  }
139 
140  GraphFile << "}" << std::endl;
141 
142  GraphFile.close();
143 }
144 
145 void PoolStorage::writeCompletionList(std::ostream & /*os*/) {}
146 
148  if (instance_ == 0) {
149  instance_ = new PoolStorage;
150  }
151  return instance_;
152 }
153 void PoolStorage::destroy() {
154  delete instance_;
155  instance_ = 0;
156 }
157 
159 
161 } // namespace sot
162 } // namespace dynamicgraph
#define SOT_THROW
void writeGraph(const std::string &aFileName)
Definition: pool.cpp:92
static PoolStorage * instance_
Definition: pool.cpp:160
#define sotDEBUGOUT(level)
Definition: debug.hh:212
#define sotDEBUGIN(level)
Definition: debug.hh:211
void writeCompletionList(std::ostream &os)
Definition: pool.cpp:145
static PoolStorage * getInstance()
Definition: pool.cpp:147
static void destroy()
Definition: pool.cpp:153
#define sotDEBUG(level)
Definition: debug.hh:165
This class gives the abstract definition of a feature.
const std::string & getName() const


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Wed Jun 21 2023 02:51:26