2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file formatters/csv_decorator.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of a CSV-style character decorator.
13 * See: http://en.wikipedia.org/wiki/Comma-separated_values
16 #ifndef BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_
17 #define BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_
19 #include <boost/range/iterator_range_core.hpp>
20 #include <boost/log/detail/config.hpp>
21 #include <boost/log/expressions/formatters/char_decorator.hpp>
22 #include <boost/log/detail/header.hpp>
24 #ifdef BOOST_HAS_PRAGMA_ONCE
30 BOOST_LOG_OPEN_NAMESPACE
32 namespace expressions {
37 struct csv_decorator_traits;
39 #ifdef BOOST_LOG_USE_CHAR
41 struct csv_decorator_traits< char >
43 static boost::iterator_range< const char* const* > get_patterns()
45 static const char* const patterns[] =
49 return boost::make_iterator_range(patterns);
51 static boost::iterator_range< const char* const* > get_replacements()
53 static const char* const replacements[] =
57 return boost::make_iterator_range(replacements);
60 #endif // BOOST_LOG_USE_CHAR
62 #ifdef BOOST_LOG_USE_WCHAR_T
64 struct csv_decorator_traits< wchar_t >
66 static boost::iterator_range< const wchar_t* const* > get_patterns()
68 static const wchar_t* const patterns[] =
72 return boost::make_iterator_range(patterns);
74 static boost::iterator_range< const wchar_t* const* > get_replacements()
76 static const wchar_t* const replacements[] =
80 return boost::make_iterator_range(replacements);
83 #endif // BOOST_LOG_USE_WCHAR_T
85 template< typename CharT >
86 struct csv_decorator_gen
88 typedef CharT char_type;
90 template< typename SubactorT >
91 BOOST_FORCEINLINE char_decorator_actor< SubactorT, pattern_replacer< char_type > > operator[] (SubactorT const& subactor) const
93 typedef csv_decorator_traits< char_type > traits_type;
94 typedef pattern_replacer< char_type > replacer_type;
95 typedef char_decorator_actor< SubactorT, replacer_type > result_type;
96 typedef typename result_type::terminal_type terminal_type;
97 typename result_type::base_type act = {{ terminal_type(subactor, replacer_type(traits_type::get_patterns(), traits_type::get_replacements())) }};
98 return result_type(act);
105 * CSV-style decorator generator object. The decorator doubles double quotes that may be found
106 * in the output. See http://en.wikipedia.org/wiki/Comma-separated_values for more information on
107 * the CSV format. The generator provides <tt>operator[]</tt> that can be used to construct
108 * the actual decorator. For example:
111 * csv_decor[ stream << attr< std::string >("MyAttr") ]
114 * For wide-character formatting there is the similar \c wcsv_decor decorator generator object.
116 #ifdef BOOST_LOG_USE_CHAR
117 const aux::csv_decorator_gen< char > csv_decor = {};
119 #ifdef BOOST_LOG_USE_WCHAR_T
120 const aux::csv_decorator_gen< wchar_t > wcsv_decor = {};
124 * The function creates an CSV-style decorator generator for arbitrary character type.
126 template< typename CharT >
127 BOOST_FORCEINLINE aux::csv_decorator_gen< CharT > make_csv_decor()
129 return aux::csv_decorator_gen< CharT >();
132 } // namespace expressions
134 BOOST_LOG_CLOSE_NAMESPACE // namespace log
138 #include <boost/log/detail/footer.hpp>
140 #endif // BOOST_LOG_EXPRESSIONS_FORMATTERS_CSV_DECORATOR_HPP_INCLUDED_