Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:54:23

0001 /*
0002  *          Copyright Andrey Semashev 2007 - 2015.
0003  * Distributed under the Boost Software License, Version 1.0.
0004  *    (See accompanying file LICENSE_1_0.txt or copy at
0005  *          http://www.boost.org/LICENSE_1_0.txt)
0006  */
0007 /*!
0008  * \file   formatters/xml_decorator.hpp
0009  * \author Andrey Semashev
0010  * \date   18.11.2012
0011  *
0012  * The header contains implementation of a XML-style character decorator.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_
0017 
0018 #include <boost/range/iterator_range_core.hpp>
0019 #include <boost/log/detail/config.hpp>
0020 #include <boost/log/expressions/formatters/char_decorator.hpp>
0021 #include <boost/log/detail/header.hpp>
0022 
0023 #ifdef BOOST_HAS_PRAGMA_ONCE
0024 #pragma once
0025 #endif
0026 
0027 namespace boost {
0028 
0029 BOOST_LOG_OPEN_NAMESPACE
0030 
0031 namespace expressions {
0032 
0033 namespace aux {
0034 
0035 template< typename >
0036 struct xml_decorator_traits;
0037 
0038 #ifdef BOOST_LOG_USE_CHAR
0039 template< >
0040 struct xml_decorator_traits< char >
0041 {
0042     static boost::iterator_range< const char* const* > get_patterns()
0043     {
0044         static const char* const patterns[] =
0045         {
0046             "&", "<", ">", "\"", "'"
0047         };
0048         return boost::make_iterator_range(patterns);
0049     }
0050     static boost::iterator_range< const char* const* > get_replacements()
0051     {
0052         static const char* const replacements[] =
0053         {
0054             "&amp;", "&lt;", "&gt;", "&quot;", "&apos;"
0055         };
0056         return boost::make_iterator_range(replacements);
0057     }
0058 };
0059 #endif // BOOST_LOG_USE_CHAR
0060 
0061 #ifdef BOOST_LOG_USE_WCHAR_T
0062 template< >
0063 struct xml_decorator_traits< wchar_t >
0064 {
0065     static boost::iterator_range< const wchar_t* const* > get_patterns()
0066     {
0067         static const wchar_t* const patterns[] =
0068         {
0069             L"&", L"<", L">", L"\"", L"'"
0070         };
0071         return boost::make_iterator_range(patterns);
0072     }
0073     static boost::iterator_range< const wchar_t* const* > get_replacements()
0074     {
0075         static const wchar_t* const replacements[] =
0076         {
0077             L"&amp;", L"&lt;", L"&gt;", L"&quot;", L"&apos;"
0078         };
0079         return boost::make_iterator_range(replacements);
0080     }
0081 };
0082 #endif // BOOST_LOG_USE_WCHAR_T
0083 
0084 template< typename CharT >
0085 struct xml_decorator_gen
0086 {
0087     typedef CharT char_type;
0088 
0089     template< typename SubactorT >
0090     BOOST_FORCEINLINE char_decorator_actor< SubactorT, pattern_replacer< char_type > > operator[] (SubactorT const& subactor) const
0091     {
0092         typedef xml_decorator_traits< char_type > traits_type;
0093         typedef pattern_replacer< char_type > replacer_type;
0094         typedef char_decorator_actor< SubactorT, replacer_type > result_type;
0095         typedef typename result_type::terminal_type terminal_type;
0096         typename result_type::base_type act = {{ terminal_type(subactor, replacer_type(traits_type::get_patterns(), traits_type::get_replacements())) }};
0097         return result_type(act);
0098     }
0099 };
0100 
0101 } // namespace aux
0102 
0103 /*!
0104  * XML-style decorator generator object. The decorator replaces characters that have special meaning
0105  * in XML documents with the corresponding decorated counterparts. The generator provides
0106  * <tt>operator[]</tt> that can be used to construct the actual decorator. For example:
0107  *
0108  * <code>
0109  * xml_decor[ stream << attr< std::string >("MyAttr") ]
0110  * </code>
0111  *
0112  * For wide-character formatting there is the similar \c wxml_decor decorator generator object.
0113  */
0114 #ifdef BOOST_LOG_USE_CHAR
0115 BOOST_INLINE_VARIABLE const aux::xml_decorator_gen< char > xml_decor = {};
0116 #endif
0117 #ifdef BOOST_LOG_USE_WCHAR_T
0118 BOOST_INLINE_VARIABLE const aux::xml_decorator_gen< wchar_t > wxml_decor = {};
0119 #endif
0120 
0121 /*!
0122  * The function creates an XML-style decorator generator for arbitrary character type.
0123  */
0124 template< typename CharT >
0125 BOOST_FORCEINLINE aux::xml_decorator_gen< CharT > make_xml_decor()
0126 {
0127     return aux::xml_decorator_gen< CharT >();
0128 }
0129 
0130 } // namespace expressions
0131 
0132 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0133 
0134 } // namespace boost
0135 
0136 #include <boost/log/detail/footer.hpp>
0137 
0138 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_XML_DECORATOR_HPP_INCLUDED_