Back to home page

EIC code displayed by LXR

 
 

    


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

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   from_settings.hpp
0009  * \author Andrey Semashev
0010  * \date   11.10.2009
0011  *
0012  * The header contains definition of facilities that allows to initialize the library from
0013  * settings.
0014  */
0015 
0016 #ifndef BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
0017 #define BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_
0018 
0019 #include <string>
0020 #include <boost/smart_ptr/shared_ptr.hpp>
0021 #include <boost/core/enable_if.hpp>
0022 #include <boost/type_traits/is_base_and_derived.hpp>
0023 #include <boost/log/detail/setup_config.hpp>
0024 #include <boost/log/sinks/sink.hpp>
0025 #include <boost/log/utility/setup/settings.hpp>
0026 #include <boost/log/detail/header.hpp>
0027 
0028 #ifdef BOOST_HAS_PRAGMA_ONCE
0029 #pragma once
0030 #endif
0031 
0032 namespace boost {
0033 
0034 BOOST_LOG_OPEN_NAMESPACE
0035 
0036 /*!
0037  * The function initializes the logging library from a settings container
0038  *
0039  * \param setts Library settings container
0040  *
0041  * \b Throws: An <tt>std::exception</tt>-based exception if the provided settings are not valid.
0042  */
0043 template< typename CharT >
0044 BOOST_LOG_SETUP_API void init_from_settings(basic_settings_section< CharT > const& setts);
0045 
0046 
0047 /*!
0048  * Sink factory base interface
0049  */
0050 template< typename CharT >
0051 struct sink_factory
0052 {
0053     //! Character type
0054     typedef CharT char_type;
0055     //! String type
0056     typedef std::basic_string< char_type > string_type;
0057     //! Settings section type
0058     typedef basic_settings_section< char_type > settings_section;
0059 
0060     /*!
0061      * Default constructor
0062      */
0063     BOOST_DEFAULTED_FUNCTION(sink_factory(), {})
0064 
0065     /*!
0066      * Virtual destructor
0067      */
0068     virtual ~sink_factory() {}
0069 
0070     /*!
0071      * The function creates a formatter for the specified attribute.
0072      *
0073      * \param settings Sink parameters
0074      */
0075     virtual shared_ptr< sinks::sink > create_sink(settings_section const& settings) = 0;
0076 
0077     BOOST_DELETED_FUNCTION(sink_factory(sink_factory const&))
0078     BOOST_DELETED_FUNCTION(sink_factory& operator= (sink_factory const&))
0079 };
0080 
0081 /*!
0082  * \brief The function registers a factory for a custom sink
0083  *
0084  * The function registers a factory for a sink. The factory will be called to create sink
0085  * instance when the parser discovers the specified sink type in the settings file. The
0086  * factory must accept a map of parameters [parameter name -> parameter value] that it
0087  * may use to initialize the sink. The factory must return a non-NULL pointer to the
0088  * constructed sink instance.
0089  *
0090  * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
0091  *                  must not be NULL.
0092  * \param factory Pointer to the custom sink factory. Must not be NULL.
0093  */
0094 template< typename CharT >
0095 BOOST_LOG_SETUP_API void register_sink_factory(const char* sink_name, shared_ptr< sink_factory< CharT > > const& factory);
0096 
0097 /*!
0098  * \brief The function registers a factory for a custom sink
0099  *
0100  * The function registers a factory for a sink. The factory will be called to create sink
0101  * instance when the parser discovers the specified sink type in the settings file. The
0102  * factory must accept a map of parameters [parameter name -> parameter value] that it
0103  * may use to initialize the sink. The factory must return a non-NULL pointer to the
0104  * constructed sink instance.
0105  *
0106  * \param sink_name The custom sink name
0107  * \param factory Pointer to the custom sink factory. Must not be NULL.
0108  */
0109 template< typename CharT >
0110 inline void register_sink_factory(std::string const& sink_name, shared_ptr< sink_factory< CharT > > const& factory)
0111 {
0112     register_sink_factory(sink_name.c_str(), factory);
0113 }
0114 
0115 /*!
0116  * \brief The function registers a factory for a custom sink
0117  *
0118  * The function registers a factory for a sink. The factory will be called to create sink
0119  * instance when the parser discovers the specified sink type in the settings file. The
0120  * factory must accept a map of parameters [parameter name -> parameter value] that it
0121  * may use to initialize the sink. The factory must return a non-NULL pointer to the
0122  * constructed sink instance.
0123  *
0124  * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters,
0125  *                  must not be NULL.
0126  * \param factory Pointer to the custom sink factory. Must not be NULL.
0127  */
0128 template< typename FactoryT >
0129 inline typename boost::enable_if_c<
0130     is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >::value
0131 >::type register_sink_factory(const char* sink_name, shared_ptr< FactoryT > const& factory)
0132 {
0133     typedef sink_factory< typename FactoryT::char_type > factory_base;
0134     register_sink_factory(sink_name, boost::static_pointer_cast< factory_base >(factory));
0135 }
0136 
0137 /*!
0138  * \brief The function registers a factory for a custom sink
0139  *
0140  * The function registers a factory for a sink. The factory will be called to create sink
0141  * instance when the parser discovers the specified sink type in the settings file. The
0142  * factory must accept a map of parameters [parameter name -> parameter value] that it
0143  * may use to initialize the sink. The factory must return a non-NULL pointer to the
0144  * constructed sink instance.
0145  *
0146  * \param sink_name The custom sink name
0147  * \param factory Pointer to the custom sink factory. Must not be NULL.
0148  */
0149 template< typename FactoryT >
0150 inline typename boost::enable_if_c<
0151     is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT >::value
0152 >::type register_sink_factory(std::string const& sink_name, shared_ptr< FactoryT > const& factory)
0153 {
0154     typedef sink_factory< typename FactoryT::char_type > factory_base;
0155     register_sink_factory(sink_name.c_str(), boost::static_pointer_cast< factory_base >(factory));
0156 }
0157 
0158 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0159 
0160 } // namespace boost
0161 
0162 #include <boost/log/detail/footer.hpp>
0163 
0164 #endif // BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_