Back to home page

EIC code displayed by LXR

 
 

    


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

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   keyword.hpp
0009  * \author Andrey Semashev
0010  * \date   29.01.2012
0011  *
0012  * The header contains attribute keyword declaration.
0013  */
0014 
0015 #ifndef BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_
0016 #define BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_
0017 
0018 #include <boost/ref.hpp>
0019 #include <boost/proto/extends.hpp>
0020 #include <boost/proto/make_expr.hpp>
0021 #include <boost/phoenix/core/actor.hpp>
0022 #include <boost/phoenix/core/domain.hpp>
0023 #include <boost/phoenix/core/environment.hpp>
0024 #include <boost/fusion/sequence/intrinsic/at.hpp>
0025 #include <boost/preprocessor/cat.hpp>
0026 #include <boost/log/detail/config.hpp>
0027 #include <boost/log/detail/custom_terminal_spec.hpp>
0028 #include <boost/log/expressions/keyword_fwd.hpp>
0029 #include <boost/log/expressions/is_keyword_descriptor.hpp>
0030 #include <boost/log/expressions/attr.hpp>
0031 #include <boost/log/attributes/attribute_name.hpp>
0032 #include <boost/log/attributes/value_extraction.hpp>
0033 #include <boost/log/attributes/fallback_policy.hpp>
0034 #include <boost/log/detail/header.hpp>
0035 
0036 #ifdef BOOST_HAS_PRAGMA_ONCE
0037 #pragma once
0038 #endif
0039 
0040 namespace boost {
0041 
0042 BOOST_LOG_OPEN_NAMESPACE
0043 
0044 namespace expressions {
0045 
0046 /*!
0047  * This class implements an expression template keyword. It is used to start template expressions involving attribute values.
0048  */
0049 template< typename DescriptorT, template< typename > class ActorT >
0050 struct attribute_keyword
0051 {
0052     //! Self type
0053     typedef attribute_keyword this_type;
0054     //! Attribute descriptor type
0055     typedef DescriptorT descriptor_type;
0056 
0057     BOOST_PROTO_BASIC_EXTENDS(typename proto::terminal< descriptor_type >::type, this_type, phoenix::phoenix_domain)
0058 
0059     //! Attribute value type
0060     typedef typename descriptor_type::value_type value_type;
0061 
0062     //! Returns attribute name
0063     static attribute_name get_name() { return descriptor_type::get_name(); }
0064 
0065     //! Expression with cached attribute name
0066     typedef attribute_actor<
0067         value_type,
0068         fallback_to_none,
0069         descriptor_type,
0070         ActorT
0071     > or_none_result_type;
0072 
0073     //! Generates an expression that extracts the attribute value or a default value
0074     static or_none_result_type or_none()
0075     {
0076         typedef typename or_none_result_type::terminal_type result_terminal;
0077         typename or_none_result_type::base_type act = {{ result_terminal(get_name()) }};
0078         return or_none_result_type(act);
0079     }
0080 
0081     //! Expression with cached attribute name
0082     typedef attribute_actor<
0083         value_type,
0084         fallback_to_throw,
0085         descriptor_type,
0086         ActorT
0087     > or_throw_result_type;
0088 
0089     //! Generates an expression that extracts the attribute value or throws an exception
0090     static or_throw_result_type or_throw()
0091     {
0092         typedef typename or_throw_result_type::terminal_type result_terminal;
0093         typename or_throw_result_type::base_type act = {{ result_terminal(get_name()) }};
0094         return or_throw_result_type(act);
0095     }
0096 
0097     //! Generates an expression that extracts the attribute value or a default value
0098     template< typename DefaultT >
0099     static attribute_actor<
0100         value_type,
0101         fallback_to_default< DefaultT >,
0102         descriptor_type,
0103         ActorT
0104     > or_default(DefaultT const& def_val)
0105     {
0106         typedef attribute_actor<
0107             value_type,
0108             fallback_to_default< DefaultT >,
0109             descriptor_type,
0110             ActorT
0111         > or_default_result_type;
0112         typedef typename or_default_result_type::terminal_type result_terminal;
0113         typename or_default_result_type::base_type act = {{ result_terminal(get_name(), def_val) }};
0114         return or_default_result_type(act);
0115     }
0116 };
0117 
0118 } // namespace expressions
0119 
0120 BOOST_LOG_CLOSE_NAMESPACE // namespace log
0121 
0122 #ifndef BOOST_LOG_DOXYGEN_PASS
0123 
0124 namespace proto {
0125 
0126 namespace detail {
0127 
0128 // This hack is needed in order to cache attribute name into the expression terminal when the template
0129 // expression is constructed. The standard way through a custom domain doesn't work because phoenix::actor
0130 // is bound to phoenix_domain.
0131 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0132 struct protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0133 {
0134     typedef boost::log::expressions::attribute_keyword< DescriptorT, ActorT > keyword_type;
0135     typedef typename keyword_type::or_none_result_type result_type;
0136 
0137     result_type operator() (keyword_type const& keyword) const
0138     {
0139         return keyword.or_none();
0140     }
0141 };
0142 
0143 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0144 struct protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >&, DomainT > :
0145     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0146 {
0147 };
0148 
0149 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0150 struct protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT > const&, DomainT > :
0151     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0152 {
0153 };
0154 
0155 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0156 struct protoify< boost::reference_wrapper< boost::log::expressions::attribute_keyword< DescriptorT, ActorT > >, DomainT > :
0157     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0158 {
0159 };
0160 
0161 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0162 struct protoify< boost::reference_wrapper< boost::log::expressions::attribute_keyword< DescriptorT, ActorT > > const, DomainT > :
0163     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0164 {
0165 };
0166 
0167 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0168 struct protoify< boost::reference_wrapper< const boost::log::expressions::attribute_keyword< DescriptorT, ActorT > >, DomainT > :
0169     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0170 {
0171 };
0172 
0173 template< typename DescriptorT, template< typename > class ActorT, typename DomainT >
0174 struct protoify< boost::reference_wrapper< const boost::log::expressions::attribute_keyword< DescriptorT, ActorT > > const, DomainT > :
0175     public protoify< boost::log::expressions::attribute_keyword< DescriptorT, ActorT >, DomainT >
0176 {
0177 };
0178 
0179 } // namespace detail
0180 
0181 } // namespace proto
0182 
0183 #endif // !defined(BOOST_LOG_DOXYGEN_PASS)
0184 
0185 } // namespace boost
0186 
0187 #ifndef BOOST_LOG_DOXYGEN_PASS
0188 
0189 #define BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE_IMPL(keyword_, name_, value_type_, tag_ns_)\
0190     namespace tag_ns_\
0191     {\
0192         struct keyword_ :\
0193             public ::boost::log::expressions::keyword_descriptor\
0194         {\
0195             typedef value_type_ value_type;\
0196             static ::boost::log::attribute_name get_name() { return ::boost::log::attribute_name(name_); }\
0197         };\
0198     }\
0199     typedef ::boost::log::expressions::attribute_keyword< tag_ns_::keyword_ > BOOST_PP_CAT(keyword_, _type);
0200 
0201 #define BOOST_LOG_ATTRIBUTE_KEYWORD_IMPL(keyword_, name_, value_type_, tag_ns_)\
0202     BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE_IMPL(keyword_, name_, value_type_, tag_ns_)\
0203     BOOST_INLINE_VARIABLE const BOOST_PP_CAT(keyword_, _type) keyword_ = {};
0204 
0205 #endif // BOOST_LOG_DOXYGEN_PASS
0206 
0207 /*!
0208  * \brief The macro declares an attribute keyword type
0209  *
0210  * The macro should be used at a namespace scope. It expands into an attribute keyword type definition, including the
0211  * \c tag namespace and the keyword tag type within which has the following layout:
0212  *
0213  * \code
0214  * namespace tag
0215  * {
0216  *   struct keyword_ :
0217  *     public boost::log::expressions::keyword_descriptor
0218  *   {
0219  *     typedef value_type_ value_type;
0220  *     static boost::log::attribute_name get_name();
0221  *   };
0222  * }
0223  *
0224  * typedef boost::log::expressions::attribute_keyword< tag::keyword_ > keyword_type;
0225  * \endcode
0226  *
0227  * The \c get_name method returns the attribute name.
0228  *
0229  * \note This macro only defines the type of the keyword. To also define the keyword object, use
0230  *       the \c BOOST_LOG_ATTRIBUTE_KEYWORD macro instead.
0231  *
0232  * \param keyword_ Keyword name
0233  * \param name_ Attribute name string
0234  * \param value_type_ Attribute value type
0235  */
0236 #define BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE(keyword_, name_, value_type_)\
0237     BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE_IMPL(keyword_, name_, value_type_, tag)
0238 
0239 /*!
0240  * \brief The macro declares an attribute keyword
0241  *
0242  * The macro provides definitions similar to \c BOOST_LOG_ATTRIBUTE_KEYWORD_TYPE and additionally
0243  * defines the keyword object.
0244  *
0245  * \param keyword_ Keyword name
0246  * \param name_ Attribute name string
0247  * \param value_type_ Attribute value type
0248  */
0249 #define BOOST_LOG_ATTRIBUTE_KEYWORD(keyword_, name_, value_type_)\
0250     BOOST_LOG_ATTRIBUTE_KEYWORD_IMPL(keyword_, name_, value_type_, tag)
0251 
0252 #include <boost/log/detail/footer.hpp>
0253 
0254 #if defined(BOOST_LOG_TRIVIAL_HPP_INCLUDED_)
0255 #include <boost/log/detail/trivial_keyword.hpp>
0256 #endif
0257 
0258 #endif // BOOST_LOG_EXPRESSIONS_KEYWORD_HPP_INCLUDED_