OpenPose  1.0.0rc2
OpenPose: A Real-Time Multi-Person Key-Point Detection And Multi-Threading C++ Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 <atomic>
5 #include <mutex>
6 #include <sstream> // std::stringstream
7 #include <string>
8 #include <vector>
11 
12 namespace op
13 {
14  template<typename T>
15  std::string tToString(const T& message)
16  {
17  // Message -> ostringstream
18  std::ostringstream oss;
19  oss << message;
20  // ostringstream -> std::string
21  return oss.str();
22  }
23 
24  // Error managment - How to use:
25  // error(message, __LINE__, __FUNCTION__, __FILE__);
26  OP_API void error(const std::string& message, const int line = -1, const std::string& function = "",
27  const std::string& file = "");
28 
29  template<typename T>
30  inline void error(const T& message, const int line = -1, const std::string& function = "",
31  const std::string& file = "")
32  {
33  error(tToString(message), line, function, file);
34  }
35 
36  // Printing info - How to use:
37  // It will print info if desiredPriority >= sPriorityThreshold
38  // log(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__);
39  OP_API void log(const std::string& message, const Priority priority = Priority::Max, const int line = -1,
40  const std::string& function = "", const std::string& file = "");
41 
42  template<typename T>
43  inline void log(const T& message, const Priority priority = Priority::Max, const int line = -1,
44  const std::string& function = "", const std::string& file = "")
45  {
46  log(tToString(message), priority, line, function, file);
47  }
48 
49  // If only desired on debug mode (no computational cost at all on release mode):
50  // It will print info if desiredPriority >= sPriorityThreshold
51  // dLog(message, desiredPriority, __LINE__, __FUNCTION__, __FILE__);
52  template<typename T>
53  inline void dLog(const T& message, const Priority priority = Priority::Max, const int line = -1,
54  const std::string& function = "", const std::string& file = "")
55  {
56  #ifndef NDEBUG
57  log(message, priority, line, function, file);
58  #else
59  UNUSED(message);
60  UNUSED(priority);
61  UNUSED(line);
62  UNUSED(function);
63  UNUSED(file);
64  #endif
65  }
66 
67  // This class is thread-safe
69  {
70  public:
71  static std::vector<ErrorMode> getErrorModes();
72 
73  static void setErrorModes(const std::vector<ErrorMode>& errorModes);
74  };
75 
76  // This class is thread-safe
78  {
79  public:
80  static Priority getPriorityThreshold();
81 
82  static const std::vector<LogMode>& getLogModes();
83 
84  static void setPriorityThreshold(const Priority priorityThreshold);
85 
86  static void setLogModes(const std::vector<LogMode>& loggingModes);
87  };
88 }
89 
90 #endif // OPENPOSE_UTILITIES_ERROR_AND_LOG_HPP
#define UNUSED(unusedVariable)
Definition: macros.hpp:28
OP_API void error(const std::string &message, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:77
std::string tToString(const T &message)
Definition: errorAndLog.hpp:15
void dLog(const T &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Definition: errorAndLog.hpp:53
OP_API void log(const std::string &message, const Priority priority=Priority::Max, const int line=-1, const std::string &function="", const std::string &file="")
Priority
Definition: enumClasses.hpp:21
#define OP_API
Definition: macros.hpp:15
Definition: errorAndLog.hpp:68
std::string string
Definition: cl2.hpp:574