diff options
Diffstat (limited to 'boost/log/utility')
-rw-r--r-- | boost/log/utility/formatting_ostream.hpp | 47 | ||||
-rw-r--r-- | boost/log/utility/setup/filter_parser.hpp | 4 | ||||
-rw-r--r-- | boost/log/utility/type_info_wrapper.hpp | 194 |
3 files changed, 39 insertions, 206 deletions
diff --git a/boost/log/utility/formatting_ostream.hpp b/boost/log/utility/formatting_ostream.hpp index 4a79998b1c..d51413693f 100644 --- a/boost/log/utility/formatting_ostream.hpp +++ b/boost/log/utility/formatting_ostream.hpp @@ -19,9 +19,12 @@ #include <string> #include <memory> #include <locale> +#include <boost/core/enable_if.hpp> #include <boost/core/explicit_operator_bool.hpp> #include <boost/utility/string_ref_fwd.hpp> #include <boost/utility/string_view_fwd.hpp> +#include <boost/type_traits/is_enum.hpp> +#include <boost/type_traits/is_scalar.hpp> #include <boost/type_traits/remove_cv.hpp> #include <boost/log/detail/config.hpp> #include <boost/log/detail/attachable_sstream_buf.hpp> @@ -57,10 +60,18 @@ struct enable_if_streamable_char_type< char32_t, R > { typedef R type; }; #endif #endif -template< typename StreamT, typename R > -struct enable_if_formatting_ostream {}; -template< typename CharT, typename TraitsT, typename AllocatorT, typename R > -struct enable_if_formatting_ostream< basic_formatting_ostream< CharT, TraitsT, AllocatorT >, R > { typedef R type; }; +template< typename StreamT, typename T, bool ByValueV, typename R > +struct enable_formatting_ostream_generic_operator {}; +template< typename CharT, typename TraitsT, typename AllocatorT, typename T, typename R > +struct enable_formatting_ostream_generic_operator< basic_formatting_ostream< CharT, TraitsT, AllocatorT >, T, false, R > : + public boost::disable_if_c< boost::is_scalar< typename boost::remove_cv< T >::type >::value, R > +{ +}; +template< typename CharT, typename TraitsT, typename AllocatorT, typename T, typename R > +struct enable_formatting_ostream_generic_operator< basic_formatting_ostream< CharT, TraitsT, AllocatorT >, T, true, R > : + public boost::enable_if_c< boost::is_enum< typename boost::remove_cv< T >::type >::value, R > +{ +}; } // namespace aux @@ -137,7 +148,7 @@ public: BOOST_DELETED_FUNCTION(sentry& operator= (sentry const&)) }; -private: +protected: // Function types typedef std::ios_base& (*ios_base_manip)(std::ios_base&); typedef std::basic_ios< char_type, traits_type >& (*basic_ios_manip)(std::basic_ios< char_type, traits_type >&); @@ -837,7 +848,7 @@ void basic_formatting_ostream< CharT, TraitsT, AllocatorT >::aligned_write(const // Implementation note: these operators below should be the least attractive for the compiler // so that user's overloads are chosen, when present. We use function template partial ordering for this purpose. -// We also don't use perfect forwarding for the right hand argument because in ths case the generic overload +// We also don't use perfect forwarding for the right hand argument because in this case the generic overload // would be more preferred than the typical one written by users: // // formatting_ostream& operator<< (formatting_ostream& strm, my_type const& arg); @@ -845,7 +856,15 @@ void basic_formatting_ostream< CharT, TraitsT, AllocatorT >::aligned_write(const // This is because my_type rvalues require adding const to the type, which counts as a conversion that is not required // if there is a perfect forwarding overload. template< typename StreamT, typename T > -inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, true, StreamT& >::type +operator<< (StreamT& strm, T value) +{ + strm.stream() << value; + return strm; +} + +template< typename StreamT, typename T > +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, false, StreamT& >::type operator<< (StreamT& strm, T const& value) { strm.stream() << value; @@ -853,7 +872,7 @@ operator<< (StreamT& strm, T const& value) } template< typename StreamT, typename T > -inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, false, StreamT& >::type operator<< (StreamT& strm, T& value) { strm.stream() << value; @@ -863,7 +882,15 @@ operator<< (StreamT& strm, T& value) #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) template< typename StreamT, typename T > -inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, true, StreamT& >::type +operator<< (StreamT&& strm, T value) +{ + strm.stream() << value; + return strm; +} + +template< typename StreamT, typename T > +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, false, StreamT& >::type operator<< (StreamT&& strm, T const& value) { strm.stream() << value; @@ -871,7 +898,7 @@ operator<< (StreamT&& strm, T const& value) } template< typename StreamT, typename T > -inline typename boost::log::aux::enable_if_formatting_ostream< StreamT, StreamT& >::type +inline typename boost::log::aux::enable_formatting_ostream_generic_operator< StreamT, T, false, StreamT& >::type operator<< (StreamT&& strm, T& value) { strm.stream() << value; diff --git a/boost/log/utility/setup/filter_parser.hpp b/boost/log/utility/setup/filter_parser.hpp index f9aa831caf..9a6c9f6d25 100644 --- a/boost/log/utility/setup/filter_parser.hpp +++ b/boost/log/utility/setup/filter_parser.hpp @@ -125,7 +125,7 @@ struct filter_factory */ virtual filter on_custom_relation(attribute_name const& name, string_type const& rel, string_type const& arg) { - BOOST_LOG_THROW_DESCR_PARAMS(parse_error, "The custom attribute value relation \"" + boost::log::aux::to_narrow(arg) + "\" is not supported", (name)); + BOOST_LOG_THROW_DESCR_PARAMS(parse_error, "The custom attribute value relation \"" + boost::log::aux::to_narrow(rel) + "\" is not supported", (name)); BOOST_LOG_UNREACHABLE_RETURN(filter()); } @@ -208,7 +208,7 @@ public: */ virtual filter on_custom_relation(attribute_name const& name, string_type const& rel, string_type const& arg) { - BOOST_LOG_THROW_DESCR_PARAMS(parse_error, "The custom attribute value relation \"" + boost::log::aux::to_narrow(arg) + "\" is not supported", (name)); + BOOST_LOG_THROW_DESCR_PARAMS(parse_error, "The custom attribute value relation \"" + boost::log::aux::to_narrow(rel) + "\" is not supported", (name)); BOOST_LOG_UNREACHABLE_RETURN(filter()); } diff --git a/boost/log/utility/type_info_wrapper.hpp b/boost/log/utility/type_info_wrapper.hpp deleted file mode 100644 index 81cd3aed69..0000000000 --- a/boost/log/utility/type_info_wrapper.hpp +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright Andrey Semashev 2007 - 2015. - * Distributed under the Boost Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at - * http://www.boost.org/LICENSE_1_0.txt) - */ -/*! - * \file type_info_wrapper.hpp - * \author Andrey Semashev - * \date 15.04.2007 - * - * The header contains implementation of a type information wrapper. - */ - -#ifndef BOOST_LOG_UTILITY_TYPE_INFO_WRAPPER_HPP_INCLUDED_ -#define BOOST_LOG_UTILITY_TYPE_INFO_WRAPPER_HPP_INCLUDED_ - -#include <typeinfo> -#include <string> -#include <boost/core/demangle.hpp> -#include <boost/core/explicit_operator_bool.hpp> -#include <boost/log/detail/config.hpp> -#include <boost/log/detail/header.hpp> - -#ifdef BOOST_HAS_PRAGMA_ONCE -#pragma once -#endif - -#if defined(__GNUC__) -#pragma message "Boost.Log: This header is deprecated, use Boost.TypeIndex instead." -#elif defined(_MSC_VER) -#pragma message("Boost.Log: This header is deprecated, use Boost.TypeIndex instead.") -#endif - -namespace boost { - -BOOST_LOG_OPEN_NAMESPACE - -/*! - * \brief A simple <tt>std::type_info</tt> wrapper that implements value semantic for type information objects - * - * The type info wrapper is very useful for storing type information objects in containers, - * as a key or value. It also provides a number of useful features, such as default construction - * and assignment support, an empty state and extended support for human-friendly type names. - */ -class type_info_wrapper -{ -private: -#ifndef BOOST_LOG_DOXYGEN_PASS - //! An inaccessible type to indicate an uninitialized state of the wrapper - struct BOOST_SYMBOL_VISIBLE uninitialized {}; -#endif // BOOST_LOG_DOXYGEN_PASS - -private: - //! A pointer to the actual type info - std::type_info const* info; - -public: - /*! - * Default constructor - * - * \post <tt>!*this == true</tt> - */ - type_info_wrapper() BOOST_NOEXCEPT : info(&typeid(uninitialized)) {} - /*! - * Copy constructor - * - * \post <tt>*this == that</tt> - * \param that Source type info wrapper to copy from - */ - type_info_wrapper(type_info_wrapper const& that) BOOST_NOEXCEPT : info(that.info) {} - /*! - * Conversion constructor - * - * \post <tt>*this == that && !!*this</tt> - * \param that Type info object to be wrapped - */ - type_info_wrapper(std::type_info const& that) BOOST_NOEXCEPT : info(&that) {} - - /*! - * \return \c true if the type info wrapper was initialized with a particular type, - * \c false if the wrapper was default-constructed and not yet initialized - */ - BOOST_EXPLICIT_OPERATOR_BOOL_NOEXCEPT() - - /*! - * Stored type info getter - * - * \pre <tt>!!*this</tt> - * \return Constant reference to the wrapped type info object - */ - std::type_info const& get() const BOOST_NOEXCEPT { return *info; } - - /*! - * Swaps two instances of the wrapper - */ - void swap(type_info_wrapper& that) BOOST_NOEXCEPT - { - std::type_info const* temp = info; - info = that.info; - that.info = temp; - } - - /*! - * The method returns the contained type name string in a possibly more readable format than <tt>get().name()</tt> - * - * \pre <tt>!!*this</tt> - * \return Type name string - */ - std::string pretty_name() const - { - if (!this->operator!()) - return boost::core::demangle(info->name()); - else - return "[uninitialized]"; - } - - /*! - * \return \c false if the type info wrapper was initialized with a particular type, - * \c true if the wrapper was default-constructed and not yet initialized - */ - bool operator! () const BOOST_NOEXCEPT { return (info == &typeid(uninitialized) || *info == typeid(uninitialized)); } - - /*! - * Equality comparison - * - * \param that Comparand - * \return If either this object or comparand is in empty state and the other is not, the result is \c false. - * If both arguments are empty, the result is \c true. If both arguments are not empty, the result - * is \c true if this object wraps the same type as the comparand and \c false otherwise. - */ - bool operator== (type_info_wrapper const& that) const BOOST_NOEXCEPT - { - return (info == that.info || *info == *that.info); - } - /*! - * Ordering operator - * - * \pre <tt>!!*this && !!that</tt> - * \param that Comparand - * \return \c true if this object wraps type info object that is ordered before - * the type info object in the comparand, \c false otherwise - * \note The results of this operator are only consistent within a single run of application. - * The result may change for the same types after rebuilding or even restarting the application. - */ - bool operator< (type_info_wrapper const& that) const BOOST_NOEXCEPT - { - return static_cast< bool >(info->before(*that.info)); - } -}; - -//! Inequality operator -inline bool operator!= (type_info_wrapper const& left, type_info_wrapper const& right) BOOST_NOEXCEPT -{ - return !left.operator==(right); -} - -//! Ordering operator -inline bool operator<= (type_info_wrapper const& left, type_info_wrapper const& right) BOOST_NOEXCEPT -{ - return (left.operator==(right) || left.operator<(right)); -} - -//! Ordering operator -inline bool operator> (type_info_wrapper const& left, type_info_wrapper const& right) BOOST_NOEXCEPT -{ - return !(left.operator==(right) || left.operator<(right)); -} - -//! Ordering operator -inline bool operator>= (type_info_wrapper const& left, type_info_wrapper const& right) BOOST_NOEXCEPT -{ - return !left.operator<(right); -} - -//! Free swap for type info wrapper -inline void swap(type_info_wrapper& left, type_info_wrapper& right) BOOST_NOEXCEPT -{ - left.swap(right); -} - -//! The function for exception serialization to string -inline std::string to_string(type_info_wrapper const& ti) -{ - return ti.pretty_name(); -} - -BOOST_LOG_CLOSE_NAMESPACE // namespace log - -} // namespace boost - -#include <boost/log/detail/footer.hpp> - -#endif // BOOST_LOG_UTILITY_TYPE_INFO_WRAPPER_HPP_INCLUDED_ |