Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/program_options/detail/parsers.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 // Copyright Vladimir Prus 2004. | |
2 // Distributed under the Boost Software License, Version 1.0. | |
3 // (See accompanying file LICENSE_1_0.txt | |
4 // or copy at http://www.boost.org/LICENSE_1_0.txt) | |
5 | |
6 #ifndef BOOST_PARSERS_HPP_VP_2004_05_06 | |
7 #define BOOST_PARSERS_HPP_VP_2004_05_06 | |
8 | |
9 #include <boost/program_options/detail/convert.hpp> | |
10 | |
11 #include <iterator> | |
12 | |
13 namespace boost { namespace program_options { | |
14 | |
15 namespace detail { | |
16 template<class charT, class Iterator> | |
17 std::vector<std::basic_string<charT> > | |
18 make_vector(Iterator i, Iterator e) | |
19 { | |
20 std::vector<std::basic_string<charT> > result; | |
21 // Some compilers don't have templated constructor for | |
22 // vector, so we can't create vector from (argv+1, argv+argc) range | |
23 for(; i != e; ++i) | |
24 result.push_back(*i); | |
25 return result; | |
26 } | |
27 } | |
28 | |
29 template<class charT> | |
30 basic_command_line_parser<charT>:: | |
31 basic_command_line_parser(const std::vector< | |
32 std::basic_string<charT> >& xargs) | |
33 : detail::cmdline(to_internal(xargs)) | |
34 {} | |
35 | |
36 | |
37 template<class charT> | |
38 basic_command_line_parser<charT>:: | |
39 basic_command_line_parser(int argc, const charT* const argv[]) | |
40 : detail::cmdline( | |
41 // Explicit template arguments are required by gcc 3.3.1 | |
42 // (at least mingw version), and do no harm on other compilers. | |
43 to_internal(detail::make_vector<charT, const charT* const*>(argv+1, argv+argc+!argc))) | |
44 {} | |
45 | |
46 | |
47 template<class charT> | |
48 basic_command_line_parser<charT>& | |
49 basic_command_line_parser<charT>::options(const options_description& desc) | |
50 { | |
51 detail::cmdline::set_options_description(desc); | |
52 m_desc = &desc; | |
53 return *this; | |
54 } | |
55 | |
56 template<class charT> | |
57 basic_command_line_parser<charT>& | |
58 basic_command_line_parser<charT>::positional( | |
59 const positional_options_description& desc) | |
60 { | |
61 detail::cmdline::set_positional_options(desc); | |
62 return *this; | |
63 } | |
64 | |
65 template<class charT> | |
66 basic_command_line_parser<charT>& | |
67 basic_command_line_parser<charT>::style(int xstyle) | |
68 { | |
69 detail::cmdline::style(xstyle); | |
70 return *this; | |
71 } | |
72 | |
73 template<class charT> | |
74 basic_command_line_parser<charT>& | |
75 basic_command_line_parser<charT>::extra_parser(ext_parser ext) | |
76 { | |
77 detail::cmdline::set_additional_parser(ext); | |
78 return *this; | |
79 } | |
80 | |
81 template<class charT> | |
82 basic_command_line_parser<charT>& | |
83 basic_command_line_parser<charT>::allow_unregistered() | |
84 { | |
85 detail::cmdline::allow_unregistered(); | |
86 return *this; | |
87 } | |
88 | |
89 template<class charT> | |
90 basic_command_line_parser<charT>& | |
91 basic_command_line_parser<charT>::extra_style_parser(style_parser s) | |
92 { | |
93 detail::cmdline::extra_style_parser(s); | |
94 return *this; | |
95 } | |
96 | |
97 | |
98 | |
99 template<class charT> | |
100 basic_parsed_options<charT> | |
101 basic_command_line_parser<charT>::run() | |
102 { | |
103 // save the canonical prefixes which were used by this cmdline parser | |
104 // eventually inside the parsed results | |
105 // This will be handy to format recognisable options | |
106 // for diagnostic messages if everything blows up much later on | |
107 parsed_options result(m_desc, detail::cmdline::get_canonical_option_prefix()); | |
108 result.options = detail::cmdline::run(); | |
109 | |
110 // Presense of parsed_options -> wparsed_options conversion | |
111 // does the trick. | |
112 return basic_parsed_options<charT>(result); | |
113 } | |
114 | |
115 | |
116 template<class charT> | |
117 basic_parsed_options<charT> | |
118 parse_command_line(int argc, const charT* const argv[], | |
119 const options_description& desc, | |
120 int style, | |
121 function1<std::pair<std::string, std::string>, | |
122 const std::string&> ext) | |
123 { | |
124 return basic_command_line_parser<charT>(argc, argv).options(desc). | |
125 style(style).extra_parser(ext).run(); | |
126 } | |
127 | |
128 template<class charT> | |
129 std::vector< std::basic_string<charT> > | |
130 collect_unrecognized(const std::vector< basic_option<charT> >& options, | |
131 enum collect_unrecognized_mode mode) | |
132 { | |
133 std::vector< std::basic_string<charT> > result; | |
134 for(unsigned i = 0; i < options.size(); ++i) | |
135 { | |
136 if (options[i].unregistered || | |
137 (mode == include_positional && options[i].position_key != -1)) | |
138 { | |
139 copy(options[i].original_tokens.begin(), | |
140 options[i].original_tokens.end(), | |
141 back_inserter(result)); | |
142 } | |
143 } | |
144 return result; | |
145 } | |
146 | |
147 | |
148 }} | |
149 | |
150 #endif |