Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-21 09:30:08

0001 /*
0002 Open Asset Import Library (assimp)
0003 ----------------------------------------------------------------------
0004 
0005 Copyright (c) 2006-2024, assimp team
0006 
0007 All rights reserved.
0008 
0009 Redistribution and use of this software in source and binary forms,
0010 with or without modification, are permitted provided that the
0011 following conditions are met:
0012 
0013 * Redistributions of source code must retain the above
0014   copyright notice, this list of conditions and the
0015   following disclaimer.
0016 
0017 * Redistributions in binary form must reproduce the above
0018   copyright notice, this list of conditions and the
0019   following disclaimer in the documentation and/or other
0020   materials provided with the distribution.
0021 
0022 * Neither the name of the assimp team, nor the names of its
0023   contributors may be used to endorse or promote products
0024   derived from this software without specific prior
0025   written permission of the assimp team.
0026 
0027 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0028 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0029 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0030 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0031 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0032 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0033 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0034 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0035 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0036 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0038 
0039 ----------------------------------------------------------------------
0040 */
0041 
0042 /** @file Logger.hpp
0043  *  @brief Abstract base class 'Logger', base of the logging system.
0044  */
0045 #pragma once
0046 #ifndef INCLUDED_AI_LOGGER_H
0047 #define INCLUDED_AI_LOGGER_H
0048 
0049 #include <assimp/types.h>
0050 #include <assimp/TinyFormatter.h>
0051 
0052 namespace Assimp {
0053 
0054 class LogStream;
0055 
0056 // Maximum length of a log message. Longer messages are rejected.
0057 #define MAX_LOG_MESSAGE_LENGTH 1024u
0058 
0059 // ----------------------------------------------------------------------------------
0060 /** @brief CPP-API: Abstract interface for logger implementations.
0061  *  Assimp provides a default implementation and uses it for almost all
0062  *  logging stuff ('DefaultLogger'). This class defines just basic logging
0063  *  behavior and is not of interest for you. Instead, take a look at #DefaultLogger. */
0064 class ASSIMP_API Logger
0065 #ifndef SWIG
0066     : public Intern::AllocateFromAssimpHeap
0067 #endif
0068 {
0069 public:
0070 
0071     // ----------------------------------------------------------------------
0072     /** @enum   LogSeverity
0073      *  @brief  Log severity to describe the granularity of logging.
0074      */
0075     enum LogSeverity {
0076         NORMAL,     ///< Normal granularity of logging
0077         DEBUGGING,  ///< Debug messages will be logged, but not verbose debug messages.
0078         VERBOSE     ///< All messages will be logged
0079     };
0080 
0081     // ----------------------------------------------------------------------
0082     /** @enum   ErrorSeverity
0083      *  @brief  Description for severity of a log message.
0084      *
0085      *  Every LogStream has a bitwise combination of these flags.
0086      *  A LogStream doesn't receive any messages of a specific type
0087      *  if it doesn't specify the corresponding ErrorSeverity flag.
0088      */
0089     enum ErrorSeverity {
0090         Debugging   = 1,    //!< Debug log message
0091         Info        = 2,    //!< Info log message
0092         Warn        = 4,    //!< Warn log message
0093         Err         = 8     //!< Error log message
0094     };
0095 
0096     /** @brief  Virtual destructor */
0097     virtual ~Logger();
0098 
0099     // ----------------------------------------------------------------------
0100     /** @brief  Writes a debug message
0101      *  @param  message Debug message*/
0102     void debug(const char* message);
0103 
0104     template<typename... T>
0105     void debug(T&&... args) {
0106         debug(formatMessage(std::forward<T>(args)...).c_str());
0107     }
0108 
0109     // ----------------------------------------------------------------------
0110     /** @brief  Writes a debug message
0111      *   @param message Debug message*/
0112     void verboseDebug(const char* message);
0113 
0114     template<typename... T>
0115     void verboseDebug(T&&... args) {
0116         verboseDebug(formatMessage(std::forward<T>(args)...).c_str());
0117     }
0118 
0119     // ----------------------------------------------------------------------
0120     /** @brief  Writes a info message
0121      *  @param  message Info message*/
0122     void info(const char* message);
0123 
0124     template<typename... T>
0125     void info(T&&... args) {
0126         info(formatMessage(std::forward<T>(args)...).c_str());
0127     }
0128 
0129     // ----------------------------------------------------------------------
0130     /** @brief  Writes a warning message
0131      *  @param  message Warn message*/
0132     void warn(const char* message);
0133 
0134     template<typename... T>
0135     void warn(T&&... args) {
0136         warn(formatMessage(std::forward<T>(args)...).c_str());
0137     }
0138 
0139     // ----------------------------------------------------------------------
0140     /** @brief  Writes an error message
0141      *  @param  message Error message*/
0142     void error(const char* message);
0143 
0144     template<typename... T>
0145     void error(T&&... args) {
0146         error(formatMessage(std::forward<T>(args)...).c_str());
0147     }
0148 
0149     // ----------------------------------------------------------------------
0150     /** @brief  Set a new log severity.
0151      *  @param  log_severity New severity for logging*/
0152     void setLogSeverity(LogSeverity log_severity);
0153 
0154     // ----------------------------------------------------------------------
0155     /** @brief Get the current log severity*/
0156     LogSeverity getLogSeverity() const;
0157 
0158     // ----------------------------------------------------------------------
0159     /** @brief  Attach a new log-stream
0160      *
0161      *  The logger takes ownership of the stream and is responsible
0162      *  for its destruction (which is done using ::delete when the logger
0163      *  itself is destroyed). Call detachStream to detach a stream and to
0164      *  gain ownership of it again.
0165      *   @param pStream  Log-stream to attach
0166      *  @param severity  Message filter, specified which types of log
0167      *    messages are dispatched to the stream. Provide a bitwise
0168      *    combination of the ErrorSeverity flags.
0169      *  @return true if the stream has been attached, false otherwise.*/
0170     virtual bool attachStream(LogStream *pStream,
0171         unsigned int severity = Debugging | Err | Warn | Info) = 0;
0172 
0173     // ----------------------------------------------------------------------
0174     /** @brief  Detach a still attached stream from the logger (or
0175      *          modify the filter flags bits)
0176      *   @param pStream Log-stream instance for detaching
0177      *  @param severity Provide a bitwise combination of the ErrorSeverity
0178      *    flags. This value is &~ed with the current flags of the stream,
0179      *    if the result is 0 the stream is detached from the Logger and
0180      *    the caller retakes the possession of the stream.
0181      *  @return true if the stream has been detached, false otherwise.*/
0182     virtual bool detachStream(LogStream *pStream,
0183         unsigned int severity = Debugging | Err | Warn | Info) = 0;
0184 
0185 protected:
0186     /**
0187      *  Default constructor
0188      */
0189     Logger() AI_NO_EXCEPT;
0190 
0191     /**
0192      *  Construction with a given log severity
0193      */
0194     explicit Logger(LogSeverity severity);
0195 
0196     // ----------------------------------------------------------------------
0197     /**
0198      *  @brief Called as a request to write a specific debug message
0199      *  @param  message Debug message. Never longer than
0200      *    MAX_LOG_MESSAGE_LENGTH characters (excluding the '0').
0201      *  @note  The message string is only valid until the scope of
0202      *    the function is left.
0203      */
0204     virtual void OnDebug(const char* message)= 0;
0205 
0206     // ----------------------------------------------------------------------
0207     /**
0208      *  @brief Called as a request to write a specific verbose debug message
0209      *  @param  message Debug message. Never longer than
0210      *    MAX_LOG_MESSAGE_LENGTH characters (excluding the '0').
0211      *  @note  The message string is only valid until the scope of
0212      *    the function is left.
0213      */
0214     virtual void OnVerboseDebug(const char *message) = 0;
0215 
0216     // ----------------------------------------------------------------------
0217     /**
0218      *  @brief Called as a request to write a specific info message
0219      *  @param  message Info message. Never longer than
0220      *    MAX_LOG_MESSAGE_LENGTH characters (ecxluding the '0').
0221      *  @note  The message string is only valid until the scope of
0222      *    the function is left.
0223      */
0224     virtual void OnInfo(const char* message) = 0;
0225 
0226     // ----------------------------------------------------------------------
0227     /**
0228      *  @brief Called as a request to write a specific warn message
0229      *  @param  message Warn message. Never longer than
0230      *    MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
0231      *  @note  The message string is only valid until the scope of
0232      *    the function is left.
0233      */
0234     virtual void OnWarn(const char* essage) = 0;
0235 
0236     // ----------------------------------------------------------------------
0237     /**
0238      *  @brief Called as a request to write a specific error message
0239      *  @param  message Error message. Never longer than
0240      *    MAX_LOG_MESSAGE_LENGTH characters (exluding the '0').
0241      *  @note  The message string is only valid until the scope of
0242      *    the function is left.
0243      */
0244     virtual void OnError(const char* message) = 0;
0245 protected:
0246     std::string formatMessage(Assimp::Formatter::format f) {
0247         return f;
0248     }
0249 
0250     template<typename... T, typename U>
0251     std::string formatMessage(Assimp::Formatter::format f, U&& u, T&&... args) {
0252         return formatMessage(std::move(f << std::forward<U>(u)), std::forward<T>(args)...);
0253     }
0254 
0255 protected:
0256     LogSeverity m_Severity;
0257 };
0258 
0259 // ----------------------------------------------------------------------------------
0260 inline Logger::Logger() AI_NO_EXCEPT :
0261         m_Severity(NORMAL) {
0262     // empty
0263 }
0264 
0265 // ----------------------------------------------------------------------------------
0266 inline Logger::~Logger() = default;
0267 
0268 // ----------------------------------------------------------------------------------
0269 inline Logger::Logger(LogSeverity severity) :
0270         m_Severity(severity) {
0271     // empty
0272 }
0273 
0274 // ----------------------------------------------------------------------------------
0275 inline void Logger::setLogSeverity(LogSeverity log_severity){
0276     m_Severity = log_severity;
0277 }
0278 
0279 // ----------------------------------------------------------------------------------
0280 // Log severity getter
0281 inline Logger::LogSeverity Logger::getLogSeverity() const {
0282     return m_Severity;
0283 }
0284 
0285 } // Namespace Assimp
0286 
0287 // ------------------------------------------------------------------------------------------------
0288 #define ASSIMP_LOG_WARN(...) \
0289     Assimp::DefaultLogger::get()->warn(__VA_ARGS__)
0290 
0291 #define ASSIMP_LOG_ERROR(...) \
0292     Assimp::DefaultLogger::get()->error(__VA_ARGS__)
0293 
0294 #define ASSIMP_LOG_DEBUG(...) \
0295     Assimp::DefaultLogger::get()->debug(__VA_ARGS__)
0296 
0297 #define ASSIMP_LOG_VERBOSE_DEBUG(...) \
0298     Assimp::DefaultLogger::get()->verboseDebug(__VA_ARGS__)
0299 
0300 #define ASSIMP_LOG_INFO(...) \
0301     Assimp::DefaultLogger::get()->info(__VA_ARGS__)
0302 
0303 #endif // !! INCLUDED_AI_LOGGER_H