openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/flann/logger.h@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
RyoheiHagimoto | 0:0e0631af0305 | 1 | /*********************************************************************** |
RyoheiHagimoto | 0:0e0631af0305 | 2 | * Software License Agreement (BSD License) |
RyoheiHagimoto | 0:0e0631af0305 | 3 | * |
RyoheiHagimoto | 0:0e0631af0305 | 4 | * Copyright 2008-2009 Marius Muja (mariusm@cs.ubc.ca). All rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 5 | * Copyright 2008-2009 David G. Lowe (lowe@cs.ubc.ca). All rights reserved. |
RyoheiHagimoto | 0:0e0631af0305 | 6 | * |
RyoheiHagimoto | 0:0e0631af0305 | 7 | * THE BSD LICENSE |
RyoheiHagimoto | 0:0e0631af0305 | 8 | * |
RyoheiHagimoto | 0:0e0631af0305 | 9 | * Redistribution and use in source and binary forms, with or without |
RyoheiHagimoto | 0:0e0631af0305 | 10 | * modification, are permitted provided that the following conditions |
RyoheiHagimoto | 0:0e0631af0305 | 11 | * are met: |
RyoheiHagimoto | 0:0e0631af0305 | 12 | * |
RyoheiHagimoto | 0:0e0631af0305 | 13 | * 1. Redistributions of source code must retain the above copyright |
RyoheiHagimoto | 0:0e0631af0305 | 14 | * notice, this list of conditions and the following disclaimer. |
RyoheiHagimoto | 0:0e0631af0305 | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
RyoheiHagimoto | 0:0e0631af0305 | 16 | * notice, this list of conditions and the following disclaimer in the |
RyoheiHagimoto | 0:0e0631af0305 | 17 | * documentation and/or other materials provided with the distribution. |
RyoheiHagimoto | 0:0e0631af0305 | 18 | * |
RyoheiHagimoto | 0:0e0631af0305 | 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
RyoheiHagimoto | 0:0e0631af0305 | 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
RyoheiHagimoto | 0:0e0631af0305 | 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
RyoheiHagimoto | 0:0e0631af0305 | 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
RyoheiHagimoto | 0:0e0631af0305 | 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
RyoheiHagimoto | 0:0e0631af0305 | 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
RyoheiHagimoto | 0:0e0631af0305 | 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
RyoheiHagimoto | 0:0e0631af0305 | 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
RyoheiHagimoto | 0:0e0631af0305 | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
RyoheiHagimoto | 0:0e0631af0305 | 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
RyoheiHagimoto | 0:0e0631af0305 | 29 | *************************************************************************/ |
RyoheiHagimoto | 0:0e0631af0305 | 30 | |
RyoheiHagimoto | 0:0e0631af0305 | 31 | #ifndef OPENCV_FLANN_LOGGER_H |
RyoheiHagimoto | 0:0e0631af0305 | 32 | #define OPENCV_FLANN_LOGGER_H |
RyoheiHagimoto | 0:0e0631af0305 | 33 | |
RyoheiHagimoto | 0:0e0631af0305 | 34 | #include <stdio.h> |
RyoheiHagimoto | 0:0e0631af0305 | 35 | #include <stdarg.h> |
RyoheiHagimoto | 0:0e0631af0305 | 36 | |
RyoheiHagimoto | 0:0e0631af0305 | 37 | #include "defines.h" |
RyoheiHagimoto | 0:0e0631af0305 | 38 | |
RyoheiHagimoto | 0:0e0631af0305 | 39 | |
RyoheiHagimoto | 0:0e0631af0305 | 40 | namespace cvflann |
RyoheiHagimoto | 0:0e0631af0305 | 41 | { |
RyoheiHagimoto | 0:0e0631af0305 | 42 | |
RyoheiHagimoto | 0:0e0631af0305 | 43 | class Logger |
RyoheiHagimoto | 0:0e0631af0305 | 44 | { |
RyoheiHagimoto | 0:0e0631af0305 | 45 | Logger() : stream(stdout), logLevel(FLANN_LOG_WARN) {} |
RyoheiHagimoto | 0:0e0631af0305 | 46 | |
RyoheiHagimoto | 0:0e0631af0305 | 47 | ~Logger() |
RyoheiHagimoto | 0:0e0631af0305 | 48 | { |
RyoheiHagimoto | 0:0e0631af0305 | 49 | if ((stream!=NULL)&&(stream!=stdout)) { |
RyoheiHagimoto | 0:0e0631af0305 | 50 | fclose(stream); |
RyoheiHagimoto | 0:0e0631af0305 | 51 | } |
RyoheiHagimoto | 0:0e0631af0305 | 52 | } |
RyoheiHagimoto | 0:0e0631af0305 | 53 | |
RyoheiHagimoto | 0:0e0631af0305 | 54 | static Logger& instance() |
RyoheiHagimoto | 0:0e0631af0305 | 55 | { |
RyoheiHagimoto | 0:0e0631af0305 | 56 | static Logger logger; |
RyoheiHagimoto | 0:0e0631af0305 | 57 | return logger; |
RyoheiHagimoto | 0:0e0631af0305 | 58 | } |
RyoheiHagimoto | 0:0e0631af0305 | 59 | |
RyoheiHagimoto | 0:0e0631af0305 | 60 | void _setDestination(const char* name) |
RyoheiHagimoto | 0:0e0631af0305 | 61 | { |
RyoheiHagimoto | 0:0e0631af0305 | 62 | if (name==NULL) { |
RyoheiHagimoto | 0:0e0631af0305 | 63 | stream = stdout; |
RyoheiHagimoto | 0:0e0631af0305 | 64 | } |
RyoheiHagimoto | 0:0e0631af0305 | 65 | else { |
RyoheiHagimoto | 0:0e0631af0305 | 66 | stream = fopen(name,"w"); |
RyoheiHagimoto | 0:0e0631af0305 | 67 | if (stream == NULL) { |
RyoheiHagimoto | 0:0e0631af0305 | 68 | stream = stdout; |
RyoheiHagimoto | 0:0e0631af0305 | 69 | } |
RyoheiHagimoto | 0:0e0631af0305 | 70 | } |
RyoheiHagimoto | 0:0e0631af0305 | 71 | } |
RyoheiHagimoto | 0:0e0631af0305 | 72 | |
RyoheiHagimoto | 0:0e0631af0305 | 73 | int _log(int level, const char* fmt, va_list arglist) |
RyoheiHagimoto | 0:0e0631af0305 | 74 | { |
RyoheiHagimoto | 0:0e0631af0305 | 75 | if (level > logLevel ) return -1; |
RyoheiHagimoto | 0:0e0631af0305 | 76 | int ret = vfprintf(stream, fmt, arglist); |
RyoheiHagimoto | 0:0e0631af0305 | 77 | return ret; |
RyoheiHagimoto | 0:0e0631af0305 | 78 | } |
RyoheiHagimoto | 0:0e0631af0305 | 79 | |
RyoheiHagimoto | 0:0e0631af0305 | 80 | public: |
RyoheiHagimoto | 0:0e0631af0305 | 81 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 82 | * Sets the logging level. All messages with lower priority will be ignored. |
RyoheiHagimoto | 0:0e0631af0305 | 83 | * @param level Logging level |
RyoheiHagimoto | 0:0e0631af0305 | 84 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 85 | static void setLevel(int level) { instance().logLevel = level; } |
RyoheiHagimoto | 0:0e0631af0305 | 86 | |
RyoheiHagimoto | 0:0e0631af0305 | 87 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 88 | * Sets the logging destination |
RyoheiHagimoto | 0:0e0631af0305 | 89 | * @param name Filename or NULL for console |
RyoheiHagimoto | 0:0e0631af0305 | 90 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 91 | static void setDestination(const char* name) { instance()._setDestination(name); } |
RyoheiHagimoto | 0:0e0631af0305 | 92 | |
RyoheiHagimoto | 0:0e0631af0305 | 93 | /** |
RyoheiHagimoto | 0:0e0631af0305 | 94 | * Print log message |
RyoheiHagimoto | 0:0e0631af0305 | 95 | * @param level Log level |
RyoheiHagimoto | 0:0e0631af0305 | 96 | * @param fmt Message format |
RyoheiHagimoto | 0:0e0631af0305 | 97 | * @return |
RyoheiHagimoto | 0:0e0631af0305 | 98 | */ |
RyoheiHagimoto | 0:0e0631af0305 | 99 | static int log(int level, const char* fmt, ...) |
RyoheiHagimoto | 0:0e0631af0305 | 100 | { |
RyoheiHagimoto | 0:0e0631af0305 | 101 | va_list arglist; |
RyoheiHagimoto | 0:0e0631af0305 | 102 | va_start(arglist, fmt); |
RyoheiHagimoto | 0:0e0631af0305 | 103 | int ret = instance()._log(level,fmt,arglist); |
RyoheiHagimoto | 0:0e0631af0305 | 104 | va_end(arglist); |
RyoheiHagimoto | 0:0e0631af0305 | 105 | return ret; |
RyoheiHagimoto | 0:0e0631af0305 | 106 | } |
RyoheiHagimoto | 0:0e0631af0305 | 107 | |
RyoheiHagimoto | 0:0e0631af0305 | 108 | #define LOG_METHOD(NAME,LEVEL) \ |
RyoheiHagimoto | 0:0e0631af0305 | 109 | static int NAME(const char* fmt, ...) \ |
RyoheiHagimoto | 0:0e0631af0305 | 110 | { \ |
RyoheiHagimoto | 0:0e0631af0305 | 111 | va_list ap; \ |
RyoheiHagimoto | 0:0e0631af0305 | 112 | va_start(ap, fmt); \ |
RyoheiHagimoto | 0:0e0631af0305 | 113 | int ret = instance()._log(LEVEL, fmt, ap); \ |
RyoheiHagimoto | 0:0e0631af0305 | 114 | va_end(ap); \ |
RyoheiHagimoto | 0:0e0631af0305 | 115 | return ret; \ |
RyoheiHagimoto | 0:0e0631af0305 | 116 | } |
RyoheiHagimoto | 0:0e0631af0305 | 117 | |
RyoheiHagimoto | 0:0e0631af0305 | 118 | LOG_METHOD(fatal, FLANN_LOG_FATAL) |
RyoheiHagimoto | 0:0e0631af0305 | 119 | LOG_METHOD(error, FLANN_LOG_ERROR) |
RyoheiHagimoto | 0:0e0631af0305 | 120 | LOG_METHOD(warn, FLANN_LOG_WARN) |
RyoheiHagimoto | 0:0e0631af0305 | 121 | LOG_METHOD(info, FLANN_LOG_INFO) |
RyoheiHagimoto | 0:0e0631af0305 | 122 | |
RyoheiHagimoto | 0:0e0631af0305 | 123 | private: |
RyoheiHagimoto | 0:0e0631af0305 | 124 | FILE* stream; |
RyoheiHagimoto | 0:0e0631af0305 | 125 | int logLevel; |
RyoheiHagimoto | 0:0e0631af0305 | 126 | }; |
RyoheiHagimoto | 0:0e0631af0305 | 127 | |
RyoheiHagimoto | 0:0e0631af0305 | 128 | } |
RyoheiHagimoto | 0:0e0631af0305 | 129 | |
RyoheiHagimoto | 0:0e0631af0305 | 130 | #endif //OPENCV_FLANN_LOGGER_H |