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 All rights reserved.
0007 
0008 Redistribution and use of this software in source and binary forms,
0009 with or without modification, are permitted provided that the
0010 following conditions are met:
0011 
0012 * Redistributions of source code must retain the above
0013   copyright notice, this list of conditions and the
0014   following disclaimer.
0015 
0016 * Redistributions in binary form must reproduce the above
0017   copyright notice, this list of conditions and the
0018   following disclaimer in the documentation and/or other
0019   materials provided with the distribution.
0020 
0021 * Neither the name of the assimp team, nor the names of its
0022   contributors may be used to endorse or promote products
0023   derived from this software without specific prior
0024   written permission of the assimp team.
0025 
0026 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0027 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0028 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0029 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0030 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0031 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0032 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0033 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0034 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0035 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0036 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0037 
0038 ----------------------------------------------------------------------
0039 */
0040 
0041 #pragma once
0042 #ifndef AI_INCLUDED_EXCEPTIONAL_H
0043 #define AI_INCLUDED_EXCEPTIONAL_H
0044 
0045 #ifdef __GNUC__
0046 #pragma GCC system_header
0047 #endif
0048 
0049 #include <assimp/DefaultIOStream.h>
0050 #include <assimp/TinyFormatter.h>
0051 #include <stdexcept>
0052 
0053 using std::runtime_error;
0054 
0055 #ifdef _MSC_VER
0056 #pragma warning(disable : 4275)
0057 #endif
0058 
0059 // ---------------------------------------------------------------------------
0060 /**
0061  *  The base-class for all other exceptions
0062  */
0063 class ASSIMP_API DeadlyErrorBase : public runtime_error {
0064 protected:
0065     /// @brief The class constructor with the formatter.
0066     /// @param f    The formatter.
0067     DeadlyErrorBase(Assimp::Formatter::format f);
0068 
0069     /// @brief The class constructor with the parameter ellipse.
0070     /// @tparam ...T    The type for the ellipse
0071     /// @tparam U       The other type
0072     /// @param f        The formatter
0073     /// @param u        One parameter
0074     /// @param ...args  The rest
0075     template<typename... T, typename U>
0076     DeadlyErrorBase(Assimp::Formatter::format f, U&& u, T&&... args) :
0077             DeadlyErrorBase(std::move(f << std::forward<U>(u)), std::forward<T>(args)...) {}
0078 };
0079 
0080 // ---------------------------------------------------------------------------
0081 /** FOR IMPORTER PLUGINS ONLY: Simple exception class to be thrown if an
0082  *  unrecoverable error occurs while importing. Loading APIs return
0083  *  nullptr instead of a valid aiScene then.  */
0084 class ASSIMP_API DeadlyImportError : public DeadlyErrorBase {
0085 public:
0086     /// @brief The class constructor with the message.
0087     /// @param message  The message
0088     DeadlyImportError(const char *message) :
0089             DeadlyErrorBase(Assimp::Formatter::format(), std::forward<const char*>(message)) {
0090         // empty
0091     }
0092 
0093     /// @brief The class constructor with the parameter ellipse.
0094     /// @tparam ...T    The type for the ellipse
0095     /// @param ...args  The args
0096     template<typename... T>
0097     explicit DeadlyImportError(T&&... args) :
0098             DeadlyErrorBase(Assimp::Formatter::format(), std::forward<T>(args)...) {
0099         // empty
0100     }
0101 };
0102 
0103 // ---------------------------------------------------------------------------
0104 /** FOR EXPORTER PLUGINS ONLY: Simple exception class to be thrown if an
0105  *  unrecoverable error occurs while exporting. Exporting APIs return
0106  *  nullptr instead of a valid aiScene then.  */
0107 class ASSIMP_API DeadlyExportError : public DeadlyErrorBase {
0108 public:
0109     /** Constructor with arguments */
0110     template<typename... T>
0111     explicit DeadlyExportError(T&&... args) :
0112             DeadlyErrorBase(Assimp::Formatter::format(), std::forward<T>(args)...) {}
0113 };
0114 
0115 #ifdef _MSC_VER
0116 #pragma warning(default : 4275)
0117 #endif
0118 
0119 // ---------------------------------------------------------------------------
0120 template <typename T>
0121 struct ExceptionSwallower {
0122     T operator()() const {
0123         return T();
0124     }
0125 };
0126 
0127 // ---------------------------------------------------------------------------
0128 template <typename T>
0129 struct ExceptionSwallower<T *> {
0130     T *operator()() const {
0131         return nullptr;
0132     }
0133 };
0134 
0135 // ---------------------------------------------------------------------------
0136 template <>
0137 struct ExceptionSwallower<aiReturn> {
0138     aiReturn operator()() const {
0139         try {
0140             throw;
0141         } catch (std::bad_alloc &) {
0142             return aiReturn_OUTOFMEMORY;
0143         } catch (...) {
0144             return aiReturn_FAILURE;
0145         }
0146     }
0147 };
0148 
0149 // ---------------------------------------------------------------------------
0150 template <>
0151 struct ExceptionSwallower<void> {
0152     void operator()() const {
0153         return;
0154     }
0155 };
0156 
0157 #define ASSIMP_BEGIN_EXCEPTION_REGION() \
0158     {                                   \
0159         try {
0160 
0161 #define ASSIMP_END_EXCEPTION_REGION_WITH_ERROR_STRING(type, ASSIMP_END_EXCEPTION_REGION_errorString, ASSIMP_END_EXCEPTION_REGION_exception)     \
0162     }                                                                                                                                           \
0163     catch (const DeadlyImportError &e) {                                                                                                        \
0164         ASSIMP_END_EXCEPTION_REGION_errorString = e.what();                                                                                     \
0165         ASSIMP_END_EXCEPTION_REGION_exception = std::current_exception();                                                                       \
0166         return ExceptionSwallower<type>()();                                                                                                    \
0167     }                                                                                                                                           \
0168     catch (...) {                                                                                                                               \
0169         ASSIMP_END_EXCEPTION_REGION_errorString = "Unknown exception";                                                                          \
0170         ASSIMP_END_EXCEPTION_REGION_exception = std::current_exception();                                                                       \
0171         return ExceptionSwallower<type>()();                                                                                                    \
0172     }                                                                                                                                           \
0173 }
0174 
0175 #define ASSIMP_END_EXCEPTION_REGION(type)    \
0176     }                                        \
0177     catch (...) {                            \
0178         return ExceptionSwallower<type>()(); \
0179     }                                        \
0180     }
0181 
0182 #endif // AI_INCLUDED_EXCEPTIONAL_H