Chris@16: // Copyright Vladimir Prus 2002-2004. Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt Chris@16: // or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: Chris@16: #ifndef BOOST_CMDLINE_VP_2003_05_19 Chris@16: #define BOOST_CMDLINE_VP_2003_05_19 Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #if defined(BOOST_MSVC) Chris@16: # pragma warning (push) Chris@16: # pragma warning (disable:4251) // class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'boost::program_options::positional_options_description' Chris@16: #endif Chris@16: Chris@16: namespace boost { namespace program_options { namespace detail { Chris@16: Chris@16: /** Command line parser class. Main requirements were: Chris@16: - Powerful enough to support all common uses. Chris@16: - Simple and easy to learn/use. Chris@16: - Minimal code size and external dependencies. Chris@16: - Extensible for custom syntaxes. Chris@16: Chris@16: First all options are registered. After that, elements of command line Chris@16: are extracted using operator++. Chris@16: Chris@16: For each element, user can find Chris@16: - if it's an option or an argument Chris@16: - name of the option Chris@16: - index of the option Chris@16: - option value(s), if any Chris@16: Chris@16: Sometimes the registered option name is not equal to the encountered Chris@16: one, for example, because name abbreviation is supported. Therefore Chris@16: two option names can be obtained: Chris@16: - the registered one Chris@16: - the one found at the command line Chris@16: Chris@16: There are lot of style options, which can be used to tune the command Chris@16: line parsing. In addition, it's possible to install additional parser Chris@16: which will process custom option styles. Chris@16: Chris@16: @todo mininal match length for guessing? Chris@16: */ Chris@16: class BOOST_PROGRAM_OPTIONS_DECL cmdline { Chris@16: public: Chris@16: Chris@16: typedef ::boost::program_options::command_line_style::style_t style_t; Chris@16: Chris@16: typedef function1, Chris@16: const std::string&> Chris@16: additional_parser; Chris@16: Chris@16: typedef function1, std::vector&> Chris@16: style_parser; Chris@16: Chris@16: /** Constructs a command line parser for (argc, argv) pair. Uses Chris@16: style options passed in 'style', which should be binary or'ed values Chris@16: of style_t enum. It can also be zero, in which case a "default" Chris@16: style will be used. If 'allow_unregistered' is true, then allows Chris@16: unregistered options. They will be assigned index 1 and are Chris@16: assumed to have optional parameter. Chris@16: */ Chris@16: cmdline(const std::vector& args); Chris@16: Chris@16: /** @overload */ Chris@16: cmdline(int argc, const char*const * argv); Chris@16: Chris@16: void style(int style); Chris@16: Chris@16: /** returns the canonical option prefix associated with the command_line_style Chris@16: * In order of precedence: Chris@16: * allow_long : allow_long Chris@16: * allow_long_disguise : allow_long_disguise Chris@16: * allow_dash_for_short : allow_short | allow_dash_for_short Chris@16: * allow_slash_for_short: allow_short | allow_slash_for_short Chris@16: * Chris@16: * This is mainly used for the diagnostic messages in exceptions Chris@16: */ Chris@16: int get_canonical_option_prefix(); Chris@16: Chris@16: void allow_unregistered(); Chris@16: Chris@16: void set_options_description(const options_description& desc); Chris@16: void set_positional_options( Chris@16: const positional_options_description& m_positional); Chris@16: Chris@16: std::vector