diff options
Diffstat (limited to 'boost/log/detail')
-rw-r--r-- | boost/log/detail/code_conversion.hpp | 57 | ||||
-rw-r--r-- | boost/log/detail/config.hpp | 7 | ||||
-rw-r--r-- | boost/log/detail/event.hpp | 44 | ||||
-rw-r--r-- | boost/log/detail/is_character_type.hpp | 75 | ||||
-rw-r--r-- | boost/log/detail/is_ostream.hpp (renamed from boost/log/detail/visible_type.hpp) | 25 |
5 files changed, 175 insertions, 33 deletions
diff --git a/boost/log/detail/code_conversion.hpp b/boost/log/detail/code_conversion.hpp index 4c39f9c02b..41c086e109 100644 --- a/boost/log/detail/code_conversion.hpp +++ b/boost/log/detail/code_conversion.hpp @@ -16,9 +16,12 @@ #ifndef BOOST_LOG_DETAIL_CODE_CONVERSION_HPP_INCLUDED_ #define BOOST_LOG_DETAIL_CODE_CONVERSION_HPP_INCLUDED_ +#include <cstddef> #include <locale> #include <string> +#include <boost/core/enable_if.hpp> #include <boost/log/detail/config.hpp> +#include <boost/log/detail/is_character_type.hpp> #include <boost/log/detail/header.hpp> #ifdef BOOST_HAS_PRAGMA_ONCE @@ -32,44 +35,64 @@ BOOST_LOG_OPEN_NAMESPACE namespace aux { //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const wchar_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const wchar_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::wstring& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const char* str1, std::size_t len, std::wstring& str2, std::locale const& loc = std::locale()); -// Note: MSVC 2015 (aka VC14) implement char16_t and char32_t types but not codecvt locale facets -#if !defined(BOOST_MSVC) +#if !defined(BOOST_LOG_NO_CXX11_CODECVT_FACETS) #if !defined(BOOST_NO_CXX11_CHAR16_T) //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const char16_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const char16_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::u16string& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const char* str1, std::size_t len, std::u16string& str2, std::locale const& loc = std::locale()); +//! The function converts one string to the character type of another +BOOST_LOG_API void code_convert_impl(const char16_t* str1, std::size_t len, std::wstring& str2, std::locale const& loc = std::locale()); #endif #if !defined(BOOST_NO_CXX11_CHAR32_T) //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const char32_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const char32_t* str1, std::size_t len, std::string& str2, std::locale const& loc = std::locale()); +//! The function converts one string to the character type of another +BOOST_LOG_API void code_convert_impl(const char* str1, std::size_t len, std::u32string& str2, std::locale const& loc = std::locale()); +//! The function converts one string to the character type of another +BOOST_LOG_API void code_convert_impl(const char32_t* str1, std::size_t len, std::wstring& str2, std::locale const& loc = std::locale()); +#endif +#if !defined(BOOST_NO_CXX11_CHAR16_T) && !defined(BOOST_NO_CXX11_CHAR32_T) +//! The function converts one string to the character type of another +BOOST_LOG_API void code_convert_impl(const char16_t* str1, std::size_t len, std::u32string& str2, std::locale const& loc = std::locale()); //! The function converts one string to the character type of another -BOOST_LOG_API void code_convert(const char* str1, std::size_t len, std::u32string& str2, std::locale const& loc = std::locale()); +BOOST_LOG_API void code_convert_impl(const char32_t* str1, std::size_t len, std::u16string& str2, std::locale const& loc = std::locale()); #endif -#endif // !defined(BOOST_MSVC) +#endif // !defined(BOOST_LOG_NO_CXX11_CODECVT_FACETS) //! The function converts one string to the character type of another -template< typename CharT, typename SourceTraitsT, typename SourceAllocatorT, typename TargetTraitsT, typename TargetAllocatorT > -inline void code_convert(std::basic_string< CharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale()) +template< typename SourceCharT, typename SourceTraitsT, typename SourceAllocatorT, typename TargetCharT, typename TargetTraitsT, typename TargetAllocatorT > +inline typename boost::enable_if_c< is_character_type< SourceCharT >::value && is_character_type< TargetCharT >::value && sizeof(SourceCharT) == sizeof(TargetCharT) >::type +code_convert(std::basic_string< SourceCharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale()) { - str2.append(str1.c_str(), str1.size()); + str2.append(reinterpret_cast< const TargetCharT* >(str1.c_str()), str1.size()); } //! The function converts one string to the character type of another -template< typename CharT, typename TargetTraitsT, typename TargetAllocatorT > -inline void code_convert(const CharT* str1, std::size_t len, std::basic_string< CharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale()) +template< typename SourceCharT, typename TargetCharT, typename TargetTraitsT, typename TargetAllocatorT > +inline typename boost::enable_if_c< is_character_type< SourceCharT >::value && is_character_type< TargetCharT >::value && sizeof(SourceCharT) == sizeof(TargetCharT) >::type +code_convert(const SourceCharT* str1, std::size_t len, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& = std::locale()) { - str2.append(str1, len); + str2.append(reinterpret_cast< const TargetCharT* >(str1), len); } //! The function converts one string to the character type of another template< typename SourceCharT, typename SourceTraitsT, typename SourceAllocatorT, typename TargetCharT, typename TargetTraitsT, typename TargetAllocatorT > -inline void code_convert(std::basic_string< SourceCharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& loc = std::locale()) +inline typename boost::enable_if_c< is_character_type< SourceCharT >::value && is_character_type< TargetCharT >::value && sizeof(SourceCharT) != sizeof(TargetCharT) >::type +code_convert(std::basic_string< SourceCharT, SourceTraitsT, SourceAllocatorT > const& str1, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& loc = std::locale()) +{ + aux::code_convert_impl(str1.c_str(), str1.size(), str2, loc); +} + +//! The function converts one string to the character type of another +template< typename SourceCharT, typename TargetCharT, typename TargetTraitsT, typename TargetAllocatorT > +inline typename boost::enable_if_c< is_character_type< SourceCharT >::value && is_character_type< TargetCharT >::value && sizeof(SourceCharT) != sizeof(TargetCharT) >::type +code_convert(const SourceCharT* str1, std::size_t len, std::basic_string< TargetCharT, TargetTraitsT, TargetAllocatorT >& str2, std::locale const& loc = std::locale()) { - aux::code_convert(str1.c_str(), str1.size(), str2, loc); + aux::code_convert_impl(str1, len, str2, loc); } //! The function converts the passed string to the narrow-character encoding diff --git a/boost/log/detail/config.hpp b/boost/log/detail/config.hpp index c5a73679ae..64b4412383 100644 --- a/boost/log/detail/config.hpp +++ b/boost/log/detail/config.hpp @@ -96,6 +96,13 @@ # define BOOST_LOG_BROKEN_CONSTANT_EXPRESSIONS #endif +#if defined(BOOST_NO_CXX11_HDR_CODECVT) + // The compiler does not support std::codecvt<char16_t> and std::codecvt<char32_t> specializations. + // The BOOST_NO_CXX11_HDR_CODECVT means there's no usable <codecvt>, which is slightly different from this macro. + // But in order for <codecvt> to be implemented the std::codecvt specializations have to be implemented as well. +# define BOOST_LOG_NO_CXX11_CODECVT_FACETS +#endif + #if defined(__CYGWIN__) // Boost.ASIO is broken on Cygwin # define BOOST_LOG_NO_ASIO diff --git a/boost/log/detail/event.hpp b/boost/log/detail/event.hpp index 4bb49822c1..0168e170e7 100644 --- a/boost/log/detail/event.hpp +++ b/boost/log/detail/event.hpp @@ -22,12 +22,15 @@ #ifndef BOOST_LOG_NO_THREADS #if defined(BOOST_THREAD_PLATFORM_PTHREAD) -# if defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0 -# if defined(__GNUC__) && defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4) -# include <semaphore.h> -# include <boost/cstdint.hpp> -# define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE -# endif +# include <boost/atomic/capabilities.hpp> +# if (defined(linux) || defined(__linux) || defined(__linux__)) && BOOST_ATOMIC_INT_LOCK_FREE == 2 +# include <boost/atomic/atomic.hpp> +# define BOOST_LOG_EVENT_USE_FUTEX +# elif defined(_POSIX_SEMAPHORES) && (_POSIX_SEMAPHORES + 0) > 0 && BOOST_ATOMIC_FLAG_LOCK_FREE == 2 +# include <semaphore.h> +# include <boost/cstdint.hpp> +# include <boost/atomic/atomic_flag.hpp> +# define BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE # endif #elif defined(BOOST_THREAD_PLATFORM_WIN32) # include <boost/cstdint.hpp> @@ -48,12 +51,37 @@ BOOST_LOG_OPEN_NAMESPACE namespace aux { -#if defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) +#if defined(BOOST_LOG_EVENT_USE_FUTEX) + +class futex_based_event +{ +private: + boost::atomic< int > m_state; + +public: + //! Default constructor + BOOST_LOG_API futex_based_event(); + //! Destructor + BOOST_LOG_API ~futex_based_event(); + + //! Waits for the object to become signalled + BOOST_LOG_API void wait(); + //! Sets the object to a signalled state + BOOST_LOG_API void set_signalled(); + + // Copying prohibited + BOOST_DELETED_FUNCTION(futex_based_event(futex_based_event const&)) + BOOST_DELETED_FUNCTION(futex_based_event& operator= (futex_based_event const&)) +}; + +typedef futex_based_event event; + +#elif defined(BOOST_LOG_EVENT_USE_POSIX_SEMAPHORE) class sem_based_event { private: - boost::uint32_t m_state; + boost::atomic_flag m_state; sem_t m_semaphore; public: diff --git a/boost/log/detail/is_character_type.hpp b/boost/log/detail/is_character_type.hpp new file mode 100644 index 0000000000..29f7dccd55 --- /dev/null +++ b/boost/log/detail/is_character_type.hpp @@ -0,0 +1,75 @@ +/* + * 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 is_character_type.hpp + * \author Andrey Semashev + * \date 25.07.2015 + * + * The header defines \c is_character_type trait which checks if the type is one of the character types + */ + +#ifndef BOOST_LOG_DETAIL_IS_CHARACTER_TYPE_HPP_INCLUDED_ +#define BOOST_LOG_DETAIL_IS_CHARACTER_TYPE_HPP_INCLUDED_ + +#include <boost/log/detail/config.hpp> +#include <boost/log/detail/header.hpp> + +#ifdef BOOST_HAS_PRAGMA_ONCE +#pragma once +#endif + +namespace boost { + +BOOST_LOG_OPEN_NAMESPACE + +namespace aux { + +template< typename T > +struct is_character_type +{ + static BOOST_CONSTEXPR_OR_CONST bool value = false; +}; + +template< > +struct is_character_type< char > +{ + static BOOST_CONSTEXPR_OR_CONST bool value = true; +}; + +#if !defined(BOOST_NO_INTRINSIC_WCHAR_T) +template< > +struct is_character_type< wchar_t > +{ + static BOOST_CONSTEXPR_OR_CONST bool value = true; +}; +#endif + +#if !defined(BOOST_NO_CXX11_CHAR16_T) +template< > +struct is_character_type< char16_t > +{ + static BOOST_CONSTEXPR_OR_CONST bool value = true; +}; +#endif + +#if !defined(BOOST_NO_CXX11_CHAR32_T) +template< > +struct is_character_type< char32_t > +{ + static BOOST_CONSTEXPR_OR_CONST bool value = true; +}; +#endif + +} // namespace aux + +BOOST_LOG_CLOSE_NAMESPACE // namespace log + +} // namespace boost + +#include <boost/log/detail/footer.hpp> + +#endif // BOOST_LOG_DETAIL_IS_CHARACTER_TYPE_HPP_INCLUDED_ diff --git a/boost/log/detail/visible_type.hpp b/boost/log/detail/is_ostream.hpp index 79f4007d2a..2131baebb5 100644 --- a/boost/log/detail/visible_type.hpp +++ b/boost/log/detail/is_ostream.hpp @@ -5,19 +5,23 @@ * http://www.boost.org/LICENSE_1_0.txt) */ /*! - * \file visible_type.hpp + * \file is_ostream.hpp * \author Andrey Semashev - * \date 08.03.2007 + * \date 05.07.2015 * * \brief This header is the Boost.Log library implementation, see the library documentation * at http://www.boost.org/doc/libs/release/libs/log/doc/html/index.html. In this file * internal configuration macros are defined. */ -#ifndef BOOST_LOG_DETAIL_VISIBLE_TYPE_HPP_INCLUDED_ -#define BOOST_LOG_DETAIL_VISIBLE_TYPE_HPP_INCLUDED_ +#ifndef BOOST_LOG_DETAIL_IS_OSTREAM_HPP_INCLUDED_ +#define BOOST_LOG_DETAIL_IS_OSTREAM_HPP_INCLUDED_ +#include <iosfwd> +#include <boost/type_traits/is_base_of.hpp> +#include <boost/type_traits/has_left_shift.hpp> #include <boost/log/detail/config.hpp> +#include <boost/log/utility/formatting_ostream_fwd.hpp> #include <boost/log/detail/header.hpp> #ifdef BOOST_HAS_PRAGMA_ONCE @@ -30,11 +34,16 @@ BOOST_LOG_OPEN_NAMESPACE namespace aux { -//! The wrapper type whose type_info is always visible template< typename T > -struct BOOST_SYMBOL_VISIBLE visible_type +struct is_ostream { - typedef T wrapped_type; + static BOOST_CONSTEXPR_OR_CONST bool value = is_base_of< std::ios_base, T >::value && has_left_shift< T, int >::value; +}; + +template< typename CharT, typename TraitsT, typename AllocatorT > +struct is_ostream< basic_formatting_ostream< CharT, TraitsT, AllocatorT > > +{ + static BOOST_CONSTEXPR_OR_CONST bool value = true; }; } // namespace aux @@ -45,4 +54,4 @@ BOOST_LOG_CLOSE_NAMESPACE // namespace log #include <boost/log/detail/footer.hpp> -#endif // BOOST_LOG_DETAIL_VISIBLE_TYPE_HPP_INCLUDED_ +#endif // BOOST_LOG_DETAIL_IS_OSTREAM_HPP_INCLUDED_ |