github.com/kaydxh/golang@v0.0.131/pkg/gocv/cgo/third_path/opencv4/include/opencv2/flann/logger.h (about) 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 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: 88 /** 89 * Sets the logging level. All messages with lower priority will be ignored. 90 * @param level Logging level 91 */ 92 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 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 { 108 va_list arglist; 109 va_start(arglist, fmt); 110 int ret = instance()._log(level,fmt,arglist); 111 va_end(arglist); 112 return ret; 113 } 114 115 #define LOG_METHOD(NAME,LEVEL) \ 116 static int NAME(const char* fmt, ...) \ 117 { \ 118 va_list ap; \ 119 va_start(ap, fmt); \ 120 int ret = instance()._log(LEVEL, fmt, ap); \ 121 va_end(ap); \ 122 return ret; \ 123 } 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