comparison DEPENDENCIES/generic/include/boost/spirit/home/classic/dynamic/impl/conditions.ipp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 /*=============================================================================
2 Copyright (c) 2002-2003 Martin Wille
3 http://spirit.sourceforge.net/
4
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
9 #ifndef BOOST_SPIRIT_CONDITIONS_IPP
10 #define BOOST_SPIRIT_CONDITIONS_IPP
11
12 ///////////////////////////////////////////////////////////////////////////////
13 #include <boost/spirit/home/classic/meta/parser_traits.hpp>
14 #include <boost/spirit/home/classic/core/composite/epsilon.hpp>
15
16 ///////////////////////////////////////////////////////////////////////////////
17 namespace boost { namespace spirit {
18
19 BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN
20
21 namespace impl {
22
23 ///////////////////////////////////////////////////////////////////////////////
24 //
25 // condition evaluation
26 //
27 ///////////////////////////////////////////////////////////////////////////////
28 //////////////////////////////////
29 // condition_parser_selector, decides which parser to use for a condition
30 // If the template argument is a parser then that parser is used.
31 // If the template argument is a functor then a condition parser using
32 // the functor is chosen
33
34 template <typename T> struct embed_t_accessor
35 {
36 typedef typename T::embed_t type;
37 };
38
39 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
40 template <> struct embed_t_accessor<int>
41 {
42 typedef int type;
43 };
44 #endif
45
46 template <typename ConditionT>
47 struct condition_parser_selector
48 {
49 typedef
50 typename mpl::if_<
51 is_parser<ConditionT>,
52 ConditionT,
53 condition_parser<ConditionT>
54 >::type
55 type;
56
57 typedef typename embed_t_accessor<type>::type embed_t;
58 };
59
60 //////////////////////////////////
61 // condition_evaluator, uses a parser to check wether a condition is met
62 // takes a parser or a functor that can be evaluated in boolean context
63 // as template parameter.
64
65 // JDG 4-15-03 refactored
66 template <typename ConditionT>
67 struct condition_evaluator
68 {
69 typedef condition_parser_selector<ConditionT> selector_t;
70 typedef typename selector_t::type selected_t;
71 typedef typename selector_t::embed_t cond_embed_t;
72
73 typedef typename boost::call_traits<cond_embed_t>::param_type
74 param_t;
75
76 condition_evaluator(param_t s) : cond(s) {}
77
78 /////////////////////////////
79 // evaluate, checks wether condition is met
80 // returns length of a match or a negative number for no-match
81 template <typename ScannerT>
82 std::ptrdiff_t
83 evaluate(ScannerT const &scan) const
84 {
85 typedef typename ScannerT::iterator_t iterator_t;
86 typedef typename parser_result<selected_t, ScannerT>::type cres_t;
87 iterator_t save(scan.first);
88 cres_t result = cond.parse(scan);
89 if (!result) // reset the position if evaluation
90 scan.first = save; // fails.
91 return result.length();
92 }
93
94 cond_embed_t cond;
95 };
96
97 ///////////////////////////////////////////////////////////////////////////////
98 } // namespace impl
99
100 BOOST_SPIRIT_CLASSIC_NAMESPACE_END
101
102 }} // namespace boost::spirit
103
104 #endif