Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/spirit/home/x3/auxiliary/any_parser.hpp @ 102:f46d142149f5
Whoops, finish that update
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:13:41 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
101:c530137014c0 | 102:f46d142149f5 |
---|---|
1 /*============================================================================= | |
2 Copyright (c) 2001-2014 Joel de Guzman | |
3 Copyright (c) 2013-2014 Agustin Berge | |
4 | |
5 Distributed under the Boost Software License, Version 1.0. (See accompanying | |
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 ==============================================================================*/ | |
8 #if !defined(BOOST_SPIRIT_X3_AUXILIARY_ANY_PARSER_APR_09_2014_1145PM) | |
9 #define BOOST_SPIRIT_X3_AUXILIARY_ANY_PARSER_APR_09_2014_1145PM | |
10 | |
11 #if defined(_MSC_VER) | |
12 #pragma once | |
13 #endif | |
14 | |
15 #include <boost/spirit/home/x3/core/parser.hpp> | |
16 #include <boost/spirit/home/x3/support/context.hpp> | |
17 #include <boost/spirit/home/x3/support/subcontext.hpp> | |
18 #include <boost/spirit/home/x3/support/unused.hpp> | |
19 #include <boost/spirit/home/x3/support/traits/container_traits.hpp> | |
20 #include <boost/spirit/home/x3/support/traits/has_attribute.hpp> | |
21 #include <boost/spirit/home/x3/support/traits/move_to.hpp> | |
22 #include <boost/spirit/home/x3/support/traits/is_parser.hpp> | |
23 #include <memory> | |
24 #include <string> | |
25 | |
26 namespace boost { namespace spirit { namespace x3 | |
27 { | |
28 template < | |
29 typename Iterator | |
30 , typename Attribute = unused_type | |
31 , typename Context = subcontext<>> | |
32 struct any_parser : parser<any_parser<Iterator, Attribute, Context>> | |
33 { | |
34 typedef Attribute attribute_type; | |
35 | |
36 static bool const has_attribute = | |
37 !is_same<unused_type, attribute_type>::value; | |
38 static bool const handles_container = | |
39 traits::is_container<Attribute>::value; | |
40 | |
41 public: | |
42 any_parser() | |
43 : _content(nullptr) {} | |
44 | |
45 template <typename Expr, | |
46 typename Enable = typename enable_if<traits::is_parser<Expr>>::type> | |
47 any_parser(Expr const& expr) | |
48 : _content(new holder<Expr>(expr)) {} | |
49 | |
50 any_parser(any_parser const& other) | |
51 : _content(other._content ? other._content->clone() : nullptr) {} | |
52 | |
53 any_parser(any_parser&& other) = default; | |
54 | |
55 any_parser& operator=(any_parser const& other) | |
56 { | |
57 _content.reset(other._content ? other._content->clone() : nullptr); | |
58 return *this; | |
59 } | |
60 | |
61 any_parser& operator=(any_parser&& other) = default; | |
62 | |
63 template <typename Iterator_, typename Context_> | |
64 bool parse(Iterator_& first, Iterator_ const& last | |
65 , Context_ const& context, unused_type, Attribute& attr) const | |
66 { | |
67 BOOST_STATIC_ASSERT_MSG( | |
68 (is_same<Iterator, Iterator_>::value) | |
69 , "Incompatible iterator used" | |
70 ); | |
71 | |
72 BOOST_ASSERT_MSG( | |
73 (_content != nullptr) | |
74 , "Invalid use of uninitialized any_parser" | |
75 ); | |
76 | |
77 return _content->parse(first, last, context, attr); | |
78 } | |
79 | |
80 template <typename Iterator_, typename Context_, typename Attribute_> | |
81 bool parse(Iterator_& first, Iterator_ const& last | |
82 , Context_ const& context, unused_type, Attribute_& attr_) const | |
83 { | |
84 Attribute attr; | |
85 if (parse(first, last, context, unused, attr)) | |
86 { | |
87 traits::move_to(attr, attr_); | |
88 return true; | |
89 } | |
90 return false; | |
91 } | |
92 | |
93 std::string get_info() const | |
94 { | |
95 return _content ? _content->get_info() : ""; | |
96 } | |
97 | |
98 private: | |
99 | |
100 struct placeholder | |
101 { | |
102 virtual placeholder* clone() const = 0; | |
103 | |
104 virtual bool parse(Iterator& first, Iterator const& last | |
105 , Context const& context, Attribute& attr) const = 0; | |
106 | |
107 virtual std::string get_info() const = 0; | |
108 | |
109 virtual ~placeholder() {} | |
110 }; | |
111 | |
112 template <typename Expr> | |
113 struct holder : placeholder | |
114 { | |
115 typedef typename extension::as_parser<Expr>::value_type parser_type; | |
116 | |
117 explicit holder(Expr const& p) | |
118 : _parser(as_parser(p)) {} | |
119 | |
120 holder* clone() const override | |
121 { | |
122 return new holder(*this); | |
123 } | |
124 | |
125 bool parse(Iterator& first, Iterator const& last | |
126 , Context const& context, Attribute& attr) const override | |
127 { | |
128 return _parser.parse(first, last, context, unused, attr); | |
129 } | |
130 | |
131 std::string get_info() const override | |
132 { | |
133 return x3::what(_parser); | |
134 } | |
135 | |
136 parser_type _parser; | |
137 }; | |
138 | |
139 private: | |
140 std::unique_ptr<placeholder> _content; | |
141 }; | |
142 | |
143 template <typename Iterator, typename Attribute, typename Context> | |
144 struct get_info<any_parser<Iterator, Attribute, Context>> | |
145 { | |
146 typedef std::string result_type; | |
147 std::string operator()( | |
148 any_parser<Iterator, Attribute, Context> const& p) const | |
149 { | |
150 return p.get_info(); | |
151 } | |
152 }; | |
153 }}} | |
154 | |
155 #endif |