Chris@16: /* Chris@101: * Copyright Andrey Semashev 2007 - 2015. Chris@16: * Distributed under the Boost Software License, Version 1.0. Chris@16: * (See accompanying file LICENSE_1_0.txt or copy at Chris@16: * http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: /*! Chris@16: * \file from_settings.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 11.10.2009 Chris@16: * Chris@16: * The header contains definition of facilities that allows to initialize the library from Chris@16: * settings. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_ Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #ifdef BOOST_HAS_PRAGMA_ONCE Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: namespace boost { Chris@16: Chris@16: BOOST_LOG_OPEN_NAMESPACE Chris@16: Chris@16: /*! Chris@16: * The function initializes the logging library from a settings container Chris@16: * Chris@16: * \param setts Library settings container Chris@16: * Chris@16: * \b Throws: An std::exception-based exception if the provided settings are not valid. Chris@16: */ Chris@16: template< typename CharT > Chris@16: BOOST_LOG_SETUP_API void init_from_settings(basic_settings_section< CharT > const& setts); Chris@16: Chris@16: Chris@16: /*! Chris@16: * Sink factory base interface Chris@16: */ Chris@16: template< typename CharT > Chris@16: struct sink_factory Chris@16: { Chris@16: //! Character type Chris@16: typedef CharT char_type; Chris@16: //! String type Chris@16: typedef std::basic_string< char_type > string_type; Chris@16: //! Settings section type Chris@16: typedef basic_settings_section< char_type > settings_section; Chris@16: Chris@16: /*! Chris@16: * Default constructor Chris@16: */ Chris@16: BOOST_DEFAULTED_FUNCTION(sink_factory(), {}) Chris@16: Chris@16: /*! Chris@16: * Virtual destructor Chris@16: */ Chris@16: virtual ~sink_factory() {} Chris@16: Chris@16: /*! Chris@16: * The function creates a formatter for the specified attribute. Chris@16: * Chris@16: * \param settings Sink parameters Chris@16: */ Chris@16: virtual shared_ptr< sinks::sink > create_sink(settings_section const& settings) = 0; Chris@16: Chris@16: BOOST_DELETED_FUNCTION(sink_factory(sink_factory const&)) Chris@16: BOOST_DELETED_FUNCTION(sink_factory& operator= (sink_factory const&)) Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * \brief The function registers a factory for a custom sink Chris@16: * Chris@16: * The function registers a factory for a sink. The factory will be called to create sink Chris@16: * instance when the parser discovers the specified sink type in the settings file. The Chris@16: * factory must accept a map of parameters [parameter name -> parameter value] that it Chris@16: * may use to initialize the sink. The factory must return a non-NULL pointer to the Chris@16: * constructed sink instance. Chris@16: * Chris@16: * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters, Chris@16: * must not be NULL. Chris@16: * \param factory Pointer to the custom sink factory. Must not be NULL. Chris@16: */ Chris@16: template< typename CharT > Chris@16: BOOST_LOG_SETUP_API void register_sink_factory(const char* sink_name, shared_ptr< sink_factory< CharT > > const& factory); Chris@16: Chris@16: /*! Chris@16: * \brief The function registers a factory for a custom sink Chris@16: * Chris@16: * The function registers a factory for a sink. The factory will be called to create sink Chris@16: * instance when the parser discovers the specified sink type in the settings file. The Chris@16: * factory must accept a map of parameters [parameter name -> parameter value] that it Chris@16: * may use to initialize the sink. The factory must return a non-NULL pointer to the Chris@16: * constructed sink instance. Chris@16: * Chris@16: * \param sink_name The custom sink name Chris@16: * \param factory Pointer to the custom sink factory. Must not be NULL. Chris@16: */ Chris@16: template< typename CharT > Chris@16: inline void register_sink_factory(std::string const& sink_name, shared_ptr< sink_factory< CharT > > const& factory) Chris@16: { Chris@16: register_sink_factory(sink_name.c_str(), factory); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * \brief The function registers a factory for a custom sink Chris@16: * Chris@16: * The function registers a factory for a sink. The factory will be called to create sink Chris@16: * instance when the parser discovers the specified sink type in the settings file. The Chris@16: * factory must accept a map of parameters [parameter name -> parameter value] that it Chris@16: * may use to initialize the sink. The factory must return a non-NULL pointer to the Chris@16: * constructed sink instance. Chris@16: * Chris@16: * \param sink_name The custom sink name. Must point to a zero-terminated sequence of characters, Chris@16: * must not be NULL. Chris@16: * \param factory Pointer to the custom sink factory. Must not be NULL. Chris@16: */ Chris@16: template< typename FactoryT > Chris@16: inline typename enable_if< Chris@16: is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT > Chris@16: >::type register_sink_factory(const char* sink_name, shared_ptr< FactoryT > const& factory) Chris@16: { Chris@16: typedef sink_factory< typename FactoryT::char_type > factory_base; Chris@16: register_sink_factory(sink_name, boost::static_pointer_cast< factory_base >(factory)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * \brief The function registers a factory for a custom sink Chris@16: * Chris@16: * The function registers a factory for a sink. The factory will be called to create sink Chris@16: * instance when the parser discovers the specified sink type in the settings file. The Chris@16: * factory must accept a map of parameters [parameter name -> parameter value] that it Chris@16: * may use to initialize the sink. The factory must return a non-NULL pointer to the Chris@16: * constructed sink instance. Chris@16: * Chris@16: * \param sink_name The custom sink name Chris@16: * \param factory Pointer to the custom sink factory. Must not be NULL. Chris@16: */ Chris@16: template< typename FactoryT > Chris@16: inline typename enable_if< Chris@16: is_base_and_derived< sink_factory< typename FactoryT::char_type >, FactoryT > Chris@16: >::type register_sink_factory(std::string const& sink_name, shared_ptr< FactoryT > const& factory) Chris@16: { Chris@16: typedef sink_factory< typename FactoryT::char_type > factory_base; Chris@16: register_sink_factory(sink_name.c_str(), boost::static_pointer_cast< factory_base >(factory)); Chris@16: } Chris@16: Chris@16: BOOST_LOG_CLOSE_NAMESPACE // namespace log Chris@16: Chris@16: } // namespace boost Chris@16: Chris@16: #include Chris@16: Chris@16: #endif // BOOST_LOG_UTILITY_SETUP_FROM_SETTINGS_HPP_INCLUDED_