|
|
|||
File indexing completed on 2026-09-10 08:39:48
0001 /* 0002 Open Asset Import Library (assimp) 0003 ---------------------------------------------------------------------- 0004 0005 Copyright (c) 2006-2025, 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 TinyFormatter.h 0043 * @brief Utility to format log messages more easily. Introduced 0044 * to get rid of the boost::format dependency. Much slinker, 0045 * basically just extends stringstream. 0046 */ 0047 #pragma once 0048 #ifndef INCLUDED_TINY_FORMATTER_H 0049 #define INCLUDED_TINY_FORMATTER_H 0050 0051 #ifdef __GNUC__ 0052 # pragma GCC system_header 0053 #endif 0054 0055 #include <sstream> 0056 0057 namespace Assimp { 0058 namespace Formatter { 0059 0060 // ------------------------------------------------------------------------------------------------ 0061 /** stringstream utility. Usage: 0062 * @code 0063 * void writelog(const std::string&s); 0064 * void writelog(const std::wstring&s); 0065 * ... 0066 * writelog(format()<< "hi! this is a number: " << 4); 0067 * writelog(wformat()<< L"hi! this is a number: " << 4); 0068 * 0069 * @endcode */ 0070 template < typename T, 0071 typename CharTraits = std::char_traits<T>, 0072 typename Allocator = std::allocator<T> > 0073 class basic_formatter { 0074 public: 0075 typedef class std::basic_string<T,CharTraits,Allocator> string; 0076 typedef class std::basic_ostringstream<T,CharTraits,Allocator> stringstream; 0077 0078 basic_formatter() { 0079 // empty 0080 } 0081 0082 /* Allow basic_formatter<T>'s to be used almost interchangeably 0083 * with std::(w)string or const (w)char* arguments because the 0084 * conversion c'tor is called implicitly. */ 0085 template <typename TT> 0086 basic_formatter(const TT& sin) { 0087 underlying << sin; 0088 } 0089 0090 // Same problem as the copy constructor below, but with root cause is that stream move 0091 // is not permitted on older GCC versions. Small performance impact on those platforms. 0092 #if defined(__GNUC__) && (__GNUC__ == 4 && __GNUC_MINOR__ <= 9) 0093 basic_formatter(basic_formatter&& other) { 0094 underlying << (string)other; 0095 } 0096 #else 0097 basic_formatter(basic_formatter&& other) 0098 : underlying(std::move(other.underlying)) { 0099 } 0100 #endif 0101 0102 // The problem described here: 0103 // https://sourceforge.net/tracker/?func=detail&atid=1067632&aid=3358562&group_id=226462 0104 // can also cause trouble here. Apparently, older gcc versions sometimes copy temporaries 0105 // being bound to const ref& function parameters. Copying streams is not permitted, though. 0106 // This workaround avoids this by manually specifying a copy ctor. 0107 #if !defined(__GNUC__) || !defined(__APPLE__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) 0108 explicit basic_formatter(const basic_formatter& other) { 0109 underlying << (string)other; 0110 } 0111 #endif 0112 0113 operator string () const { 0114 return underlying.str(); 0115 } 0116 0117 /* note - this is declared const because binding temporaries does only 0118 * work for const references, so many function prototypes will 0119 * include const basic_formatter<T>& s but might still want to 0120 * modify the formatted string without the need for a full copy.*/ 0121 template <typename TToken, typename std::enable_if<!std::is_base_of<std::exception, TToken>::value>::type * = nullptr> 0122 const basic_formatter &operator<<(const TToken &s) const { 0123 underlying << s; 0124 return *this; 0125 } 0126 0127 template <typename TToken, typename std::enable_if<std::is_base_of<std::exception, TToken>::value>::type * = nullptr> 0128 const basic_formatter &operator<<(const TToken &s) const { 0129 underlying << s.what(); 0130 return *this; 0131 } 0132 0133 template <typename TToken, typename std::enable_if<!std::is_base_of<std::exception, TToken>::value>::type * = nullptr> 0134 basic_formatter &operator<<(const TToken &s) { 0135 underlying << s; 0136 return *this; 0137 } 0138 0139 template <typename TToken, typename std::enable_if<std::is_base_of<std::exception, TToken>::value>::type * = nullptr> 0140 basic_formatter &operator<<(const TToken &s) { 0141 underlying << s.what(); 0142 return *this; 0143 } 0144 0145 0146 // comma operator overloaded as well, choose your preferred way. 0147 template <typename TToken> 0148 const basic_formatter& operator, (const TToken& s) const { 0149 *this << s; 0150 return *this; 0151 } 0152 0153 template <typename TToken> 0154 basic_formatter& operator, (const TToken& s) { 0155 *this << s; 0156 return *this; 0157 } 0158 0159 // Fix for MSVC8 0160 // See https://sourceforge.net/projects/assimp/forums/forum/817654/topic/4372824 0161 template <typename TToken> 0162 basic_formatter& operator, (TToken& s) { 0163 *this << s; 0164 return *this; 0165 } 0166 0167 0168 private: 0169 mutable stringstream underlying; 0170 }; 0171 0172 0173 typedef basic_formatter< char > format; 0174 typedef basic_formatter< wchar_t > wformat; 0175 0176 } // ! namespace Formatter 0177 0178 } // ! namespace Assimp 0179 0180 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|