GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
ErrorLog.h
1 /*
2 GRT MIT License
3 Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5 Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6 and associated documentation files (the "Software"), to deal in the Software without restriction,
7 including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9 subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in all copies or substantial
12 portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 */
20 
21 #ifndef GRT_ERROR_LOG_HEADER
22 #define GRT_ERROR_LOG_HEADER
23 
24 #include "ObserverManager.h"
25 #include "Log.h"
26 
27 GRT_BEGIN_NAMESPACE
28 
29 class GRT_API ErrorLogMessage{
30 public:
31  ErrorLogMessage(std::string key = "",std::string message = ""){
32  this->key = key;
33  this->message = message;
34  }
35  ~ErrorLogMessage(){
36 
37  }
38 
39  std::string getProceedingText() const {
40  return key;
41  }
42 
43  std::string getMessage() const {
44  return message;
45  }
46 
47  std::string key;
48  std::string message;
49 };
50 
51 class GRT_API ErrorLog : public Log {
52 public:
53  ErrorLog(const std::string &key = "" ) : Log( key )
54  {
55  loggingEnabledPtr = &errorLoggingEnabled;
56  }
57 
58  ErrorLog(const ErrorLog &rhs)
59  {
60  *this = rhs;
61  }
62 
63  virtual ~ErrorLog(){}
64 
65  ErrorLog& operator=(const ErrorLog &rhs){
66  if( this != &rhs ){
67  //Copy the base class
68  Log *thisBase = this;
69  const Log *rhsBase = &rhs;
70  *thisBase = *rhsBase;
71 
72  //Perform any custom copies
73  this->loggingEnabledPtr = &errorLoggingEnabled;
74  }
75  return *this;
76  }
77 
82  static bool getLoggingEnabled() {
83  return errorLoggingEnabled;
84  }
85 
90  static bool setLoggingEnabled(const bool enabled) {
91  errorLoggingEnabled = enabled;
92  return true;
93  }
94 
95  static bool registerObserver(Observer< ErrorLogMessage > &observer);
96 
97  static bool removeObserver(Observer< ErrorLogMessage > &observer);
98 
99  GRT_DEPRECATED_MSG("enableLogging is deprecated, use setLoggingEnabled instead", static bool enableLogging(bool loggingEnabled) );
100 
101 protected:
102  virtual void triggerCallback( const std::string &message ) const{
103  observerManager.notifyObservers( ErrorLogMessage(key,message) );
104  return;
105  }
106 
107  static ObserverManager< ErrorLogMessage > observerManager;
108  static bool errorLoggingEnabled;
109 };
110 
111 GRT_END_NAMESPACE
112 
113 #endif //GRT_ERROR_LOG_HEADER
virtual void triggerCallback(const std::string &message) const
This callback can be used to propagate messages to other interfaces (e.g., a GUI built on top of the ...
Definition: ErrorLog.h:102
static bool getLoggingEnabled()
returns true if logging is enabled for this class, this supersedes the specific instance logging ...
Definition: ErrorLog.h:82
Log(const std::string &key="")
defines the log default constructor
Definition: Log.h:46
static bool setLoggingEnabled(const bool enabled)
sets if logging is enabled for this class, this supersedes the specific instance logging ...
Definition: ErrorLog.h:90
The Log class provides the base class for all GRT logging functionality.
Definition: Log.h:37
Log & operator=(const Log &rhs)
defines the log equals operator
Definition: Log.h:76