]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*============================================================================= |
2 | Copyright (c) 2002-2003 Joel de Guzman | |
3 | Copyright (c) 2002-2003 Hartmut Kaiser | |
4 | http://spirit.sourceforge.net/ | |
5 | ||
6 | Distributed under the Boost Software License, Version 1.0. (See accompanying | |
7 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
8 | =============================================================================*/ | |
9 | #if !defined(BOOST_SPIRIT_AS_PARSER_HPP) | |
10 | #define BOOST_SPIRIT_AS_PARSER_HPP | |
11 | ||
12 | #include <boost/spirit/home/classic/namespace.hpp> | |
13 | #include <boost/spirit/home/classic/core/primitives/primitives.hpp> | |
14 | ||
15 | namespace boost { namespace spirit { | |
16 | ||
17 | BOOST_SPIRIT_CLASSIC_NAMESPACE_BEGIN | |
18 | ||
19 | /////////////////////////////////////////////////////////////////////////// | |
20 | // | |
21 | // Helper templates to derive the parser type from an auxilliary type | |
22 | // and to generate an object of the required parser type given an | |
23 | // auxilliary object. Supported types to convert are parsers, | |
24 | // single characters and character strings. | |
25 | // | |
26 | /////////////////////////////////////////////////////////////////////////// | |
27 | namespace impl | |
28 | { | |
29 | template<typename T> | |
30 | struct default_as_parser | |
31 | { | |
32 | typedef T type; | |
33 | static type const& convert(type const& p) | |
34 | { | |
35 | return p; | |
36 | } | |
37 | }; | |
38 | ||
39 | struct char_as_parser | |
40 | { | |
41 | typedef chlit<char> type; | |
42 | static type convert(char ch) | |
43 | { | |
44 | return type(ch); | |
45 | } | |
46 | }; | |
47 | ||
48 | struct wchar_as_parser | |
49 | { | |
50 | typedef chlit<wchar_t> type; | |
51 | static type convert(wchar_t ch) | |
52 | { | |
53 | return type(ch); | |
54 | } | |
55 | }; | |
56 | ||
57 | struct string_as_parser | |
58 | { | |
59 | typedef strlit<char const*> type; | |
60 | static type convert(char const* str) | |
61 | { | |
62 | return type(str); | |
63 | } | |
64 | }; | |
65 | ||
66 | struct wstring_as_parser | |
67 | { | |
68 | typedef strlit<wchar_t const*> type; | |
69 | static type convert(wchar_t const* str) | |
70 | { | |
71 | return type(str); | |
72 | } | |
73 | }; | |
74 | } | |
75 | ||
76 | template<typename T> | |
77 | struct as_parser : impl::default_as_parser<T> {}; | |
78 | ||
79 | template<> | |
80 | struct as_parser<char> : impl::char_as_parser {}; | |
81 | ||
82 | template<> | |
83 | struct as_parser<wchar_t> : impl::wchar_as_parser {}; | |
84 | ||
85 | template<> | |
86 | struct as_parser<char*> : impl::string_as_parser {}; | |
87 | ||
88 | template<> | |
89 | struct as_parser<char const*> : impl::string_as_parser {}; | |
90 | ||
91 | template<> | |
92 | struct as_parser<wchar_t*> : impl::wstring_as_parser {}; | |
93 | ||
94 | template<> | |
95 | struct as_parser<wchar_t const*> : impl::wstring_as_parser {}; | |
96 | ||
97 | template<int N> | |
98 | struct as_parser<char[N]> : impl::string_as_parser {}; | |
99 | ||
100 | template<int N> | |
101 | struct as_parser<wchar_t[N]> : impl::wstring_as_parser {}; | |
102 | ||
103 | template<int N> | |
104 | struct as_parser<char const[N]> : impl::string_as_parser {}; | |
105 | ||
106 | template<int N> | |
107 | struct as_parser<wchar_t const[N]> : impl::wstring_as_parser {}; | |
108 | ||
109 | BOOST_SPIRIT_CLASSIC_NAMESPACE_END | |
110 | ||
111 | }} // namespace BOOST_SPIRIT_CLASSIC_NS | |
112 | ||
113 | #endif |