Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class error_with_option_name

boost::program_options::error_with_option_name

Synopsis

// In header: <boost/program_options/errors.hpp>


class error_with_option_name : public boost::program_options::error {
public:
  // construct/copy/destruct
  error_with_option_name(const std::string &, const std::string & = "", 
                         const std::string & = "", int = 0);
  ~error_with_option_name();

  // public member functions
  void set_substitute(const std::string &, const std::string &);
  void set_substitute_default(const std::string &, const std::string &, 
                              const std::string &);
  void add_context(const std::string &, const std::string &, int);
  void set_prefix(int);
  virtual void set_option_name(const std::string &);
  std::string get_option_name() const;
  void set_original_token(const std::string &);
  virtual const char * what() const;

  // protected member functions
  virtual void substitute_placeholders(const std::string &) const;
  void replace_token(const std::string &, const std::string &) const;
  std::string get_canonical_option_name() const;
  std::string get_canonical_option_prefix() const;

  // public data members
  std::string m_error_template;
};

Description

Base class for most exceptions in the library.

Substitutes the values for the parameter name placeholders in the template to create the human readable error message

Placeholders are surrounded by % signs: example% Poor man's version of boost::format

If a parameter name is absent, perform default substitutions instead so ugly placeholders are never left in-place.

Options are displayed in "canonical" form This is the most unambiguous form of the parsed option name and would correspond to option_description::format_name() i.e. what is shown by print_usage()

The "canonical" form depends on whether the option is specified in short or long form, using dashes or slashes or without a prefix (from a configuration file)

error_with_option_name public construct/copy/destruct

  1. error_with_option_name(const std::string & template_, 
                           const std::string & option_name = "", 
                           const std::string & original_token = "", 
                           int option_style = 0);
  2. ~error_with_option_name();

    gcc says that throw specification on dtor is loosened without this line

error_with_option_name public member functions

  1. void set_substitute(const std::string & parameter_name, 
                        const std::string & value);

    Substitute parameter_name->value to create the error message from the error template

  2. void set_substitute_default(const std::string & parameter_name, 
                                const std::string & from, const std::string & to);

    If the parameter is missing, then make the from->to substitution instead

  3. void add_context(const std::string & option_name, 
                     const std::string & original_token, int option_style);

    Add context to an exception

  4. void set_prefix(int option_style);
  5. virtual void set_option_name(const std::string & option_name);

    Overridden in error_with_no_option_name

  6. std::string get_option_name() const;
  7. void set_original_token(const std::string & original_token);
  8. virtual const char * what() const;

    Creates the error_message on the fly Currently a thin wrapper for substitute_placeholders()

error_with_option_name protected member functions

  1. virtual void substitute_placeholders(const std::string & error_template) const;

    Makes all substitutions using the template

  2. void replace_token(const std::string & from, const std::string & to) const;
  3. std::string get_canonical_option_name() const;

    Construct option name in accordance with the appropriate prefix style: i.e. long dash or short slash etc

  4. std::string get_canonical_option_prefix() const;

error_with_option_name public public data members

  1. std::string m_error_template;

    template with placeholders


PrevUpHomeNext