nuclear@0: /* nuclear@0: Open Asset Import Library (assimp) nuclear@0: ---------------------------------------------------------------------- nuclear@0: nuclear@0: Copyright (c) 2006-2018, assimp team nuclear@0: nuclear@0: nuclear@0: All rights reserved. nuclear@0: nuclear@0: Redistribution and use of this software in source and binary forms, nuclear@0: with or without modification, are permitted provided that the nuclear@0: following conditions are met: nuclear@0: nuclear@0: * Redistributions of source code must retain the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer. nuclear@0: nuclear@0: * Redistributions in binary form must reproduce the above nuclear@0: copyright notice, this list of conditions and the nuclear@0: following disclaimer in the documentation and/or other nuclear@0: materials provided with the distribution. nuclear@0: nuclear@0: * Neither the name of the assimp team, nor the names of its nuclear@0: contributors may be used to endorse or promote products nuclear@0: derived from this software without specific prior nuclear@0: written permission of the assimp team. nuclear@0: nuclear@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS nuclear@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT nuclear@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR nuclear@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT nuclear@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, nuclear@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT nuclear@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, nuclear@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY nuclear@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT nuclear@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE nuclear@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. nuclear@0: nuclear@0: ---------------------------------------------------------------------- nuclear@0: */ nuclear@0: nuclear@0: /** @file TinyFormatter.h nuclear@0: * @brief Utility to format log messages more easily. Introduced nuclear@0: * to get rid of the boost::format dependency. Much slinker, nuclear@0: * basically just extends stringstream. nuclear@0: */ nuclear@0: #ifndef INCLUDED_TINY_FORMATTER_H nuclear@0: #define INCLUDED_TINY_FORMATTER_H nuclear@0: nuclear@0: #include nuclear@0: nuclear@0: namespace Assimp { nuclear@0: namespace Formatter { nuclear@0: nuclear@0: // ------------------------------------------------------------------------------------------------ nuclear@0: /** stringstream utility. Usage: nuclear@0: * @code nuclear@0: * void writelog(const std::string&s); nuclear@0: * void writelog(const std::wstring&s); nuclear@0: * ... nuclear@0: * writelog(format()<< "hi! this is a number: " << 4); nuclear@0: * writelog(wformat()<< L"hi! this is a number: " << 4); nuclear@0: * nuclear@0: * @endcode */ nuclear@0: template < typename T, nuclear@0: typename CharTraits = std::char_traits, nuclear@0: typename Allocator = std::allocator nuclear@0: > nuclear@0: class basic_formatter nuclear@0: { nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: typedef class std::basic_string< nuclear@0: T,CharTraits,Allocator nuclear@0: > string; nuclear@0: nuclear@0: typedef class std::basic_ostringstream< nuclear@0: T,CharTraits,Allocator nuclear@0: > stringstream; nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: basic_formatter() {} nuclear@0: nuclear@0: /* Allow basic_formatter's to be used almost interchangeably nuclear@0: * with std::(w)string or const (w)char* arguments because the nuclear@0: * conversion c'tor is called implicitly. */ nuclear@0: template nuclear@0: basic_formatter(const TT& sin) { nuclear@0: underlying << sin; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // The problem described here: nuclear@0: // https://sourceforge.net/tracker/?func=detail&atid=1067632&aid=3358562&group_id=226462 nuclear@0: // can also cause trouble here. Apparently, older gcc versions sometimes copy temporaries nuclear@0: // being bound to const ref& function parameters. Copying streams is not permitted, though. nuclear@0: // This workaround avoids this by manually specifying a copy ctor. nuclear@0: #if !defined(__GNUC__) || !defined(__APPLE__) || __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) nuclear@0: explicit basic_formatter(const basic_formatter& other) { nuclear@0: underlying << (string)other; nuclear@0: } nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: public: nuclear@0: nuclear@0: operator string () const { nuclear@0: return underlying.str(); nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* note - this is declared const because binding temporaries does only nuclear@0: * work for const references, so many function prototypes will nuclear@0: * include const basic_formatter& s but might still want to nuclear@0: * modify the formatted string without the need for a full copy.*/ nuclear@0: template nuclear@0: const basic_formatter& operator << (const TToken& s) const { nuclear@0: underlying << s; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: template nuclear@0: basic_formatter& operator << (const TToken& s) { nuclear@0: underlying << s; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: // comma operator overloaded as well, choose your preferred way. nuclear@0: template nuclear@0: const basic_formatter& operator, (const TToken& s) const { nuclear@0: underlying << s; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: template nuclear@0: basic_formatter& operator, (const TToken& s) { nuclear@0: underlying << s; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: // Fix for MSVC8 nuclear@0: // See https://sourceforge.net/projects/assimp/forums/forum/817654/topic/4372824 nuclear@0: template nuclear@0: basic_formatter& operator, (TToken& s) { nuclear@0: underlying << s; nuclear@0: return *this; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: private: nuclear@0: mutable stringstream underlying; nuclear@0: }; nuclear@0: nuclear@0: nuclear@0: typedef basic_formatter< char > format; nuclear@0: typedef basic_formatter< wchar_t > wformat; nuclear@0: nuclear@0: } // ! namespace Formatter nuclear@0: nuclear@0: } // ! namespace Assimp nuclear@0: nuclear@0: #endif