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)
44 _IGNORE(g_option_context_free)
47 /** Creates a new option context.
48 * @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...]
50 explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
52 //Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance,
53 //so it should be used carefully. For instance you could not access data in a derived class via this second instance.
54 explicit OptionContext(GOptionContext* castitem, bool take_ownership = false);
55 virtual ~OptionContext();
57 _WRAP_METHOD(void set_help_enabled(bool help_enabled = true), g_option_context_set_help_enabled)
58 _WRAP_METHOD(bool get_help_enabled() const, g_option_context_get_help_enabled)
59 _WRAP_METHOD(void set_ignore_unknown_options(bool ignore_unknown = true), g_option_context_set_ignore_unknown_options)
60 _WRAP_METHOD(bool get_ignore_unknown_options() const, g_option_context_get_ignore_unknown_options)
62 #m4 _CONVERSION(`char**&',`gchar***',`&($3)')
63 _WRAP_METHOD(bool parse(int& argc, char**& argv), g_option_context_parse, errthrow)
65 //g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group()
66 //- a group without callbacks seems to do some simple default parsing.
67 _IGNORE(g_option_context_add_main_entries)
69 /** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group.
70 * Note that the group will not be copied, so it should exist for as long as the context exists.
72 * @param group The group to add.
74 void add_group(OptionGroup& group);
75 _IGNORE(g_option_context_add_group)
77 /** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only
78 * difference is that the options in the main group are treated differently when generating --help output.
79 * Note that the group will not be copied, so it should exist for as long as the context exists.
81 * @param group The group to add.
83 void set_main_group(OptionGroup& group);
84 _IGNORE(g_option_context_set_main_group)
86 //We don't need this (hopefully), and the memory management would be really awkward.
87 //OptionGroup& get_main_group();
88 //const OptionGroup& get_main_group() const;
89 _IGNORE(g_option_context_get_main_group)
91 #m4 _CONVERSION(`const OptionGroup&',`GOptionGroup*',`const_cast<GOptionGroup*>(($3).gobj())')
92 _WRAP_METHOD(Glib::ustring get_help(bool main_help, const OptionGroup& group) const, g_option_context_get_help)
94 //TODO: Documentation.
95 Glib::ustring get_help(bool main_help = true) const;
97 GOptionContext* gobj() { return gobject_; }
98 const GOptionContext* gobj() const { return gobject_; }
100 _WRAP_METHOD(void set_summary(const Glib::ustring& summary), g_option_context_set_summary)
101 _WRAP_METHOD(Glib::ustring get_summary() const, g_option_context_get_summary)
102 _WRAP_METHOD(void set_description(const Glib::ustring& description), g_option_context_set_description)
103 _WRAP_METHOD(Glib::ustring get_description() const, g_option_context_get_description)
105 _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_context_set_translation_domain)
108 * This function is used to translate user-visible strings, for --help output.
109 * The function takes an untranslated string and returns a translated string
111 typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
114 * Sets the function which is used to translate user-visible
115 * strings, for --help output. Different groups can use different functions.
117 * If you are using gettext(), you only need to set the translation domain,
118 * see set_translation_domain().
122 void set_translate_func (const SlotTranslate& slot);
123 _IGNORE(g_option_context_set_translate_func)
127 GOptionContext* gobject_;