YARP
Yet Another Robot Platform
utility.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_UTILITY
10 #define YARP_MANAGER_UTILITY
11 
12 #include <algorithm>
13 #include <cctype>
14 #include <string>
15 #include <vector>
16 #include <cstring>
17 #include <iostream>
18 #include <sstream>
19 
20 #include <yarp/manager/ymm-types.h>
21 
22 namespace yarp {
23 namespace manager {
24 
25 
26 class StrStream
27 {
28 public:
30  StrStream(const std::string str);
32  std::string str();
34  StrStream& operator<<(const std::string &str);
35  StrStream& operator<<(int n);
36  StrStream& operator<<(double n);
37  StrStream& operator = (const char* sz);
38  StrStream& operator = (char* sz);
39  StrStream& operator = (const std::string &str);
41  StrStream& operator = (int n);
42  friend std::ostream& operator << (std::ostream &os , StrStream& sstr);
43 
44 private:
45  std::string dummyStr;
46 };
47 
48 
49 #if defined(_MSC_VER) && (_MSC_VER == 1600)
50  typedef StrStream OSTRINGSTREAM;
51 #else
52  typedef std::stringstream OSTRINGSTREAM;
53 #endif
54 
55 
60 {
61 public:
62  static ErrorLogger* Instance();
63 
64  void addWarning(const char* szWarning);
65  void addWarning(const std::string &str);
66  void addWarning(OSTRINGSTREAM &stream);
67  void addError(const char* szError);
68  void addError(const std::string &str);
69  void addError(OSTRINGSTREAM &stream);
70  const char* getLastError();
71  const char* getLastWarning();
72  const char* getFormatedErrorString();
73  const char* getFormatedWarningString();
74  void clear();
75  int errorCount();
76  int warningCount();
77 
78 private:
79  ErrorLogger(){}
80  ErrorLogger(ErrorLogger const&){}
81  std::vector<std::string> errors;
82  std::vector<std::string> warnings;
83 };
84 
85 
86 bool compareString(const char* szFirst, const char* szSecond);
87 void trimString(std::string& str);
88 OS strToOS(const char* szOS);
89 
90 class Graph;
91 bool exportDotGraph(Graph& graph, const char* szFileName);
92 
93 } // namespace yarp
94 } // namespace manager
95 
96 
97 #endif // __YARP_MANAGER_UTILITY__
Singleton class ErrorLogger.
Definition: utility.h:60
const char * getLastError()
Definition: utility.cpp:134
const char * getFormatedErrorString()
Definition: utility.cpp:143
void addError(const char *szError)
Definition: utility.cpp:121
void addWarning(const char *szWarning)
Definition: utility.cpp:108
static ErrorLogger * Instance()
Singleton class ErrorLogger.
Definition: utility.cpp:102
const char * getLastWarning()
Definition: utility.cpp:151
const char * getFormatedWarningString()
Definition: utility.cpp:160
Class Graph.
Definition: graph.h:31
StrStream & operator<<(StrStream &oss)
Definition: utility.cpp:37
std::string str()
Definition: utility.cpp:33
StrStream & operator=(const char *sz)
Definition: utility.cpp:62
bool compareString(const char *szFirst, const char *szSecond)
Definition: utility.cpp:305
void trimString(std::string &str)
Definition: utility.cpp:323
std::stringstream OSTRINGSTREAM
Definition: utility.h:52
OS strToOS(const char *szOS)
Definition: utility.cpp:290
bool exportDotGraph(Graph &graph, const char *szFileName)
Definition: utility.cpp:337
enum yarp::manager::__OS OS
The main, catch-all namespace for YARP.
Definition: environment.h:25