123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #ifndef BOOST_LOG_UTILITY_SETUP_FORMATTER_PARSER_HPP_INCLUDED_
- #define BOOST_LOG_UTILITY_SETUP_FORMATTER_PARSER_HPP_INCLUDED_
- #include <iosfwd>
- #include <map>
- #include <string>
- #include <boost/smart_ptr/shared_ptr.hpp>
- #include <boost/smart_ptr/make_shared_object.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/type_traits/is_base_and_derived.hpp>
- #include <boost/log/detail/setup_config.hpp>
- #include <boost/log/attributes/attribute_name.hpp>
- #include <boost/log/core/record.hpp>
- #include <boost/log/expressions/formatter.hpp>
- #include <boost/log/expressions/attr.hpp>
- #include <boost/log/expressions/formatters/stream.hpp>
- #include <boost/log/detail/header.hpp>
- #ifdef BOOST_HAS_PRAGMA_ONCE
- #pragma once
- #endif
- namespace boost {
- BOOST_LOG_OPEN_NAMESPACE
- template< typename CharT >
- struct formatter_factory
- {
-
- typedef CharT char_type;
-
- typedef std::basic_string< char_type > string_type;
-
- typedef basic_formatter< char_type > formatter_type;
-
- typedef std::map< string_type, string_type > args_map;
-
- BOOST_DEFAULTED_FUNCTION(formatter_factory(), {})
-
- virtual ~formatter_factory() {}
-
- virtual formatter_type create_formatter(attribute_name const& name, args_map const& args) = 0;
- BOOST_DELETED_FUNCTION(formatter_factory(formatter_factory const&))
- BOOST_DELETED_FUNCTION(formatter_factory& operator= (formatter_factory const&))
- };
- template< typename CharT, typename AttributeValueT >
- class basic_formatter_factory :
- public formatter_factory< CharT >
- {
- private:
- typedef formatter_factory< CharT > base_type;
- public:
-
- typedef AttributeValueT value_type;
-
- typedef typename base_type::formatter_type formatter_type;
- typedef typename base_type::args_map args_map;
-
- formatter_type create_formatter(attribute_name const& name, args_map const& args)
- {
- return formatter_type(expressions::stream << expressions::attr< value_type >(name));
- }
- };
- template< typename CharT >
- BOOST_LOG_SETUP_API void register_formatter_factory(
- attribute_name const& attr_name, shared_ptr< formatter_factory< CharT > > const& factory);
- template< typename FactoryT >
- inline typename boost::enable_if_c<
- is_base_and_derived< formatter_factory< typename FactoryT::char_type >, FactoryT >::value
- >::type register_formatter_factory(attribute_name const& attr_name, shared_ptr< FactoryT > const& factory)
- {
- typedef formatter_factory< typename FactoryT::char_type > factory_base;
- register_formatter_factory(attr_name, boost::static_pointer_cast< factory_base >(factory));
- }
- template< typename AttributeValueT, typename CharT >
- inline void register_simple_formatter_factory(attribute_name const& attr_name)
- {
- shared_ptr< formatter_factory< CharT > > factory =
- boost::make_shared< basic_formatter_factory< CharT, AttributeValueT > >();
- register_formatter_factory(attr_name, factory);
- }
- template< typename CharT >
- BOOST_LOG_SETUP_API basic_formatter< CharT > parse_formatter(const CharT* begin, const CharT* end);
- template< typename CharT, typename TraitsT, typename AllocatorT >
- inline basic_formatter< CharT > parse_formatter(std::basic_string< CharT, TraitsT, AllocatorT > const& str)
- {
- const CharT* p = str.c_str();
- return parse_formatter(p, p + str.size());
- }
- template< typename CharT >
- inline basic_formatter< CharT > parse_formatter(const CharT* str)
- {
- return parse_formatter(str, str + std::char_traits< CharT >::length(str));
- }
- BOOST_LOG_CLOSE_NAMESPACE
- }
- #include <boost/log/detail/footer.hpp>
- #endif
|