/work/install-coverage/include/opencv4/opencv2/flann/logger.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
34 | | //! @cond IGNORED |
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 | 0 | Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {} |
48 | | |
49 | | ~Logger() |
50 | 0 | { |
51 | 0 | if ((stream!=NULL)&&(stream!=stdout)) { |
52 | 0 | fclose(stream); |
53 | 0 | } |
54 | 0 | } |
55 | | |
56 | | static Logger& instance() |
57 | 0 | { |
58 | 0 | static Logger logger; |
59 | 0 | return logger; |
60 | 0 | } |
61 | | |
62 | | void _setDestination(const char* name) |
63 | 0 | { |
64 | 0 | if (name==NULL) { |
65 | 0 | stream = stdout; |
66 | 0 | } |
67 | 0 | else { |
68 | 0 | #ifdef _MSC_VER |
69 | 0 | if (fopen_s(&stream, name, "w") != 0) |
70 | 0 | stream = NULL; |
71 | 0 | #else |
72 | 0 | stream = fopen(name,"w"); |
73 | 0 | #endif |
74 | 0 | if (stream == NULL) { |
75 | 0 | stream = stdout; |
76 | 0 | } |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | int _log(int level, const char* fmt, va_list arglist) |
81 | 0 | { |
82 | 0 | if (level > logLevel ) return -1; |
83 | 0 | int ret = vfprintf(stream, fmt, arglist); |
84 | 0 | return ret; |
85 | 0 | } |
86 | | |
87 | | public: |
88 | | /** |
89 | | * Sets the logging level. All messages with lower priority will be ignored. |
90 | | * @param level Logging level |
91 | | */ |
92 | 0 | static void setLevel(int level) { instance().logLevel = level; } |
93 | | |
94 | | /** |
95 | | * Sets the logging destination |
96 | | * @param name Filename or NULL for console |
97 | | */ |
98 | 0 | static void setDestination(const char* name) { instance()._setDestination(name); } |
99 | | |
100 | | /** |
101 | | * Print log message |
102 | | * @param level Log level |
103 | | * @param fmt Message format |
104 | | * @return |
105 | | */ |
106 | | static int log(int level, const char* fmt, ...) |
107 | 0 | { |
108 | 0 | va_list arglist; |
109 | 0 | va_start(arglist, fmt); |
110 | 0 | int ret = instance()._log(level,fmt,arglist); |
111 | 0 | va_end(arglist); |
112 | 0 | return ret; |
113 | 0 | } |
114 | | |
115 | | #define LOG_METHOD(NAME,LEVEL) \ |
116 | | static int NAME(const char* fmt, ...) \ |
117 | 0 | { \ |
118 | 0 | va_list ap; \ |
119 | 0 | va_start(ap, fmt); \ |
120 | 0 | int ret = instance()._log(LEVEL, fmt, ap); \ |
121 | 0 | va_end(ap); \ |
122 | 0 | return ret; \ |
123 | 0 | } Unexecuted instantiation: cvflann::Logger::fatal(char const*, ...) Unexecuted instantiation: cvflann::Logger::error(char const*, ...) Unexecuted instantiation: cvflann::Logger::warn(char const*, ...) Unexecuted instantiation: cvflann::Logger::info(char const*, ...) |
124 | | |
125 | | LOG_METHOD(fatal, FLANN_LOG_FATAL) |
126 | | LOG_METHOD(error, FLANN_LOG_ERROR) |
127 | | LOG_METHOD(warn, FLANN_LOG_WARN) |
128 | | LOG_METHOD(info, FLANN_LOG_INFO) |
129 | | |
130 | | private: |
131 | | FILE* stream; |
132 | | int logLevel; |
133 | | }; |
134 | | |
135 | | } |
136 | | |
137 | | //! @endcond |
138 | | |
139 | | #endif //OPENCV_FLANN_LOGGER_H |