GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
Log.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_LOG_HEADER
22 #define GRT_LOG_HEADER
23 
24 #include <iostream>
25 #include <string.h>
26 #include "Util.h"
27 
28 namespace GRT{
29 
30 class Log{
31 public:
32  Log(std::string proceedingText = ""){
33  setProceedingText(proceedingText);
34  loggingEnabledPtr = NULL;
35  writeProceedingText = true;
36  writeProceedingTextPtr = &writeProceedingText;
37  lastMessagePtr = &lastMessage;
38  }
39 
40  virtual ~Log(){}
41 
42  const Log& operator<< (const bool val ) const{
43  if( *loggingEnabledPtr ){
44  if( *writeProceedingTextPtr ){
45  *writeProceedingTextPtr = false;
46  *lastMessagePtr = "";
47  std::cout << proceedingText.c_str();
48  }
49  std::cout << proceedingText.c_str() << val;
50  *lastMessagePtr += Util::toString(val);
51  }
52  return *this;
53  }
54 
55  const Log& operator<< (const short val ) const{
56  if( *loggingEnabledPtr ){
57  if( *writeProceedingTextPtr ){
58  *writeProceedingTextPtr = false;
59  *lastMessagePtr = "";
60  std::cout << proceedingText.c_str();
61  }
62  std::cout << val;
63  *lastMessagePtr += Util::toString(val);
64  }
65  return *this;
66  }
67 
68  const Log& operator<< (const unsigned short val ) const{
69  if( *loggingEnabledPtr ){
70  if( *writeProceedingTextPtr ){
71  *writeProceedingTextPtr = false;
72  *lastMessagePtr = "";
73  std::cout << proceedingText.c_str();
74  }
75  std::cout << val;
76  *lastMessagePtr += Util::toString(val);
77  }
78  return *this;
79  }
80 
81  const Log& operator<< (const int val ) const{
82  if( *loggingEnabledPtr ){
83  if( *writeProceedingTextPtr ){
84  *writeProceedingTextPtr = false;
85  *lastMessagePtr = "";
86  std::cout << proceedingText.c_str();
87  }
88  std::cout << val;
89  *lastMessagePtr += Util::toString(val);
90  }
91  return *this;
92  }
93 
94  const Log& operator<< (const unsigned int val ) const{
95  if( *loggingEnabledPtr ){
96  if( *writeProceedingTextPtr ){
97  *writeProceedingTextPtr = false;
98  *lastMessagePtr = "";
99  std::cout << proceedingText.c_str();
100  }
101  std::cout << val;
102  *lastMessagePtr += Util::toString(val);
103  }
104  return *this;
105  }
106 
107  const Log& operator<< (const long val ) const{
108  if( *loggingEnabledPtr ){
109  if( *writeProceedingTextPtr ){
110  *writeProceedingTextPtr = false;
111  *lastMessagePtr = "";
112  std::cout << proceedingText.c_str();
113  }
114  std::cout << val;
115  *lastMessagePtr += Util::toString(val);
116  }
117  return *this; }
118 
119  const Log& operator<< (const unsigned long val ) const{
120  if( *loggingEnabledPtr ){
121  if( *writeProceedingTextPtr ){
122  *writeProceedingTextPtr = false;
123  *lastMessagePtr = "";
124  std::cout << proceedingText.c_str();
125  }
126  std::cout << val;
127  *lastMessagePtr += Util::toString(val);
128  }
129  return *this;
130  }
131 
132  const Log& operator<< (const unsigned long long val ) const{
133  if( *loggingEnabledPtr ){
134  if( *writeProceedingTextPtr ){
135  *writeProceedingTextPtr = false;
136  *lastMessagePtr = "";
137  std::cout << proceedingText.c_str();
138  }
139  std::cout << val;
140  *lastMessagePtr += Util::toString(val);
141  }
142  return *this;
143  }
144 
145  const Log& operator<< (const float val ) const{
146  if( *loggingEnabledPtr ){
147  if( *writeProceedingTextPtr ){
148  *writeProceedingTextPtr = false;
149  *lastMessagePtr = "";
150  std::cout << proceedingText.c_str();
151  }
152  std::cout << val;
153  *lastMessagePtr += Util::toString(val);
154  }
155  return *this; }
156 
157  const Log& operator<< (const double val ) const{
158  if( *loggingEnabledPtr ){
159  if( *writeProceedingTextPtr ){
160  *writeProceedingTextPtr = false;
161  *lastMessagePtr = "";
162  std::cout << proceedingText.c_str();
163  }
164  std::cout << val;
165  *lastMessagePtr += Util::toString(val);
166  }
167  return *this;
168  }
169 
170  const Log& operator<< (const long double val ) const{
171  if( *loggingEnabledPtr ){
172  if( *writeProceedingTextPtr ){
173  *writeProceedingTextPtr = false;
174  *lastMessagePtr = "";
175  std::cout << proceedingText.c_str();
176  }
177  std::cout << val;
178  *lastMessagePtr += Util::toString(val);
179  }
180  return *this; }
181 
182  const Log& operator<< (const void* val ) const{
183  if( *loggingEnabledPtr ){
184  if( *writeProceedingTextPtr ){
185  *writeProceedingTextPtr = false;
186  *lastMessagePtr = "";
187  std::cout << proceedingText.c_str();
188  }
189  std::cout << val;
190  }
191  return *this;
192  }
193 
194  const Log& operator<< (const std::string val ) const{
195  if( *loggingEnabledPtr ){
196  if( *writeProceedingTextPtr ){
197  *writeProceedingTextPtr = false;
198  *lastMessagePtr = "";
199  std::cout << proceedingText.c_str();
200  }
201  std::cout << val.c_str();
202  *lastMessagePtr += val;
203  }
204  return *this;
205  }
206 
207  const Log& operator<< (const char* val ) const{
208  if( *loggingEnabledPtr ){
209  if( *writeProceedingTextPtr ){
210  *writeProceedingTextPtr = false;
211  std::cout << proceedingText.c_str();
212  *lastMessagePtr = "";
213  }
214  std::cout << val;
215  *lastMessagePtr += val;
216  }
217  return *this;
218  }
219 
220  // this is the type of std::cout
221  typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
222 
223  // this is the function signature of std::endl
224  typedef CoutType& (*StandardEndLine)(CoutType&);
225 
226  // define an operator<< to take in std::endl
227  const Log& operator<<(const StandardEndLine manip) const{
228  if( *loggingEnabledPtr ){
229  // call the function, but we cannot return it's value
230  manip(std::cout);
231  *writeProceedingTextPtr = true;
232 
233  //Trigger any logging callbacks
234  triggerCallback( lastMessage );
235  }
236 
237  return *this;
238  }
239 
240  //Getters
241  virtual bool getLoggingEnabled() const{ return false; }
242 
243  std::string getProceedingText() const{ return proceedingText; }
244 
245  virtual std::string getLastMessage() const{ return lastMessage; }
246 
247  //Setters
248  void setProceedingText(const std::string &proceedingText){
249  if( proceedingText.length() == 0 ) this->proceedingText = "";
250  else this->proceedingText = proceedingText + " ";
251  }
252 
253 protected:
254  virtual void triggerCallback( const std::string &message ) const{
255  return;
256  }
257 
258  std::string proceedingText;
259  std::string lastMessage;
260  bool *loggingEnabledPtr;
261  bool *writeProceedingTextPtr;
262  std::string *lastMessagePtr;
263  bool writeProceedingText;
264 };
265 
266 } //End of namespace GRT
267 
268 #endif //GRT_LOG_HEADER
This file contains the Util class, a wrapper for a number of generic functions that are used througho...
static std::string toString(const int &i)
Definition: Util.cpp:65
Definition: AdaBoost.cpp:25
Definition: Log.h:30