@@ -79,145 +79,145 @@ namespace dynamicgraph {
7979 #define SEND_ERROR_STREAM_MSG (msg ) SEND_MSG(msg,MSG_TYPE_ERROR_STREAM)
8080#endif
8181
82- /* * Enum representing the different kind of messages.
83- */
84- enum MsgType
85- {
86- MSG_TYPE_DEBUG =0 ,
87- MSG_TYPE_INFO =1 ,
88- MSG_TYPE_WARNING =2 ,
89- MSG_TYPE_ERROR =3 ,
90- MSG_TYPE_DEBUG_STREAM =4 ,
91- MSG_TYPE_INFO_STREAM =5 ,
92- MSG_TYPE_WARNING_STREAM =6 ,
93- MSG_TYPE_ERROR_STREAM =7
94- };
95-
96- template <typename T>
97- std::string toString (const T& v, const int precision=3 , const int width=-1 )
98- {
99- std::stringstream ss;
100- if (width>precision)
101- ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v;
102- else
103- ss<<std::fixed<<std::setprecision (precision)<<v;
104- return ss.str ();
105- }
106-
107- template <typename T>
108- std::string toString (const std::vector<T>& v, const int precision=3 , const int width=-1 ,
109- const std::string separator=" , " )
110- {
111- std::stringstream ss;
112- if (width>precision)
113- {
114- for (int i=0 ; i<v.size ()-1 ; i++)
115- ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[i]<<separator;
116- ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[v.size ()-1 ];
117- }
118- else
119- {
120- for (int i=0 ; i<v.size ()-1 ; i++)
121- ss<<std::fixed<<std::setprecision (precision)<<v[i]<<separator;
122- ss<<std::fixed<<std::setprecision (precision)<<v[v.size ()-1 ];
123- }
124-
125- return ss.str ();
126- }
82+ /* * Enum representing the different kind of messages.
83+ */
84+ enum MsgType
85+ {
86+ MSG_TYPE_DEBUG =0 ,
87+ MSG_TYPE_INFO =1 ,
88+ MSG_TYPE_WARNING =2 ,
89+ MSG_TYPE_ERROR =3 ,
90+ MSG_TYPE_DEBUG_STREAM =4 ,
91+ MSG_TYPE_INFO_STREAM =5 ,
92+ MSG_TYPE_WARNING_STREAM =6 ,
93+ MSG_TYPE_ERROR_STREAM =7
94+ };
95+
96+ template <typename T>
97+ std::string toString (const T& v, const int precision=3 , const int width=-1 )
98+ {
99+ std::stringstream ss;
100+ if (width>precision)
101+ ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v;
102+ else
103+ ss<<std::fixed<<std::setprecision (precision)<<v;
104+ return ss.str ();
105+ }
106+
107+ template <typename T>
108+ std::string toString (const std::vector<T>& v, const int precision=3 , const int width=-1 ,
109+ const std::string separator=" , " )
110+ {
111+ std::stringstream ss;
112+ if (width>precision)
113+ {
114+ for (int i=0 ; i<v.size ()-1 ; i++)
115+ ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[i]<<separator;
116+ ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[v.size ()-1 ];
117+ }
118+ else
119+ {
120+ for (int i=0 ; i<v.size ()-1 ; i++)
121+ ss<<std::fixed<<std::setprecision (precision)<<v[i]<<separator;
122+ ss<<std::fixed<<std::setprecision (precision)<<v[v.size ()-1 ];
123+ }
124+
125+ return ss.str ();
126+ }
127127
128128// template<typename T, int N>
129129// std::string toString(const Eigen::Matrix<T, N, 1, 0, N, 1>& v, const std::string separator=", ",
130130// const int precision=3, const int width=-1)
131- template <typename T>
132- std::string toString (const Eigen::MatrixBase<T>& v,
133- const int precision=3 , const int width=-1 , const std::string separator=" , " )
134- {
135- std::stringstream ss;
136- if (width>precision)
137- {
138- for (int i=0 ; i<v.size ()-1 ; i++)
139- ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[i]<<separator;
140- ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[v.size ()-1 ];
141- }
142- else
143- {
144- for (int i=0 ; i<v.size ()-1 ; i++)
145- ss<<std::fixed<<std::setprecision (precision)<<v[i]<<separator;
146- ss<<std::setprecision (precision)<<v[v.size ()-1 ];
147- }
148-
149- return ss.str ();
150- }
151-
152- enum LoggerVerbosity
153- {
154- VERBOSITY_ALL,
155- VERBOSITY_INFO_WARNING_ERROR,
156- VERBOSITY_WARNING_ERROR,
157- VERBOSITY_ERROR,
158- VERBOSITY_NONE
159- };
160-
161- /* * A simple class for logging messages
162- */
163- class Logger
164- {
165- public:
166-
167- /* * Constructor */
168- Logger (double timeSample=0.001 , double streamPrintPeriod=1.0 );
169-
170- /* * Destructor */
171- ~Logger (){}
172-
173- /* * Method to be called at every control iteration
174- * to decrement the internal Logger's counter. */
175- void countdown ();
176-
177- /* * Print the specified message on standard output if the verbosity level
178- * allows it. The file name and the line number are used to identify
179- * the point where sendMsg is called so that streaming messages are
180- * printed only every streamPrintPeriod iterations.
181- */
182- void sendMsg (std::string msg, MsgType type, const char * file=" " , int line=0 );
183-
184- /* * Set the sampling time at which the method countdown()
185- * is going to be called. */
186- bool setTimeSample (double t);
187-
188- /* * Set the time period for printing of streaming messages. */
189- bool setStreamPrintPeriod (double s);
190-
191- /* * Set the verbosity level of the logger. */
192- void setVerbosity (LoggerVerbosity lv);
193-
194- protected:
195- LoggerVerbosity m_lv; // / verbosity of the logger
196- double m_timeSample; // / specify the period of call of the countdown method
197- double m_streamPrintPeriod; // / specify the time period of the stream prints
198- double m_printCountdown; // / every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
199-
200- /* * Pointer to the dynamic structure which holds the collection of streaming messages */
201- std::map<std::string, double > m_stream_msg_counters;
202-
203- bool isStreamMsg (MsgType m)
204- { return m==MSG_TYPE_ERROR_STREAM || m==MSG_TYPE_DEBUG_STREAM || m==MSG_TYPE_INFO_STREAM || m==MSG_TYPE_WARNING_STREAM; }
205-
206- bool isDebugMsg (MsgType m)
207- { return m==MSG_TYPE_DEBUG_STREAM || m==MSG_TYPE_DEBUG; }
208-
209- bool isInfoMsg (MsgType m)
210- { return m==MSG_TYPE_INFO_STREAM || m==MSG_TYPE_INFO; }
211-
212- bool isWarningMsg (MsgType m)
213- { return m==MSG_TYPE_WARNING_STREAM || m==MSG_TYPE_WARNING; }
214-
215- bool isErrorMsg (MsgType m)
216- { return m==MSG_TYPE_ERROR_STREAM || m==MSG_TYPE_ERROR; }
217- };
218-
219- /* * Method to get the logger (singleton). */
220- Logger& getLogger ();
131+ template <typename T>
132+ std::string toString (const Eigen::MatrixBase<T>& v,
133+ const int precision=3 , const int width=-1 , const std::string separator=" , " )
134+ {
135+ std::stringstream ss;
136+ if (width>precision)
137+ {
138+ for (int i=0 ; i<v.size ()-1 ; i++)
139+ ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[i]<<separator;
140+ ss<<std::fixed<<std::setw (width)<<std::setprecision (precision)<<v[v.size ()-1 ];
141+ }
142+ else
143+ {
144+ for (int i=0 ; i<v.size ()-1 ; i++)
145+ ss<<std::fixed<<std::setprecision (precision)<<v[i]<<separator;
146+ ss<<std::setprecision (precision)<<v[v.size ()-1 ];
147+ }
148+
149+ return ss.str ();
150+ }
151+
152+ enum LoggerVerbosity
153+ {
154+ VERBOSITY_ALL,
155+ VERBOSITY_INFO_WARNING_ERROR,
156+ VERBOSITY_WARNING_ERROR,
157+ VERBOSITY_ERROR,
158+ VERBOSITY_NONE
159+ };
160+
161+ /* * A simple class for logging messages
162+ */
163+ class Logger
164+ {
165+ public:
166+
167+ /* * Constructor */
168+ Logger (double timeSample=0.001 , double streamPrintPeriod=1.0 );
169+
170+ /* * Destructor */
171+ ~Logger (){}
172+
173+ /* * Method to be called at every control iteration
174+ * to decrement the internal Logger's counter. */
175+ void countdown ();
176+
177+ /* * Print the specified message on standard output if the verbosity level
178+ * allows it. The file name and the line number are used to identify
179+ * the point where sendMsg is called so that streaming messages are
180+ * printed only every streamPrintPeriod iterations.
181+ */
182+ void sendMsg (std::string msg, MsgType type, const char * file=" " , int line=0 );
183+
184+ /* * Set the sampling time at which the method countdown()
185+ * is going to be called. */
186+ bool setTimeSample (double t);
187+
188+ /* * Set the time period for printing of streaming messages. */
189+ bool setStreamPrintPeriod (double s);
190+
191+ /* * Set the verbosity level of the logger. */
192+ void setVerbosity (LoggerVerbosity lv);
193+
194+ protected:
195+ LoggerVerbosity m_lv; // / verbosity of the logger
196+ double m_timeSample; // / specify the period of call of the countdown method
197+ double m_streamPrintPeriod; // / specify the time period of the stream prints
198+ double m_printCountdown; // / every time this is < 0 (i.e. every _streamPrintPeriod sec) print stuff
199+
200+ /* * Pointer to the dynamic structure which holds the collection of streaming messages */
201+ std::map<std::string, double > m_stream_msg_counters;
202+
203+ bool isStreamMsg (MsgType m)
204+ { return m==MSG_TYPE_ERROR_STREAM || m==MSG_TYPE_DEBUG_STREAM || m==MSG_TYPE_INFO_STREAM || m==MSG_TYPE_WARNING_STREAM; }
205+
206+ bool isDebugMsg (MsgType m)
207+ { return m==MSG_TYPE_DEBUG_STREAM || m==MSG_TYPE_DEBUG; }
208+
209+ bool isInfoMsg (MsgType m)
210+ { return m==MSG_TYPE_INFO_STREAM || m==MSG_TYPE_INFO; }
211+
212+ bool isWarningMsg (MsgType m)
213+ { return m==MSG_TYPE_WARNING_STREAM || m==MSG_TYPE_WARNING; }
214+
215+ bool isErrorMsg (MsgType m)
216+ { return m==MSG_TYPE_ERROR_STREAM || m==MSG_TYPE_ERROR; }
217+ };
218+
219+ /* * Method to get the logger (singleton). */
220+ Logger& getLogger ();
221221
222222 } // namespace sot
223223} // namespace dynamicgraph
0 commit comments