File indexing completed on 2025-01-18 09:39:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef BOOST_LOG_UTILITY_SETUP_FORMATTER_PARSER_HPP_INCLUDED_
0017 #define BOOST_LOG_UTILITY_SETUP_FORMATTER_PARSER_HPP_INCLUDED_
0018
0019 #include <iosfwd>
0020 #include <map>
0021 #include <string>
0022 #include <boost/smart_ptr/shared_ptr.hpp>
0023 #include <boost/smart_ptr/make_shared_object.hpp>
0024 #include <boost/core/enable_if.hpp>
0025 #include <boost/type_traits/is_base_and_derived.hpp>
0026 #include <boost/log/detail/setup_config.hpp>
0027 #include <boost/log/attributes/attribute_name.hpp>
0028 #include <boost/log/core/record.hpp>
0029 #include <boost/log/expressions/formatter.hpp>
0030 #include <boost/log/expressions/attr.hpp>
0031 #include <boost/log/expressions/formatters/stream.hpp>
0032 #include <boost/log/detail/header.hpp>
0033
0034 #ifdef BOOST_HAS_PRAGMA_ONCE
0035 #pragma once
0036 #endif
0037
0038 namespace boost {
0039
0040 BOOST_LOG_OPEN_NAMESPACE
0041
0042
0043
0044
0045 template< typename CharT >
0046 struct formatter_factory
0047 {
0048
0049 typedef CharT char_type;
0050
0051 typedef std::basic_string< char_type > string_type;
0052
0053 typedef basic_formatter< char_type > formatter_type;
0054
0055
0056
0057
0058 typedef std::map< string_type, string_type > args_map;
0059
0060
0061
0062
0063 BOOST_DEFAULTED_FUNCTION(formatter_factory(), {})
0064
0065
0066
0067
0068 virtual ~formatter_factory() {}
0069
0070
0071
0072
0073
0074
0075
0076 virtual formatter_type create_formatter(attribute_name const& name, args_map const& args) = 0;
0077
0078 BOOST_DELETED_FUNCTION(formatter_factory(formatter_factory const&))
0079 BOOST_DELETED_FUNCTION(formatter_factory& operator= (formatter_factory const&))
0080 };
0081
0082
0083
0084
0085
0086 template< typename CharT, typename AttributeValueT >
0087 class basic_formatter_factory :
0088 public formatter_factory< CharT >
0089 {
0090 private:
0091 typedef formatter_factory< CharT > base_type;
0092
0093 public:
0094
0095 typedef AttributeValueT value_type;
0096
0097 typedef typename base_type::formatter_type formatter_type;
0098 typedef typename base_type::args_map args_map;
0099
0100
0101
0102
0103
0104
0105
0106 formatter_type create_formatter(attribute_name const& name, args_map const& args)
0107 {
0108 return formatter_type(expressions::stream << expressions::attr< value_type >(name));
0109 }
0110 };
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 template< typename CharT >
0124 BOOST_LOG_SETUP_API void register_formatter_factory(
0125 attribute_name const& attr_name, shared_ptr< formatter_factory< CharT > > const& factory);
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138 template< typename FactoryT >
0139 inline typename boost::enable_if_c<
0140 is_base_and_derived< formatter_factory< typename FactoryT::char_type >, FactoryT >::value
0141 >::type register_formatter_factory(attribute_name const& attr_name, shared_ptr< FactoryT > const& factory)
0142 {
0143 typedef formatter_factory< typename FactoryT::char_type > factory_base;
0144 register_formatter_factory(attr_name, boost::static_pointer_cast< factory_base >(factory));
0145 }
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159 template< typename AttributeValueT, typename CharT >
0160 inline void register_simple_formatter_factory(attribute_name const& attr_name)
0161 {
0162 shared_ptr< formatter_factory< CharT > > factory =
0163 boost::make_shared< basic_formatter_factory< CharT, AttributeValueT > >();
0164 register_formatter_factory(attr_name, factory);
0165 }
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177 template< typename CharT >
0178 BOOST_LOG_SETUP_API basic_formatter< CharT > parse_formatter(const CharT* begin, const CharT* end);
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188 template< typename CharT, typename TraitsT, typename AllocatorT >
0189 inline basic_formatter< CharT > parse_formatter(std::basic_string< CharT, TraitsT, AllocatorT > const& str)
0190 {
0191 const CharT* p = str.c_str();
0192 return parse_formatter(p, p + str.size());
0193 }
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204 template< typename CharT >
0205 inline basic_formatter< CharT > parse_formatter(const CharT* str)
0206 {
0207 return parse_formatter(str, str + std::char_traits< CharT >::length(str));
0208 }
0209
0210 BOOST_LOG_CLOSE_NAMESPACE
0211
0212 }
0213
0214 #include <boost/log/detail/footer.hpp>
0215
0216 #endif