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