vrshoot

annotate libs/assimp/assimp/DefaultLogger.hpp @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
rev   line source
nuclear@0 1 /*
nuclear@0 2 Open Asset Import Library (assimp)
nuclear@0 3 ----------------------------------------------------------------------
nuclear@0 4
nuclear@0 5 Copyright (c) 2006-2012, assimp team
nuclear@0 6 All rights reserved.
nuclear@0 7
nuclear@0 8 Redistribution and use of this software in source and binary forms,
nuclear@0 9 with or without modification, are permitted provided that the
nuclear@0 10 following conditions are met:
nuclear@0 11
nuclear@0 12 * Redistributions of source code must retain the above
nuclear@0 13 copyright notice, this list of conditions and the
nuclear@0 14 following disclaimer.
nuclear@0 15
nuclear@0 16 * Redistributions in binary form must reproduce the above
nuclear@0 17 copyright notice, this list of conditions and the
nuclear@0 18 following disclaimer in the documentation and/or other
nuclear@0 19 materials provided with the distribution.
nuclear@0 20
nuclear@0 21 * Neither the name of the assimp team, nor the names of its
nuclear@0 22 contributors may be used to endorse or promote products
nuclear@0 23 derived from this software without specific prior
nuclear@0 24 written permission of the assimp team.
nuclear@0 25
nuclear@0 26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 37
nuclear@0 38 ----------------------------------------------------------------------
nuclear@0 39 */
nuclear@0 40 /** @file DefaultLogger.h
nuclear@0 41 */
nuclear@0 42
nuclear@0 43 #ifndef INCLUDED_AI_DEFAULTLOGGER
nuclear@0 44 #define INCLUDED_AI_DEFAULTLOGGER
nuclear@0 45
nuclear@0 46 #include "Logger.hpp"
nuclear@0 47 #include "LogStream.hpp"
nuclear@0 48 #include "NullLogger.hpp"
nuclear@0 49 #include <vector>
nuclear@0 50
nuclear@0 51 namespace Assimp {
nuclear@0 52 // ------------------------------------------------------------------------------------
nuclear@0 53 class IOStream;
nuclear@0 54 struct LogStreamInfo;
nuclear@0 55
nuclear@0 56 /** default name of logfile */
nuclear@0 57 #define ASSIMP_DEFAULT_LOG_NAME "AssimpLog.txt"
nuclear@0 58
nuclear@0 59 // ------------------------------------------------------------------------------------
nuclear@0 60 /** @brief CPP-API: Primary logging facility of Assimp.
nuclear@0 61 *
nuclear@0 62 * The library stores its primary #Logger as a static member of this class.
nuclear@0 63 * #get() returns this primary logger. By default the underlying implementation is
nuclear@0 64 * just a #NullLogger which rejects all log messages. By calling #create(), logging
nuclear@0 65 * is turned on. To capture the log output multiple log streams (#LogStream) can be
nuclear@0 66 * attach to the logger. Some default streams for common streaming locations (such as
nuclear@0 67 * a file, std::cout, OutputDebugString()) are also provided.
nuclear@0 68 *
nuclear@0 69 * If you wish to customize the logging at an even deeper level supply your own
nuclear@0 70 * implementation of #Logger to #set().
nuclear@0 71 * @note The whole logging stuff causes a small extra overhead for all imports. */
nuclear@0 72 class ASSIMP_API DefaultLogger :
nuclear@0 73 public Logger {
nuclear@0 74
nuclear@0 75 public:
nuclear@0 76
nuclear@0 77 // ----------------------------------------------------------------------
nuclear@0 78 /** @brief Creates a logging instance.
nuclear@0 79 * @param name Name for log file. Only valid in combination
nuclear@0 80 * with the aiDefaultLogStream_FILE flag.
nuclear@0 81 * @param severity Log severity, VERBOSE turns on debug messages
nuclear@0 82 * @param defStreams Default log streams to be attached. Any bitwise
nuclear@0 83 * combination of the aiDefaultLogStream enumerated values.
nuclear@0 84 * If #aiDefaultLogStream_FILE is specified but an empty string is
nuclear@0 85 * passed for 'name', no log file is created at all.
nuclear@0 86 * @param io IOSystem to be used to open external files (such as the
nuclear@0 87 * log file). Pass NULL to rely on the default implementation.
nuclear@0 88 * This replaces the default #NullLogger with a #DefaultLogger instance. */
nuclear@0 89 static Logger *create(const char* name = ASSIMP_DEFAULT_LOG_NAME,
nuclear@0 90 LogSeverity severity = NORMAL,
nuclear@0 91 unsigned int defStreams = aiDefaultLogStream_DEBUGGER | aiDefaultLogStream_FILE,
nuclear@0 92 IOSystem* io = NULL);
nuclear@0 93
nuclear@0 94 // ----------------------------------------------------------------------
nuclear@0 95 /** @brief Setup a custom #Logger implementation.
nuclear@0 96 *
nuclear@0 97 * Use this if the provided #DefaultLogger class doesn't fit into
nuclear@0 98 * your needs. If the provided message formatting is OK for you,
nuclear@0 99 * it's much easier to use #create() and to attach your own custom
nuclear@0 100 * output streams to it.
nuclear@0 101 * @param logger Pass NULL to setup a default NullLogger*/
nuclear@0 102 static void set (Logger *logger);
nuclear@0 103
nuclear@0 104 // ----------------------------------------------------------------------
nuclear@0 105 /** @brief Getter for singleton instance
nuclear@0 106 * @return Only instance. This is never null, but it could be a
nuclear@0 107 * NullLogger. Use isNullLogger to check this.*/
nuclear@0 108 static Logger *get();
nuclear@0 109
nuclear@0 110 // ----------------------------------------------------------------------
nuclear@0 111 /** @brief Return whether a #NullLogger is currently active
nuclear@0 112 * @return true if the current logger is a #NullLogger.
nuclear@0 113 * Use create() or set() to setup a logger that does actually do
nuclear@0 114 * something else than just rejecting all log messages. */
nuclear@0 115 static bool isNullLogger();
nuclear@0 116
nuclear@0 117 // ----------------------------------------------------------------------
nuclear@0 118 /** @brief Kills the current singleton logger and replaces it with a
nuclear@0 119 * #NullLogger instance. */
nuclear@0 120 static void kill();
nuclear@0 121
nuclear@0 122 // ----------------------------------------------------------------------
nuclear@0 123 /** @copydoc Logger::attachStream */
nuclear@0 124 bool attachStream(LogStream *pStream,
nuclear@0 125 unsigned int severity);
nuclear@0 126
nuclear@0 127 // ----------------------------------------------------------------------
nuclear@0 128 /** @copydoc Logger::detatchStream */
nuclear@0 129 bool detatchStream(LogStream *pStream,
nuclear@0 130 unsigned int severity);
nuclear@0 131
nuclear@0 132
nuclear@0 133 private:
nuclear@0 134
nuclear@0 135 // ----------------------------------------------------------------------
nuclear@0 136 /** @briefPrivate construction for internal use by create().
nuclear@0 137 * @param severity Logging granularity */
nuclear@0 138 DefaultLogger(LogSeverity severity);
nuclear@0 139
nuclear@0 140 // ----------------------------------------------------------------------
nuclear@0 141 /** @briefDestructor */
nuclear@0 142 ~DefaultLogger();
nuclear@0 143
nuclear@0 144 private:
nuclear@0 145
nuclear@0 146 /** @brief Logs debug infos, only been written when severity level VERBOSE is set */
nuclear@0 147 void OnDebug(const char* message);
nuclear@0 148
nuclear@0 149 /** @brief Logs an info message */
nuclear@0 150 void OnInfo(const char* message);
nuclear@0 151
nuclear@0 152 /** @brief Logs a warning message */
nuclear@0 153 void OnWarn(const char* message);
nuclear@0 154
nuclear@0 155 /** @brief Logs an error message */
nuclear@0 156 void OnError(const char* message);
nuclear@0 157
nuclear@0 158 // ----------------------------------------------------------------------
nuclear@0 159 /** @brief Writes a message to all streams */
nuclear@0 160 void WriteToStreams(const char* message, ErrorSeverity ErrorSev );
nuclear@0 161
nuclear@0 162 // ----------------------------------------------------------------------
nuclear@0 163 /** @brief Returns the thread id.
nuclear@0 164 * @note This is an OS specific feature, if not supported, a
nuclear@0 165 * zero will be returned.
nuclear@0 166 */
nuclear@0 167 unsigned int GetThreadID();
nuclear@0 168
nuclear@0 169 private:
nuclear@0 170 // Aliases for stream container
nuclear@0 171 typedef std::vector<LogStreamInfo*> StreamArray;
nuclear@0 172 typedef std::vector<LogStreamInfo*>::iterator StreamIt;
nuclear@0 173 typedef std::vector<LogStreamInfo*>::const_iterator ConstStreamIt;
nuclear@0 174
nuclear@0 175 //! only logging instance
nuclear@0 176 static Logger *m_pLogger;
nuclear@0 177 static NullLogger s_pNullLogger;
nuclear@0 178
nuclear@0 179 //! Attached streams
nuclear@0 180 StreamArray m_StreamArray;
nuclear@0 181
nuclear@0 182 bool noRepeatMsg;
nuclear@0 183 char lastMsg[MAX_LOG_MESSAGE_LENGTH*2];
nuclear@0 184 size_t lastLen;
nuclear@0 185 };
nuclear@0 186 // ------------------------------------------------------------------------------------
nuclear@0 187
nuclear@0 188 } // Namespace Assimp
nuclear@0 189
nuclear@0 190 #endif // !! INCLUDED_AI_DEFAULTLOGGER