GteLogger.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <GTEngineDEF.h>
11 #include <mutex>
12 #include <set>
13 #include <string>
14 
15 // Uncomment this to turn off the logging system. The macros LogAssert,
16 // LogError, LogWarning, and LogInformation expand to nothing. (Do this for
17 // optimal performance.)
18 //#define GTE_NO_LOGGER
19 
20 namespace gte
21 {
22 
24 {
25 public:
26  // Construction. The Logger object is designed to exist only for a
27  // single-line call. A string is generated from the input parameters and
28  // is used for reporting.
29  Logger(char const* file, char const* function, int line,
30  std::string const& message);
31 
32  // Notify current listeners about the logged information.
33  void Assertion();
34  void Error();
35  void Warning();
36  void Information();
37 
38  // Listeners subscribe to Logger to receive message strings.
39  class Listener
40  {
41  public:
42  enum
43  {
44  LISTEN_FOR_NOTHING = 0x00000000,
45  LISTEN_FOR_ASSERTION = 0x00000001,
46  LISTEN_FOR_ERROR = 0x00000002,
47  LISTEN_FOR_WARNING = 0x00000004,
48  LISTEN_FOR_INFORMATION = 0x00000008,
49  LISTEN_FOR_ALL = 0xFFFFFFFF
50  };
51 
52  // Construction and destruction.
53  virtual ~Listener();
54  Listener(int flags = LISTEN_FOR_NOTHING);
55 
56  // What the listener wants to hear.
57  int GetFlags() const;
58 
59  // Handlers for the messages received from the logger.
60  void Assertion(std::string const& message);
61  void Error(std::string const& message);
62  void Warning(std::string const& message);
63  void Information(std::string const& message);
64 
65  private:
66  virtual void Report(std::string const& message);
67 
68  int mFlags;
69  };
70 
71  static void Subscribe(Listener* listener);
72  static void Unsubscribe(Listener* listener);
73 
74 private:
76 
77  static std::mutex msMutex;
78  static std::set<Listener*> msListeners;
79 };
80 
81 }
82 
83 
84 #if !defined(GTE_NO_LOGGER)
85 
86 #define LogAssert(condition, message) \
87  if (!(condition)) \
88  { \
89  gte::Logger(__FILE__, __FUNCTION__, __LINE__, message).Assertion(); \
90  }
91 
92 #define LogError(message) \
93  gte::Logger(__FILE__, __FUNCTION__, __LINE__, message).Error()
94 
95 #define LogWarning(message) \
96  gte::Logger(__FILE__, __FUNCTION__, __LINE__, message).Warning()
97 
98 #define LogInformation(message) \
99  gte::Logger(__FILE__, __FUNCTION__, __LINE__, message).Information()
100 
101 #else
102 
103 // No logging of assertions, warnings, errors, or information.
104 #define LogAssert(condition, message)
105 #define LogError(message)
106 #define LogWarning(message)
107 #define LogInformation(message)
108 
109 #endif
110 
static std::mutex msMutex
Definition: GteLogger.h:77
GLsizei const GLchar *const * string
Definition: glcorearb.h:809
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2538
GLbitfield flags
Definition: glcorearb.h:1591
std::string mMessage
Definition: GteLogger.h:75
static std::set< Listener * > msListeners
Definition: GteLogger.h:78
#define GTE_IMPEXP
Definition: GTEngineDEF.h:63


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00