EstervQrCode 1.1.1
Library for qr code manipulation
logger.h
1 /***********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved.
5  * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved.
6  *
7  * THE BSD LICENSE
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *************************************************************************/
30 
31 #ifndef OPENCV_FLANN_LOGGER_H
32 #define OPENCV_FLANN_LOGGER_H
33 
35 
36 #include <stdio.h>
37 #include <stdarg.h>
38 
39 #include "defines.h"
40 
41 
42 namespace cvflann
43 {
44 
45 class Logger
46 {
47  Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {}
48 
49  ~Logger()
50  {
51  if ((stream!=NULL)&&(stream!=stdout)) {
52  fclose(stream);
53  }
54  }
55 
56  static Logger& instance()
57  {
58  static Logger logger;
59  return logger;
60  }
61 
62  void _setDestination(const char* name)
63  {
64  if (name==NULL) {
65  stream = stdout;
66  }
67  else {
68 #ifdef _MSC_VER
69  if (fopen_s(&stream, name, "w") != 0)
70  stream = NULL;
71 #else
72  stream = fopen(name,"w");
73 #endif
74  if (stream == NULL) {
75  stream = stdout;
76  }
77  }
78  }
79 
80  int _log(int level, const char* fmt, va_list arglist)
81  {
82  if (level > logLevel ) return -1;
83  int ret = vfprintf(stream, fmt, arglist);
84  return ret;
85  }
86 
87 public:
92  static void setLevel(int level) { instance().logLevel = level; }
93 
98  static void setDestination(const char* name) { instance()._setDestination(name); }
99 
105  static int log(int level, const char* fmt, ...)
106  {
107  va_list arglist;
108  va_start(arglist, fmt);
109  int ret = instance()._log(level,fmt,arglist);
110  va_end(arglist);
111  return ret;
112  }
113 
114 #define LOG_METHOD(NAME,LEVEL) \
115  static int NAME(const char* fmt, ...) \
116  { \
117  va_list ap; \
118  va_start(ap, fmt); \
119  int ret = instance()._log(LEVEL, fmt, ap); \
120  va_end(ap); \
121  return ret; \
122  }
123 
124  LOG_METHOD(fatal, FLANN_LOG_FATAL)
125  LOG_METHOD(error, FLANN_LOG_ERROR)
126  LOG_METHOD(warn, FLANN_LOG_WARN)
127  LOG_METHOD(info, FLANN_LOG_INFO)
128 
129 private:
130  FILE* stream;
131  int logLevel;
132 };
133 
134 }
135 
137 
138 #endif //OPENCV_FLANN_LOGGER_H
T fclose(T... args)
T fopen(T... args)
CV_EXPORTS CV_NORETURN void error(int _code, const String &_err, const char *_func, const char *_file, int _line)
Signals an error and raises the exception.
Quat< T > log(const Quat< T > &q, QuatAssumeType assumeUnit=QUAT_ASSUME_NOT_UNIT)
Definition: flann.hpp:60
T vfprintf(T... args)