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