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 value_extraction.hpp Chris@16: * \author Andrey Semashev Chris@16: * \date 01.03.2008 Chris@16: * Chris@16: * The header contains implementation of tools for extracting an attribute value Chris@16: * from the view. Chris@16: */ Chris@16: Chris@16: #ifndef BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_ Chris@16: #define BOOST_LOG_ATTRIBUTES_VALUE_EXTRACTION_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: #include 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: #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: namespace result_of { Chris@16: Chris@16: /*! Chris@16: * \brief A metafunction that allows to acquire the result of the value extraction Chris@16: * Chris@16: * The metafunction results in a type that is in form of T const&, if \c T is Chris@16: * not an MPL type sequence and DefaultT is the same as T, Chris@16: * or value_ref< TypesT, TagT > otherwise, with Chris@16: * \c TypesT being a type sequence comprising the types from sequence \c T and \c DefaultT, Chris@16: * if it is not present in \c T already. Chris@16: */ Chris@16: template< typename T, typename DefaultT, typename TagT > Chris@16: struct extract_or_default Chris@16: { Chris@16: typedef typename mpl::eval_if< Chris@16: mpl::is_sequence< T >, Chris@16: mpl::eval_if< Chris@16: mpl::contains< T, DefaultT >, Chris@16: mpl::identity< T >, Chris@16: mpl::push_back< T, DefaultT > Chris@16: >, Chris@16: mpl::if_< Chris@16: is_same< T, DefaultT >, Chris@16: T, Chris@16: mpl::vector2< T, DefaultT > Chris@16: > Chris@16: >::type extracted_type; Chris@16: Chris@16: typedef typename mpl::if_< Chris@16: mpl::is_sequence< extracted_type >, Chris@16: value_ref< extracted_type, TagT >, Chris@16: extracted_type const& Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * \brief A metafunction that allows to acquire the result of the value extraction Chris@16: * Chris@16: * The metafunction results in a type that is in form of T const&, if \c T is Chris@16: * not an MPL type sequence, or value_ref< T, TagT > otherwise. In the latter Chris@16: * case the value reference shall never be empty. Chris@16: */ Chris@16: template< typename T, typename TagT > Chris@16: struct extract_or_throw Chris@16: { Chris@16: typedef typename mpl::if_< Chris@16: mpl::is_sequence< T >, Chris@16: value_ref< T, TagT >, Chris@16: T const& Chris@16: >::type type; Chris@16: }; Chris@16: Chris@16: /*! Chris@16: * \brief A metafunction that allows to acquire the result of the value extraction Chris@16: * Chris@16: * The metafunction results in a type that is in form of value_ref< T, TagT >. Chris@16: */ Chris@16: template< typename T, typename TagT > Chris@16: struct extract Chris@16: { Chris@16: typedef value_ref< T, TagT > type; Chris@16: }; Chris@16: Chris@16: } // namespace result_of Chris@16: Chris@16: namespace aux { Chris@16: Chris@16: //! The function object initializes the value reference Chris@16: template< typename RefT > Chris@16: struct value_ref_initializer Chris@16: { Chris@16: typedef void result_type; Chris@16: Chris@16: value_ref_initializer(RefT& ref) : m_ref(ref) Chris@16: { Chris@16: } Chris@16: Chris@16: template< typename ArgT > Chris@16: result_type operator() (ArgT const& arg) const Chris@16: { Chris@16: m_ref = RefT(arg); Chris@16: } Chris@16: Chris@16: private: Chris@16: RefT& m_ref; Chris@16: }; Chris@16: Chris@16: //! The function unwraps \c value_ref, if possible Chris@16: template< typename T, typename TagT > Chris@16: BOOST_FORCEINLINE typename enable_if< mpl::is_sequence< T >, value_ref< T, TagT > >::type Chris@16: unwrap_value_ref(value_ref< T, TagT > const& r) Chris@16: { Chris@16: return r; Chris@16: } Chris@16: Chris@16: template< typename T, typename TagT > Chris@16: BOOST_FORCEINLINE typename disable_if< mpl::is_sequence< T >, T const& >::type Chris@16: unwrap_value_ref(value_ref< T, TagT > const& r) Chris@16: { Chris@16: return r.get(); Chris@16: } Chris@16: Chris@16: } // namespace aux Chris@16: Chris@16: /*! Chris@16: * \brief Generic attribute value extractor Chris@16: * Chris@16: * Attribute value extractor is a functional object that attempts to find and extract the stored Chris@16: * attribute value from the attribute values view or a log record. The extracted value is returned Chris@16: * from the extractor. Chris@16: */ Chris@16: template< typename T, typename FallbackPolicyT, typename TagT > Chris@16: class value_extractor : Chris@16: private FallbackPolicyT Chris@16: { Chris@16: public: Chris@16: //! Fallback policy Chris@16: typedef FallbackPolicyT fallback_policy; Chris@16: //! Attribute value types Chris@16: typedef T value_type; Chris@16: //! Function object result type Chris@16: typedef value_ref< value_type, TagT > result_type; Chris@16: Chris@16: public: Chris@16: /*! Chris@16: * Default constructor Chris@16: */ Chris@16: BOOST_DEFAULTED_FUNCTION(value_extractor(), {}) Chris@16: Chris@16: /*! Chris@16: * Copy constructor Chris@16: */ Chris@16: value_extractor(value_extractor const& that) : fallback_policy(static_cast< fallback_policy const& >(that)) Chris@16: { Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Constructor Chris@16: * Chris@16: * \param arg Fallback policy constructor argument Chris@16: */ Chris@16: template< typename U > Chris@16: explicit value_extractor(U const& arg) : fallback_policy(arg) {} Chris@16: Chris@16: /*! Chris@16: * Extraction operator. Attempts to acquire the stored value of one of the supported types. If extraction succeeds, Chris@16: * the extracted value is returned. Chris@16: * Chris@16: * \param attr The attribute value to extract from. Chris@16: * \return The extracted value, if extraction succeeded, an empty value otherwise. Chris@16: */ Chris@16: result_type operator() (attribute_value const& attr) const Chris@16: { Chris@16: result_type res; Chris@16: aux::value_ref_initializer< result_type > initializer(res); Chris@16: if (!!attr) Chris@16: { Chris@16: static_type_dispatcher< value_type > disp(initializer); Chris@16: if (!attr.dispatch(disp) && !fallback_policy::apply_default(initializer)) Chris@16: fallback_policy::on_invalid_type(attr.get_type()); Chris@16: } Chris@16: else if (!fallback_policy::apply_default(initializer)) Chris@16: { Chris@16: fallback_policy::on_missing_value(); Chris@16: } Chris@16: return res; Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Extraction operator. Looks for an attribute value with the specified name Chris@16: * and tries to acquire the stored value of one of the supported types. If extraction succeeds, Chris@16: * the extracted value is returned. Chris@16: * Chris@16: * \param name Attribute value name. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \return The extracted value, if extraction succeeded, an empty value otherwise. Chris@16: */ Chris@16: result_type operator() (attribute_name const& name, attribute_value_set const& attrs) const Chris@16: { Chris@16: try Chris@16: { Chris@16: attribute_value_set::const_iterator it = attrs.find(name); Chris@16: if (it != attrs.end()) Chris@16: return operator() (it->second); Chris@16: else Chris@16: return operator() (attribute_value()); Chris@16: } Chris@16: catch (exception& e) Chris@16: { Chris@16: // Attach the attribute name to the exception Chris@16: boost::log::aux::attach_attribute_name_info(e, name); Chris@16: throw; Chris@16: } Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Extraction operator. Looks for an attribute value with the specified name Chris@16: * and tries to acquire the stored value of one of the supported types. If extraction succeeds, Chris@16: * the extracted value is returned. Chris@16: * Chris@16: * \param name Attribute value name. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value, if extraction succeeded, an empty value otherwise. Chris@16: */ Chris@16: result_type operator() (attribute_name const& name, record const& rec) const Chris@16: { Chris@16: return operator() (name, rec.attribute_values()); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * Extraction operator. Looks for an attribute value with the specified name Chris@16: * and tries to acquire the stored value of one of the supported types. If extraction succeeds, Chris@16: * the extracted value is returned. Chris@16: * Chris@16: * \param name Attribute value name. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value, if extraction succeeded, an empty value otherwise. Chris@16: */ Chris@16: result_type operator() (attribute_name const& name, record_view const& rec) const Chris@16: { Chris@16: return operator() (name, rec.attribute_values()); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * \returns Fallback policy Chris@16: */ Chris@16: fallback_policy const& get_fallback_policy() const Chris@16: { Chris@16: return *static_cast< fallback_policy const* >(this); Chris@16: } Chris@16: }; Chris@16: Chris@16: #if !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: #if !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) Chris@16: #define BOOST_LOG_AUX_VOID_DEFAULT = void Chris@16: #else Chris@16: #define BOOST_LOG_AUX_VOID_DEFAULT Chris@16: #endif Chris@16: #endif // !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< T, fallback_to_none, TagT > extractor; Chris@16: return extractor(name, attrs); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_none, TagT > extractor; Chris@16: return extractor(name, rec); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract< T, TagT >::type extract(attribute_name const& name, record_view const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_none, TagT > extractor; Chris@16: return extractor(name, rec); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param value Attribute value. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract< T, TagT >::type extract(attribute_value const& value) Chris@16: { Chris@16: value_extractor< T, fallback_to_none, TagT > extractor; Chris@16: return extractor(value); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw, TagT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, attrs)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw, TagT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_name const& name, record_view const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw, TagT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param value Attribute value. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT > Chris@16: inline typename result_of::extract_or_throw< T, TagT >::type extract_or_throw(attribute_value const& value) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw, TagT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(value)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT, TagT >::type Chris@16: extract_or_default(attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, attrs)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be visited. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT, TagT >::type Chris@16: extract_or_default(attribute_name const& name, record const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be visited. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param name The name of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT, TagT >::type Chris@16: extract_or_default(attribute_name const& name, record_view const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be visited. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param value Attribute value. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename T, typename TagT BOOST_LOG_AUX_VOID_DEFAULT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT, TagT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT, TagT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, TagT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(value)); Chris@16: } Chris@16: Chris@16: #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract< T >::type extract(attribute_name const& name, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< T, fallback_to_none > extractor; Chris@16: return extractor(name, attrs); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract< T >::type extract(attribute_name const& name, record const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_none > extractor; Chris@16: return extractor(name, rec); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract< T >::type extract(attribute_name const& name, record_view const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_none > extractor; Chris@16: return extractor(name, rec); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract< T >::type extract(attribute_value const& value) Chris@16: { Chris@16: value_extractor< T, fallback_to_none > extractor; Chris@16: return extractor(value); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, attrs)); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_name const& name, record_view const& rec) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw > extractor; Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_throw< T >::type extract_or_throw(attribute_value const& value) Chris@16: { Chris@16: value_extractor< T, fallback_to_throw > extractor; Chris@16: return aux::unwrap_value_ref(extractor(value)); Chris@16: } Chris@16: Chris@16: template< typename T, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default( Chris@16: attribute_name const& name, attribute_value_set const& attrs, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, attrs)); Chris@16: } Chris@16: Chris@16: template< typename T, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default( Chris@16: attribute_name const& name, record const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: template< typename T, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default( Chris@16: attribute_name const& name, record_view const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(name, rec)); Chris@16: } Chris@16: Chris@16: template< typename T, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT >::type extract_or_default(attribute_value const& value, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< T, DefaultT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& > > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(value)); Chris@16: } Chris@16: Chris@16: #endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor; Chris@16: return extractor(keyword.get_name(), attrs); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor; Chris@16: return extractor(keyword.get_name(), rec); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \return A \c value_ref that refers to the extracted value, if found. An empty value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_none, DescriptorT > extractor; Chris@16: return extractor(keyword.get_name(), rec); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \return The extracted value or a non-empty \c value_ref that refers to the value. Chris@16: * \throws An exception is thrown if the requested value cannot be extracted. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT > Chris@16: inline typename result_of::extract_or_throw< typename DescriptorT::value_type, DescriptorT >::type Chris@16: extract_or_throw(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec) Chris@16: { Chris@16: value_extractor< typename DescriptorT::value_type, fallback_to_throw, DescriptorT > extractor; Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be extracted. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param attrs A set of attribute values in which to look for the specified attribute value. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type Chris@16: extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, attribute_value_set const& attrs, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), attrs)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be visited. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record. The attribute value will be sought among those associated with the record. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type Chris@16: extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), rec)); Chris@16: } Chris@16: Chris@16: /*! Chris@16: * The function extracts an attribute value from the view. The user has to explicitly specify the Chris@16: * type or set of possible types of the attribute value to be visited. Chris@16: * Chris@16: * \note Caution must be exercised if the default value is a temporary object. Because the function returns Chris@16: * a reference, if the temporary object is destroyed, the reference may become dangling. Chris@16: * Chris@16: * \param keyword The keyword of the attribute value to extract. Chris@16: * \param rec A log record view. The attribute value will be sought among those associated with the record. Chris@16: * \param def_val The default value Chris@16: * \return The extracted value, if found. The default value otherwise. Chris@16: */ Chris@16: template< typename DescriptorT, template< typename > class ActorT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::type Chris@16: extract_or_default(expressions::attribute_keyword< DescriptorT, ActorT > const& keyword, record_view const& rec, DefaultT const& def_val) Chris@16: { Chris@16: typedef typename result_of::extract_or_default< typename DescriptorT::value_type, DefaultT, DescriptorT >::extracted_type extracted_type; Chris@16: value_extractor< extracted_type, fallback_to_default< DefaultT const& >, DescriptorT > extractor(def_val); Chris@16: return aux::unwrap_value_ref(extractor(keyword.get_name(), rec)); Chris@16: } Chris@16: Chris@16: #if !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: Chris@16: template< typename T, typename TagT > Chris@16: inline typename result_of::extract< T, TagT >::type attribute_value::extract() const Chris@16: { Chris@16: return boost::log::extract< T, TagT >(*this); Chris@16: } Chris@16: Chris@16: template< typename T, typename TagT > Chris@16: inline typename result_of::extract_or_throw< T, TagT >::type attribute_value::extract_or_throw() const Chris@16: { Chris@16: return boost::log::extract_or_throw< T, TagT >(*this); Chris@16: } Chris@16: Chris@16: template< typename T, typename TagT > Chris@16: inline typename result_of::extract_or_default< T, T, TagT >::type attribute_value::extract_or_default(T const& def_value) const Chris@16: { Chris@16: return boost::log::extract_or_default< T, TagT >(*this, def_value); Chris@16: } Chris@16: Chris@16: template< typename T, typename TagT, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT, TagT >::type attribute_value::extract_or_default(DefaultT const& def_value) const Chris@16: { Chris@16: return boost::log::extract_or_default< T, TagT >(*this, def_value); Chris@16: } Chris@16: Chris@16: #if defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract< T >::type attribute_value::extract() const Chris@16: { Chris@16: return boost::log::extract< T >(*this); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_throw< T >::type attribute_value::extract_or_throw() const Chris@16: { Chris@16: return boost::log::extract_or_throw< T >(*this); Chris@16: } Chris@16: Chris@16: template< typename T > Chris@16: inline typename result_of::extract_or_default< T, T >::type attribute_value::extract_or_default(T const& def_value) const Chris@16: { Chris@16: return boost::log::extract_or_default< T >(*this, def_value); Chris@16: } Chris@16: Chris@16: template< typename T, typename DefaultT > Chris@16: inline typename result_of::extract_or_default< T, DefaultT >::type attribute_value::extract_or_default(DefaultT const& def_value) const Chris@16: { Chris@16: return boost::log::extract_or_default< T >(*this, def_value); Chris@16: } Chris@16: Chris@16: #endif // defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) Chris@16: Chris@16: #endif // !defined(BOOST_LOG_DOXYGEN_PASS) Chris@16: Chris@16: #undef BOOST_LOG_AUX_VOID_DEFAULT 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_ATTRIBUTES_VALUE_EXTRACTION_HPP_INCLUDED_