OpenPose  1.7.0
The first real-time multi-person system to jointly detect human body, hand, facial, and foot keypoints
errorAndLog.hpp
Go to the documentation of this file.
1 #ifndef OPENPOSE_UTILITIES_ERROR_AND_LOG_HPP
2 #define OPENPOSE_UTILITIES_ERROR_AND_LOG_HPP
3 
4 #include <sstream> // std::stringstream
5 #include <string>
6 #include <vector>
9 
10 namespace op
11 {
13 
14  OP_API std::string getThreadId();
15 
17 
19 
20  template<typename T>
21  std::string tToString(const T& message)
22  {
23  // Message -> ostringstream
24  std::ostringstream oss;
25  oss << message;
26  // ostringstream -> std::string
27  return oss.str();
28  }
29 
39  // Error management - How to use:
40  // error(message, __LINE__, __FUNCTION__, __FILE__);
41  OP_API void error(
42  const std::string& message, const int line = -1, const std::string& function = "",
43  const std::string& file = "");
44 
45  template<typename T>
46  inline void error(
47  const T& message, const int line = -1, const std::string& function = "", const std::string& file = "")
48  {
49  error(tToString(message), line, function, file);
50  }
51 
52  // Worker error management
54 
56  const std::string& message, const int line = -1, const std::string& function = "",
57  const std::string& file = "");
58 
59  template<typename T>
60  inline void errorWorker(
61  const T& message, const int line = -1, const std::string& function = "", const std::string& file = "")
62  {
63  errorWorker(tToString(message), line, function, file);
64  }
65 
66  // Destructor error management
68  const std::string& message, const int line = -1, const std::string& function = "",
69  const std::string& file = "");
70 
71  template<typename T>
72  inline void errorDestructor(
73  const T& message, const int line = -1, const std::string& function = "", const std::string& file = "")
74  {
75  errorDestructor(tToString(message), line, function, file);
76  }
77 
78  // Printing info - How to use:
79  // It will print info if desiredPriority >= sPriorityThreshold
80  // opLog(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__);
81  OP_API void opLog(
82  const std::string& message, const Priority priority = Priority::Max, const int line = -1,
83  const std::string& function = "", const std::string& file = "");
84 
85  template<typename T>
86  inline void opLog(
87  const T& message, const Priority priority = Priority::Max, const int line = -1,
88  const std::string& function = "", const std::string& file = "")
89  {
90  opLog(tToString(message), priority, line, function, file);
91  }
92 
93  // If only desired on debug mode (no computational cost at all on release mode):
94  // It will print info if desiredPriority >= sPriorityThreshold
95  // opLogIfDebug(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__);
96  template<typename T>
97  inline void opLogIfDebug(
98  const T& message, const Priority priority = Priority::Max, const int line = -1,
99  const std::string& function = "", const std::string& file = "")
100  {
101  #ifndef NDEBUG
102  opLog(message, priority, line, function, file);
103  #else
104  UNUSED(message);
105  UNUSED(priority);
106  UNUSED(line);
107  UNUSED(function);
108  UNUSED(file);
109  #endif
110  }
111 
112  // This class is thread-safe
113  namespace ConfigureError
114  {
115  OP_API std::vector<ErrorMode> getErrorModes();
116 
117  OP_API void setErrorModes(const std::vector<ErrorMode>& errorModes);
118  }
119 
120  // This class is not fully thread-safe
121  namespace ConfigureLog
122  {
124 
125  OP_API const std::vector<LogMode>& getLogModes();
126 
127  // This function is not thread-safe. It must be run at the beginning
128  OP_API void setPriorityThreshold(const Priority priorityThreshold);
129 
130  // This function is not thread-safe. It must be run at the beginning
131  OP_API void setLogModes(const std::vector<LogMode>& loggingModes);
132  }
133 }
134 
135 #endif // OPENPOSE_UTILITIES_ERROR_AND_LOG_HPP
#define OP_API
Definition: macros.hpp:18
#define UNUSED(unusedVariable)
Definition: macros.hpp:30
OP_API void setErrorModes(const std::vector< ErrorMode > &errorModes)
OP_API std::vector< ErrorMode > getErrorModes()
OP_API Priority getPriorityThreshold()
OP_API void setPriorityThreshold(const Priority priorityThreshold)
OP_API void setLogModes(const std::vector< LogMode > &loggingModes)
OP_API const std::vector< LogMode > & getLogModes()
OP_API std::string getThreadId()
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
OP_API void errorWorker(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
OP_API void setMainThread()
OP_API void errorDestructor(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
OP_API void checkWorkerErrors()
void opLogIfDebug(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:97
OP_API void opLog(const std::string &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
OP_API bool getIfNotInMainThreadOrEmpty()
OP_API bool getIfInMainThreadOrEmpty()
Priority
Definition: enumClasses.hpp:22
std::string tToString(const T &message)
Definition: errorAndLog.hpp:21