2 * Copyright Andrey Semashev 2007 - 2015.
3 * Distributed under the Boost Software License, Version 1.0.
4 * (See accompanying file LICENSE_1_0.txt or copy at
5 * http://www.boost.org/LICENSE_1_0.txt)
8 * \file begins_with.hpp
9 * \author Andrey Semashev
12 * The header contains implementation of a \c begins_with predicate in template expressions.
15 #ifndef BOOST_LOG_EXPRESSIONS_PREDICATES_BEGINS_WITH_HPP_INCLUDED_
16 #define BOOST_LOG_EXPRESSIONS_PREDICATES_BEGINS_WITH_HPP_INCLUDED_
18 #include <boost/phoenix/core/actor.hpp>
19 #include <boost/log/detail/config.hpp>
20 #include <boost/log/detail/embedded_string_type.hpp>
21 #include <boost/log/detail/unary_function_terminal.hpp>
22 #include <boost/log/detail/attribute_predicate.hpp>
23 #include <boost/log/attributes/attribute_name.hpp>
24 #include <boost/log/attributes/fallback_policy.hpp>
25 #include <boost/log/expressions/attr_fwd.hpp>
26 #include <boost/log/expressions/keyword_fwd.hpp>
27 #include <boost/log/utility/functional/begins_with.hpp>
28 #include <boost/log/detail/header.hpp>
30 #ifdef BOOST_HAS_PRAGMA_ONCE
36 BOOST_LOG_OPEN_NAMESPACE
38 namespace expressions {
41 * The predicate checks if the attribute value begins with a substring. The attribute value is assumed to be of a string type.
43 #if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
45 template< typename T, typename SubstringT, typename FallbackPolicyT = fallback_to_none >
46 using attribute_begins_with = aux::attribute_predicate< T, SubstringT, begins_with_fun, FallbackPolicyT >;
48 #else // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
50 template< typename T, typename SubstringT, typename FallbackPolicyT = fallback_to_none >
51 class attribute_begins_with :
52 public aux::attribute_predicate< T, SubstringT, begins_with_fun, FallbackPolicyT >
54 typedef aux::attribute_predicate< T, SubstringT, begins_with_fun, FallbackPolicyT > base_type;
58 * Initializing constructor
60 * \param name Attribute name
61 * \param substring The expected attribute value beginning
63 attribute_begins_with(attribute_name const& name, SubstringT const& substring) : base_type(name, substring)
68 * Initializing constructor
70 * \param name Attribute name
71 * \param substring The expected attribute value beginning
72 * \param arg Additional parameter for the fallback policy
74 template< typename U >
75 attribute_begins_with(attribute_name const& name, SubstringT const& substring, U const& arg) : base_type(name, substring, arg)
80 #endif // !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
83 * The function generates a terminal node in a template expression. The node will check if the attribute value,
84 * which is assumed to be a string, begins with the specified substring.
86 template< typename T, typename FallbackPolicyT, typename TagT, template< typename > class ActorT, typename SubstringT >
87 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_begins_with< T, typename boost::log::aux::make_embedded_string_type< SubstringT >::type, FallbackPolicyT > > >
88 begins_with(attribute_actor< T, FallbackPolicyT, TagT, ActorT > const& attr, SubstringT const& substring)
90 typedef aux::unary_function_terminal< attribute_begins_with< T, typename boost::log::aux::make_embedded_string_type< SubstringT >::type, FallbackPolicyT > > terminal_type;
91 ActorT< terminal_type > act = {{ terminal_type(attr.get_name(), substring, attr.get_fallback_policy()) }};
96 * The function generates a terminal node in a template expression. The node will check if the attribute value,
97 * which is assumed to be a string, begins with the specified substring.
99 template< typename DescriptorT, template< typename > class ActorT, typename SubstringT >
100 BOOST_FORCEINLINE ActorT< aux::unary_function_terminal< attribute_begins_with< typename DescriptorT::value_type, typename boost::log::aux::make_embedded_string_type< SubstringT >::type > > >
101 begins_with(attribute_keyword< DescriptorT, ActorT > const&, SubstringT const& substring)
103 typedef aux::unary_function_terminal< attribute_begins_with< typename DescriptorT::value_type, typename boost::log::aux::make_embedded_string_type< SubstringT >::type > > terminal_type;
104 ActorT< terminal_type > act = {{ terminal_type(DescriptorT::get_name(), substring) }};
109 * The function generates a terminal node in a template expression. The node will check if the attribute value,
110 * which is assumed to be a string, begins with the specified substring.
112 template< typename T, typename SubstringT >
113 BOOST_FORCEINLINE phoenix::actor< aux::unary_function_terminal< attribute_begins_with< T, typename boost::log::aux::make_embedded_string_type< SubstringT >::type > > >
114 begins_with(attribute_name const& name, SubstringT const& substring)
116 typedef aux::unary_function_terminal< attribute_begins_with< T, typename boost::log::aux::make_embedded_string_type< SubstringT >::type > > terminal_type;
117 phoenix::actor< terminal_type > act = {{ terminal_type(name, substring) }};
121 } // namespace expressions
123 BOOST_LOG_CLOSE_NAMESPACE // namespace log
127 #include <boost/log/detail/footer.hpp>
129 #endif // BOOST_LOG_EXPRESSIONS_PREDICATES_BEGINS_WITH_HPP_INCLUDED_