vrshoot
diff libs/assimp/assimp/Logger.hpp @ 0:b2f14e535253
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 01 Feb 2014 19:58:19 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/assimp/assimp/Logger.hpp Sat Feb 01 19:58:19 2014 +0200 1.3 @@ -0,0 +1,262 @@ 1.4 +/* 1.5 +Open Asset Import Library (assimp) 1.6 +---------------------------------------------------------------------- 1.7 + 1.8 +Copyright (c) 2006-2012, assimp team 1.9 +All rights reserved. 1.10 + 1.11 +Redistribution and use of this software in source and binary forms, 1.12 +with or without modification, are permitted provided that the 1.13 +following conditions are met: 1.14 + 1.15 +* Redistributions of source code must retain the above 1.16 + copyright notice, this list of conditions and the 1.17 + following disclaimer. 1.18 + 1.19 +* Redistributions in binary form must reproduce the above 1.20 + copyright notice, this list of conditions and the 1.21 + following disclaimer in the documentation and/or other 1.22 + materials provided with the distribution. 1.23 + 1.24 +* Neither the name of the assimp team, nor the names of its 1.25 + contributors may be used to endorse or promote products 1.26 + derived from this software without specific prior 1.27 + written permission of the assimp team. 1.28 + 1.29 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.30 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.31 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.32 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.33 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.34 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.35 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.36 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.37 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.38 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.39 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.40 + 1.41 +---------------------------------------------------------------------- 1.42 +*/ 1.43 + 1.44 +/** @file Logger.hpp 1.45 + * @brief Abstract base class 'Logger', base of the logging system. 1.46 + */ 1.47 +#ifndef INCLUDED_AI_LOGGER_H 1.48 +#define INCLUDED_AI_LOGGER_H 1.49 + 1.50 +#include "types.h" 1.51 +namespace Assimp { 1.52 +class LogStream; 1.53 + 1.54 +// Maximum length of a log message. Longer messages are rejected. 1.55 +#define MAX_LOG_MESSAGE_LENGTH 1024u 1.56 + 1.57 +// ---------------------------------------------------------------------------------- 1.58 +/** @brief CPP-API: Abstract interface for logger implementations. 1.59 + * Assimp provides a default implementation and uses it for almost all 1.60 + * logging stuff ('DefaultLogger'). This class defines just basic logging 1.61 + * behaviour and is not of interest for you. Instead, take a look at #DefaultLogger. */ 1.62 +class ASSIMP_API Logger 1.63 + : public Intern::AllocateFromAssimpHeap { 1.64 +public: 1.65 + 1.66 + // ---------------------------------------------------------------------- 1.67 + /** @enum LogSeverity 1.68 + * @brief Log severity to describe the granularity of logging. 1.69 + */ 1.70 + enum LogSeverity 1.71 + { 1.72 + NORMAL, //!< Normal granularity of logging 1.73 + VERBOSE //!< Debug infos will be logged, too 1.74 + }; 1.75 + 1.76 + // ---------------------------------------------------------------------- 1.77 + /** @enum ErrorSeverity 1.78 + * @brief Description for severity of a log message. 1.79 + * 1.80 + * Every LogStream has a bitwise combination of these flags. 1.81 + * A LogStream doesn't receive any messages of a specific type 1.82 + * if it doesn't specify the corresponding ErrorSeverity flag. 1.83 + */ 1.84 + enum ErrorSeverity 1.85 + { 1.86 + Debugging = 1, //!< Debug log message 1.87 + Info = 2, //!< Info log message 1.88 + Warn = 4, //!< Warn log message 1.89 + Err = 8 //!< Error log message 1.90 + }; 1.91 + 1.92 +public: 1.93 + 1.94 + /** @brief Virtual destructor */ 1.95 + virtual ~Logger(); 1.96 + 1.97 + // ---------------------------------------------------------------------- 1.98 + /** @brief Writes a debug message 1.99 + * @param message Debug message*/ 1.100 + void debug(const char* message); 1.101 + inline void debug(const std::string &message); 1.102 + 1.103 + // ---------------------------------------------------------------------- 1.104 + /** @brief Writes a info message 1.105 + * @param message Info message*/ 1.106 + void info(const char* message); 1.107 + inline void info(const std::string &message); 1.108 + 1.109 + // ---------------------------------------------------------------------- 1.110 + /** @brief Writes a warning message 1.111 + * @param message Warn message*/ 1.112 + void warn(const char* message); 1.113 + inline void warn(const std::string &message); 1.114 + 1.115 + // ---------------------------------------------------------------------- 1.116 + /** @brief Writes an error message 1.117 + * @param message Error message*/ 1.118 + void error(const char* message); 1.119 + inline void error(const std::string &message); 1.120 + 1.121 + // ---------------------------------------------------------------------- 1.122 + /** @brief Set a new log severity. 1.123 + * @param log_severity New severity for logging*/ 1.124 + void setLogSeverity(LogSeverity log_severity); 1.125 + 1.126 + // ---------------------------------------------------------------------- 1.127 + /** @brief Get the current log severity*/ 1.128 + LogSeverity getLogSeverity() const; 1.129 + 1.130 + // ---------------------------------------------------------------------- 1.131 + /** @brief Attach a new log-stream 1.132 + * 1.133 + * The logger takes ownership of the stream and is responsible 1.134 + * for its destruction (which is done using ::delete when the logger 1.135 + * itself is destroyed). Call detachStream to detach a stream and to 1.136 + * gain ownership of it again. 1.137 + * @param pStream Log-stream to attach 1.138 + * @param severity Message filter, specified which types of log 1.139 + * messages are dispatched to the stream. Provide a bitwise 1.140 + * combination of the ErrorSeverity flags. 1.141 + * @return true if the stream has been attached, false otherwise.*/ 1.142 + virtual bool attachStream(LogStream *pStream, 1.143 + unsigned int severity = Debugging | Err | Warn | Info) = 0; 1.144 + 1.145 + // ---------------------------------------------------------------------- 1.146 + /** @brief Detach a still attached stream from the logger (or 1.147 + * modify the filter flags bits) 1.148 + * @param pStream Log-stream instance for detaching 1.149 + * @param severity Provide a bitwise combination of the ErrorSeverity 1.150 + * flags. This value is &~ed with the current flags of the stream, 1.151 + * if the result is 0 the stream is detached from the Logger and 1.152 + * the caller retakes the possession of the stream. 1.153 + * @return true if the stream has been detached, false otherwise.*/ 1.154 + virtual bool detatchStream(LogStream *pStream, 1.155 + unsigned int severity = Debugging | Err | Warn | Info) = 0; 1.156 + 1.157 +protected: 1.158 + 1.159 + /** Default constructor */ 1.160 + Logger(); 1.161 + 1.162 + /** Construction with a given log severity */ 1.163 + Logger(LogSeverity severity); 1.164 + 1.165 + // ---------------------------------------------------------------------- 1.166 + /** @brief Called as a request to write a specific debug message 1.167 + * @param message Debug message. Never longer than 1.168 + * MAX_LOG_MESSAGE_LENGTH characters (excluding the '0'). 1.169 + * @note The message string is only valid until the scope of 1.170 + * the function is left. 1.171 + */ 1.172 + virtual void OnDebug(const char* message)= 0; 1.173 + 1.174 + // ---------------------------------------------------------------------- 1.175 + /** @brief Called as a request to write a specific info message 1.176 + * @param message Info message. Never longer than 1.177 + * MAX_LOG_MESSAGE_LENGTH characters (ecxluding the '0'). 1.178 + * @note The message string is only valid until the scope of 1.179 + * the function is left. 1.180 + */ 1.181 + virtual void OnInfo(const char* message) = 0; 1.182 + 1.183 + // ---------------------------------------------------------------------- 1.184 + /** @brief Called as a request to write a specific warn message 1.185 + * @param message Warn message. Never longer than 1.186 + * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0'). 1.187 + * @note The message string is only valid until the scope of 1.188 + * the function is left. 1.189 + */ 1.190 + virtual void OnWarn(const char* essage) = 0; 1.191 + 1.192 + // ---------------------------------------------------------------------- 1.193 + /** @brief Called as a request to write a specific error message 1.194 + * @param message Error message. Never longer than 1.195 + * MAX_LOG_MESSAGE_LENGTH characters (exluding the '0'). 1.196 + * @note The message string is only valid until the scope of 1.197 + * the function is left. 1.198 + */ 1.199 + virtual void OnError(const char* message) = 0; 1.200 + 1.201 +protected: 1.202 + 1.203 + //! Logger severity 1.204 + LogSeverity m_Severity; 1.205 +}; 1.206 + 1.207 +// ---------------------------------------------------------------------------------- 1.208 +// Default constructor 1.209 +inline Logger::Logger() { 1.210 + setLogSeverity(NORMAL); 1.211 +} 1.212 + 1.213 +// ---------------------------------------------------------------------------------- 1.214 +// Virtual destructor 1.215 +inline Logger::~Logger() 1.216 +{ 1.217 +} 1.218 + 1.219 +// ---------------------------------------------------------------------------------- 1.220 +// Construction with given logging severity 1.221 +inline Logger::Logger(LogSeverity severity) { 1.222 + setLogSeverity(severity); 1.223 +} 1.224 + 1.225 +// ---------------------------------------------------------------------------------- 1.226 +// Log severity setter 1.227 +inline void Logger::setLogSeverity(LogSeverity log_severity){ 1.228 + m_Severity = log_severity; 1.229 +} 1.230 + 1.231 +// ---------------------------------------------------------------------------------- 1.232 +// Log severity getter 1.233 +inline Logger::LogSeverity Logger::getLogSeverity() const { 1.234 + return m_Severity; 1.235 +} 1.236 + 1.237 +// ---------------------------------------------------------------------------------- 1.238 +inline void Logger::debug(const std::string &message) 1.239 +{ 1.240 + return debug(message.c_str()); 1.241 +} 1.242 + 1.243 +// ---------------------------------------------------------------------------------- 1.244 +inline void Logger::error(const std::string &message) 1.245 +{ 1.246 + return error(message.c_str()); 1.247 +} 1.248 + 1.249 +// ---------------------------------------------------------------------------------- 1.250 +inline void Logger::warn(const std::string &message) 1.251 +{ 1.252 + return warn(message.c_str()); 1.253 +} 1.254 + 1.255 +// ---------------------------------------------------------------------------------- 1.256 +inline void Logger::info(const std::string &message) 1.257 +{ 1.258 + return info(message.c_str()); 1.259 +} 1.260 + 1.261 +// ---------------------------------------------------------------------------------- 1.262 + 1.263 +} // Namespace Assimp 1.264 + 1.265 +#endif // !! INCLUDED_AI_LOGGER_H