Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:15

0001 // Copyright Vladimir Prus 2004.
0002 // Distributed under the Boost Software License, Version 1.0.
0003 // (See accompanying file LICENSE_1_0.txt
0004 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_PARSERS_HPP_VP_2004_05_06
0007 #define BOOST_PARSERS_HPP_VP_2004_05_06
0008 
0009 #include <boost/program_options/detail/convert.hpp>
0010 
0011 #include <iterator>
0012 
0013 namespace boost { namespace program_options {
0014 
0015     template<class charT>
0016     basic_command_line_parser<charT>::
0017     basic_command_line_parser(const std::vector<
0018                               std::basic_string<charT> >& xargs)
0019        : detail::cmdline(to_internal(xargs))
0020     {}
0021 
0022 
0023     template<class charT>
0024     basic_command_line_parser<charT>::
0025     basic_command_line_parser(int argc, const charT* const argv[])
0026     : detail::cmdline(
0027         to_internal(std::vector<std::basic_string<charT> >(argv+1, argv+argc))),
0028         m_desc()
0029     {}
0030 
0031     
0032     template<class charT>
0033     basic_command_line_parser<charT>& 
0034     basic_command_line_parser<charT>::options(const options_description& desc)
0035     {
0036         detail::cmdline::set_options_description(desc);
0037         m_desc = &desc;
0038         return *this;
0039     }
0040 
0041     template<class charT>
0042     basic_command_line_parser<charT>& 
0043     basic_command_line_parser<charT>::positional(
0044         const positional_options_description& desc)
0045     {
0046         detail::cmdline::set_positional_options(desc);
0047         return *this;
0048     }
0049 
0050     template<class charT>
0051     basic_command_line_parser<charT>& 
0052     basic_command_line_parser<charT>::style(int xstyle)
0053     {
0054         detail::cmdline::style(xstyle);
0055         return *this;
0056     }
0057 
0058     template<class charT>
0059     basic_command_line_parser<charT>& 
0060     basic_command_line_parser<charT>::extra_parser(ext_parser ext)
0061     {
0062         detail::cmdline::set_additional_parser(ext);
0063         return *this;
0064     }
0065 
0066     template<class charT>
0067     basic_command_line_parser<charT>& 
0068     basic_command_line_parser<charT>::allow_unregistered()
0069     {
0070         detail::cmdline::allow_unregistered();
0071         return *this;
0072     }
0073 
0074     template<class charT>
0075     basic_command_line_parser<charT>& 
0076     basic_command_line_parser<charT>::extra_style_parser(style_parser s)
0077     {
0078         detail::cmdline::extra_style_parser(s);
0079         return *this;
0080     }
0081 
0082 
0083 
0084     template<class charT>    
0085     basic_parsed_options<charT>
0086     basic_command_line_parser<charT>::run()
0087     {
0088         // save the canonical prefixes which were used by this cmdline parser
0089         //    eventually inside the parsed results
0090         //    This will be handy to format recognisable options
0091         //    for diagnostic messages if everything blows up much later on
0092         parsed_options result(m_desc, detail::cmdline::get_canonical_option_prefix());
0093         result.options = detail::cmdline::run();
0094 
0095         // Presense of parsed_options -> wparsed_options conversion
0096         // does the trick.
0097         return basic_parsed_options<charT>(result);
0098     }
0099 
0100 
0101     template<class charT>
0102     basic_parsed_options<charT>
0103     parse_command_line(int argc, const charT* const argv[],
0104                        const options_description& desc,
0105                        int style,
0106                        function1<std::pair<std::string, std::string>, 
0107                                  const std::string&> ext)
0108     {
0109         return basic_command_line_parser<charT>(argc, argv).options(desc).
0110             style(style).extra_parser(ext).run();
0111     }
0112 
0113     template<class charT>
0114     std::vector< std::basic_string<charT> > 
0115     collect_unrecognized(const std::vector< basic_option<charT> >& options,
0116                          enum collect_unrecognized_mode mode)
0117     {
0118         std::vector< std::basic_string<charT> >  result;
0119         for(unsigned i = 0; i < options.size(); ++i)
0120         {
0121             if (options[i].unregistered ||
0122                 (mode == include_positional && options[i].position_key != -1))
0123             {
0124                 copy(options[i].original_tokens.begin(),
0125                      options[i].original_tokens.end(),
0126                      back_inserter(result));
0127             }
0128         }
0129         return result;
0130     }
0131 
0132 
0133 }}
0134 
0135 #endif