1 /* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */
3 /* Copyright (C) 2004 The glibmm Development Team
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <glibmm/optionentry.h>
23 #include <glibmm/optiongroup.h>
24 #include <glibmm/error.h>
25 #include <sigc++/signal.h>
27 #ifndef DOXYGEN_SHOULD_SKIP_THIS
28 extern "C" { typedef struct _GOptionContext GOptionContext; }
35 /** Exception class for options.
37 _WRAP_GERROR(OptionError, GOptionError, G_OPTION_ERROR, NO_GTYPE)
39 /** An OptionContext defines which options are accepted by the commandline option parser.
43 _CLASS_GENERIC(OptionContext, GOptionContext)
46 /** Creates a new option context.
47 * @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...]
49 explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
51 //Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance,
52 //so it should be used carefully. For instance you could not access data in a derived class via this second instance.
53 explicit OptionContext(GOptionContext* castitem, bool take_ownership = false);
54 virtual ~OptionContext();
56 _WRAP_METHOD(void set_help_enabled(bool help_enabled = true), g_option_context_set_help_enabled)
57 _WRAP_METHOD(bool get_help_enabled() const, g_option_context_get_help_enabled)
58 _WRAP_METHOD(void set_ignore_unknown_options(bool ignore_unknown = true), g_option_context_set_ignore_unknown_options)
59 _WRAP_METHOD(bool get_ignore_unknown_options() const, g_option_context_get_ignore_unknown_options)
61 #m4 _CONVERSION(`char**&',`gchar***',`&($3)')
62 _WRAP_METHOD(bool parse(int& argc, char**& argv), g_option_context_parse, errthrow)
64 //g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group()
65 //- a group without callbacks seems to do some simple default parsing.
66 _IGNORE(g_option_context_add_main_entries)
68 /** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group.
69 * Note that the group will not be copied, so it should exist for as long as the context exists.
71 * @param group The group to add.
73 void add_group(OptionGroup& group);
74 _IGNORE(g_option_context_add_group)
76 /** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only
77 * difference is that the options in the main group are treated differently when generating --help output.
78 * Note that the group will not be copied, so it should exist for as long as the context exists.
80 * @param group The group to add.
82 void set_main_group(OptionGroup& group);
83 _IGNORE(g_option_context_set_main_group)
85 //We don't need this (hopefully), and the memory management would be really awkward.
86 //OptionGroup& get_main_group();
87 //const OptionGroup& get_main_group() const;
88 _IGNORE(g_option_context_get_main_group)
91 GOptionContext* gobj() { return gobject_; }
92 const GOptionContext* gobj() const { return gobject_; }
94 _WRAP_METHOD(void set_summary(const Glib::ustring& summary), g_option_context_set_summary)
95 _WRAP_METHOD(Glib::ustring get_summary() const, g_option_context_get_summary)
96 _WRAP_METHOD(void set_description(const Glib::ustring& description), g_option_context_set_description)
97 _WRAP_METHOD(Glib::ustring get_description() const, g_option_context_get_description)
99 _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_context_set_translation_domain)
102 * This function is used to translate user-visible strings, for --help output.
103 * The function takes an untranslated string and returns a translated string
105 typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
108 * Sets the function which is used to translate user-visible
109 * strings, for --help output. Different groups can use different functions.
111 * If you are using gettext(), you only need to set the translation domain,
112 * see set_translation_domain().
116 void set_translate_func (const SlotTranslate& slot);
117 _IGNORE(g_option_context_set_translate_func)
121 GOptionContext* gobject_;