Class options_description

| Home | Libraries | People | FAQ | More

## Class options_description

boost::program_options::options_description —

## Synopsis

    class options_description {
    public:
      // construct/copy/destruct
      options_description();
      options_description(const std::string &);

      // public member functions
      void add(shared_ptr< option_description >) ;
      options_description & add(const options_description &) ;
      options_description_easy_init add_options() ;
      unsigned count(const std::string &) const;
      unsigned count_approx(const std::string &) const;
      const option_description & find(const std::string &) const;
      const option_description & find_approx(const std::string &) const;
      std::set< std::string > keys() const;
      std::set< std::string > primary_keys() const;
      std::set< std::string > approximations(const std::string &) const;
      void print(std::ostream &) const;

      // private member functions
      approximation_range find_approximation(const std::string &) const;
    };

## Description

A set of option descriptions. This provides convenient interface for adding new option (the add_options) method, and facilities to search for options by name.

See here for option adding interface discussion.

option_description

### `options_description` construct/copy/destruct

1.     options_description();

   Creates the instance.

2.     options_description(const std::string & caption);

   Creates the instance. The 'caption' parameter gives the name of this 'options_description' instance. Primarily useful for output.

### `options_description` public member functions

1.     void add(shared_ptr< option_description > desc) ;

   Adds new variable description. Throws duplicate_variable_error if either short or long name matches that of already present one.

2.     options_description & add(const options_description & desc) ;

   Adds a group of option description. This has the same effect as adding all option_descriptions in 'desc' individually, except that output operator will show a separate group. Returns *this.

3.     options_description_easy_init add_options() ;

   Returns an object of implementation-defined type suitable for adding options to options_description. The returned object will have overloaded operator() with parameter type matching 'option_description' constructors. Calling the operator will create new option_description instance and add it.

4.     unsigned count(const std::string & name) const;

   Count the number of option descriptions with given name. Returns 0 or 1. The 'name' parameter can be either name of long option, and short option prefixed by '-'.

5.     unsigned count_approx(const std::string & prefix) const;

   Count the number of descriptions having the given string as prefix. This makes sense only for long options.

6.     const option_description & find(const std::string & name) const;

   Returns description given a name.

   Requires: count(name) == 1

7.     const option_description & find_approx(const std::string & prefix) const;

   Returns description given a prefix. Throws

   Requires: count_approx(name) == 1

8.     std::set< std::string > keys() const;

9.     std::set< std::string > primary_keys() const;

   For each option description stored, contains long name if not empty, if it is empty, short name is returned.

10.     std::set< std::string > approximations(const std::string & prefix) const;

11.     void print(std::ostream & os) const;

    Output 'desc' to the specified stream, calling 'f' to output each option_description element.

### `options_description` private member functions

1.     approximation_range find_approximation(const std::string & prefix) const;

| Copyright © 2002-2004 Vladimir Prus