Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:39:22

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/csv_decorator.hpp
0009  * \author Andrey Semashev
0010  * \date   18.11.2012
0011  *
0012  * The header contains implementation of a CSV-style character decorator.
0013  * See: http://en.wikipedia.org/wiki/Comma-separated_values
0014  */
0015 
0016 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_
0017 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_
0018 
0019 #include <boost/range/iterator_range_core.hpp>
0020 #include <boost/log/detail/config.hpp>
0021 #include <boost/log/expressions/formatters/char_decorator.hpp>
0022 #include <boost/log/detail/header.hpp>
0023 
0024 #ifdef BOOST_HAS_PRAGMA_ONCE
0025 #pragma once
0026 #endif
0027 
0028 namespace boost {
0029 
0030 BOOST_LOG_OPEN_NAMESPACE
0031 
0032 namespace expressions {
0033 
0034 namespace aux {
0035 
0036 template< typename >
0037 struct csv_decorator_traits;
0038 
0039 #ifdef BOOST_LOG_USE_CHAR
0040 template< >
0041 struct csv_decorator_traits< char >
0042 {
0043     static boost::iterator_range< const char* const* > get_patterns()
0044     {
0045         static const char* const patterns[] =
0046         {
0047             "\""
0048         };
0049         return boost::make_iterator_range(patterns);
0050     }
0051     static boost::iterator_range< const char* const* > get_replacements()
0052     {
0053         static const char* const replacements[] =
0054         {
0055             "\"\""
0056         };
0057         return boost::make_iterator_range(replacements);
0058     }
0059 };
0060 #endif // BOOST_LOG_USE_CHAR
0061 
0062 #ifdef BOOST_LOG_USE_WCHAR_T
0063 template< >
0064 struct csv_decorator_traits< wchar_t >
0065 {
0066     static boost::iterator_range< const wchar_t* const* > get_patterns()
0067     {
0068         static const wchar_t* const patterns[] =
0069         {
0070             L"\""
0071         };
0072         return boost::make_iterator_range(patterns);
0073     }
0074     static boost::iterator_range< const wchar_t* const* > get_replacements()
0075     {
0076         static const wchar_t* const replacements[] =
0077         {
0078             L"\"\""
0079         };
0080         return boost::make_iterator_range(replacements);
0081     }
0082 };
0083 #endif // BOOST_LOG_USE_WCHAR_T
0084 
0085 template< typename CharT >
0086 struct csv_decorator_gen
0087 {
0088     typedef CharT char_type;
0089 
0090     template< typename SubactorT >
0091     BOOST_FORCEINLINE char_decorator_actor< SubactorT, pattern_replacer< char_type > > operator[] (SubactorT const& subactor) const
0092     {
0093         typedef csv_decorator_traits< char_type > traits_type;
0094         typedef pattern_replacer< char_type > replacer_type;
0095         typedef char_decorator_actor< SubactorT, replacer_type > result_type;
0096         typedef typename result_type::terminal_type terminal_type;
0097         typename result_type::base_type act = {{ terminal_type(subactor, replacer_type(traits_type::get_patterns(), traits_type::get_replacements())) }};
0098         return result_type(act);
0099     }
0100 };
0101 
0102 } // namespace aux
0103 
0104 /*!
0105  * CSV-style decorator generator object. The decorator doubles double quotes that may be found
0106  * in the output. See http://en.wikipedia.org/wiki/Comma-separated_values for more information on
0107  * the CSV format. The generator provides <tt>operator[]</tt> that can be used to construct
0108  * the actual decorator. For example:
0109  *
0110  * <code>
0111  * csv_decor[ stream << attr< std::string >("MyAttr") ]
0112  * </code>
0113  *
0114  * For wide-character formatting there is the similar \c wcsv_decor decorator generator object.
0115  */
0116 #ifdef BOOST_LOG_USE_CHAR
0117 BOOST_INLINE_VARIABLE const aux::csv_decorator_gen< char > csv_decor = {};
0118 #endif
0119 #ifdef BOOST_LOG_USE_WCHAR_T
0120 BOOST_INLINE_VARIABLE const aux::csv_decorator_gen< wchar_t > wcsv_decor = {};
0121 #endif
0122 
0123 /*!
0124  * The function creates an CSV-style decorator generator for arbitrary character type.
0125  */
0126 template< typename CharT >
0127 BOOST_FORCEINLINE aux::csv_decorator_gen< CharT > make_csv_decor()
0128 {
0129     return aux::csv_decorator_gen< CharT >();
0130 }
0131 
0132 } // namespace expressions
0133 
0134 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0135 
0136 } // namespace boost
0137 
0138 #include <boost/log/detail/footer.hpp>
0139 
0140 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_