glibmm 2.80.0
Public Types | Public Member Functions | List of all members
Glib::OptionGroup Class Reference

An OptionGroup defines the options in a single group. More...

#include <glibmm/optiongroup.h>

Public Types

using SlotTranslate = sigc::slot< Glib::ustring(const Glib::ustring &)>
 For example Glib::ustring on_translate(const Glib::ustring& original);.
 
using SlotOptionArgString = sigc::slot< bool(const Glib::ustring &, const Glib::ustring &, bool)>
 For example bool on_option_arg_string(const Glib::ustring& option_name, const Glib::ustring& value, bool has_value);.
 
using SlotOptionArgFilename = sigc::slot< bool(const Glib::ustring &, const std::string &, bool)>
 For example bool on_option_arg_filename(const Glib::ustring& option_name, const std::string& value, bool has_value);.
 
using vecustrings = std::vector< Glib::ustring >
 
using vecstrings = std::vector< std::string >
 

Public Member Functions

 OptionGroup (const Glib::ustring & name, const Glib::ustring &description, const Glib::ustring &help_description={})
 
 OptionGroup (GOptionGroup *castitem)
 This always takes ownership of the underlying GOptionGroup, so it is only useful with C functions that return newly-allocated GOptionGroups.
 
 OptionGroup (const OptionGroup &other)=delete
 
OptionGroupoperator= (const OptionGroup &other)=delete
 
 OptionGroup (OptionGroup &&other)=delete
 
OptionGroupoperator= (OptionGroup &&other)=delete
 
virtual ~OptionGroup ()
 
virtual bool on_pre_parse (OptionContext &context)
 
virtual bool on_post_parse (OptionContext &context)
 
virtual void on_error (OptionContext &context, const Error &error)
 
void add_entry (const OptionEntry &entry)
 
void add_entry (const OptionEntry &entry, bool &arg)
 Add a boolean option entry.
 
void add_entry (const OptionEntry &entry, int &arg)
 Add an integer option entry.
 
void add_entry (const OptionEntry &entry, double &arg)
 Add a double option entry.
 
void add_entry (const OptionEntry &entry, Glib::ustring &arg)
 Add a UTF-8 string option entry.
 
void add_entry_filename (const OptionEntry &entry, std::string &arg)
 Add a filename string option entry.
 
void add_entry (const OptionEntry &entry, vecustrings &arg)
 Add an option entry that provides a list of UTF-8 strings.
 
void add_entry_filename (const OptionEntry &entry, vecstrings &arg)
 Add an option entry that provides a list of filename strings.
 
void add_entry (const OptionEntry &entry, const SlotOptionArgString &slot)
 Add a string option entry, but let a callback slot parse the extra argument instead of just setting a variable to its value.
 
void add_entry_filename (const OptionEntry &entry, const SlotOptionArgFilename &slot)
 Add a filename option entry, but let a callback slot parse the extra argument instead of just setting a variable to its value.
 
void set_translate_func (const SlotTranslate &slot)
 Sets the function which is used to translate user-visible strings, for –help output.
 
void set_translation_domain (const Glib::ustring & domain)
 A convenience function to use gettext() for translating user-visible strings.
 
GOptionGroupgobj ()
 Provides access to the underlying C instance.
 
const GOptionGroupgobj () const
 Provides access to the underlying C instance.
 
GOptionGroupgobj_copy () const
 Provides access to the underlying C instance. The caller is responsible for unrefing it.
 

Detailed Description

An OptionGroup defines the options in a single group.

Libraries which need to parse commandline options are expected to provide a function that allows their OptionGroups to be added to the application's OptionContext.

Member Typedef Documentation

◆ SlotOptionArgFilename

For example bool on_option_arg_filename(const Glib::ustring& option_name, const std::string& value, bool has_value);.

◆ SlotOptionArgString

For example bool on_option_arg_string(const Glib::ustring& option_name, const Glib::ustring& value, bool has_value);.

◆ SlotTranslate

For example Glib::ustring on_translate(const Glib::ustring& original);.

◆ vecstrings

◆ vecustrings

Constructor & Destructor Documentation

◆ OptionGroup() [1/4]

Glib::OptionGroup::OptionGroup ( const Glib::ustring name,
const Glib::ustring description,
const Glib::ustring help_description = {} 
)

◆ OptionGroup() [2/4]

Glib::OptionGroup::OptionGroup ( GOptionGroup castitem)
explicit

This always takes ownership of the underlying GOptionGroup, so it is only useful with C functions that return newly-allocated GOptionGroups.

◆ OptionGroup() [3/4]

Glib::OptionGroup::OptionGroup ( const OptionGroup other)
delete

◆ OptionGroup() [4/4]

Glib::OptionGroup::OptionGroup ( OptionGroup &&  other)
delete

◆ ~OptionGroup()

virtual Glib::OptionGroup::~OptionGroup ( )
virtual

Member Function Documentation

◆ add_entry() [1/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry)

◆ add_entry() [2/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
bool &  arg 
)

Add a boolean option entry.

If the option exists among the parsed arguments, the arg parameter will be set to true or, if entry contains OptionEntry::FLAG_REVERSE, to false after OptionContext::parse() has returned.

◆ add_entry() [3/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
const SlotOptionArgString slot 
)

Add a string option entry, but let a callback slot parse the extra argument instead of just setting a variable to its value.

◆ add_entry() [4/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
double arg 
)

Add a double option entry.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

◆ add_entry() [5/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
Glib::ustring arg 
)

Add a UTF-8 string option entry.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

As indicated by the Glib::ustring type, the string will be UTF-8 encoded.

◆ add_entry() [6/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
int arg 
)

Add an integer option entry.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

◆ add_entry() [7/7]

void Glib::OptionGroup::add_entry ( const OptionEntry entry,
vecustrings arg 
)

Add an option entry that provides a list of UTF-8 strings.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

As indicated by the Glib::ustring type, the strings will be UTF-8 encoded.

◆ add_entry_filename() [1/3]

void Glib::OptionGroup::add_entry_filename ( const OptionEntry entry,
const SlotOptionArgFilename slot 
)

Add a filename option entry, but let a callback slot parse the extra argument instead of just setting a variable to its value.

◆ add_entry_filename() [2/3]

void Glib::OptionGroup::add_entry_filename ( const OptionEntry entry,
std::string arg 
)

Add a filename string option entry.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

The string will be in glib's filename encoding.

◆ add_entry_filename() [3/3]

void Glib::OptionGroup::add_entry_filename ( const OptionEntry entry,
vecstrings arg 
)

Add an option entry that provides a list of filename strings.

The arg parameter will be set to the option's extra argument after OptionContext::parse() has returned.

The strings will be in glib's filename encoding.

◆ gobj() [1/2]

GOptionGroup * Glib::OptionGroup::gobj ( )
inline

Provides access to the underlying C instance.

◆ gobj() [2/2]

const GOptionGroup * Glib::OptionGroup::gobj ( ) const
inline

Provides access to the underlying C instance.

◆ gobj_copy()

GOptionGroup * Glib::OptionGroup::gobj_copy ( ) const

Provides access to the underlying C instance. The caller is responsible for unrefing it.

◆ on_error()

virtual void Glib::OptionGroup::on_error ( OptionContext context,
const Error error 
)
virtual

◆ on_post_parse()

virtual bool Glib::OptionGroup::on_post_parse ( OptionContext context)
virtual

◆ on_pre_parse()

virtual bool Glib::OptionGroup::on_pre_parse ( OptionContext context)
virtual

◆ operator=() [1/2]

OptionGroup & Glib::OptionGroup::operator= ( const OptionGroup other)
delete

◆ operator=() [2/2]

OptionGroup & Glib::OptionGroup::operator= ( OptionGroup &&  other)
delete

◆ set_translate_func()

void Glib::OptionGroup::set_translate_func ( const SlotTranslate slot)

Sets the function which is used to translate user-visible strings, for –help output.

Different groups can use a different SlotTranslate. If a translate function is not set, strings are not translated.

If you are using gettext(), you only need to set the translation domain, see set_translation_domain().

Parameters
slotthe slot to be used for translation.
Since glibmm 2.28:

◆ set_translation_domain()

void Glib::OptionGroup::set_translation_domain ( const Glib::ustring domain)

A convenience function to use gettext() for translating user-visible strings.

Since glibmm 2.6:
Parameters
domainThe domain to use.