2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GLIBMM_OPTIONCONTEXT_H
4 #define _GLIBMM_OPTIONCONTEXT_H
7 /* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */
9 /* Copyright (C) 2004 The glibmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #include <glibmm/optionentry.h>
28 #include <glibmm/optiongroup.h>
29 #include <glibmm/error.h>
30 #include <sigc++/signal.h>
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 extern "C" { typedef struct _GOptionContext GOptionContext; }
40 /** Exception class for options.
42 class OptionError : public Glib::Error
52 OptionError(Code error_code, const Glib::ustring& error_message);
53 explicit OptionError(GError* gobject);
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
59 #ifdef GLIBMM_EXCEPTIONS_ENABLED
60 static void throw_func(GError* gobject);
62 //When not using exceptions, we just pass the Exception object around without throwing it:
63 static std::auto_ptr<Glib::Error> throw_func(GError* gobject);
64 #endif //GLIBMM_EXCEPTIONS_ENABLED
66 friend void wrap_init(); // uses throw_func()
71 /** An OptionContext defines which options are accepted by the commandline option parser.
76 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77 typedef OptionContext CppObjectType;
78 typedef GOptionContext BaseObjectType;
79 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
85 /** Creates a new option context.
86 * @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...]
88 explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
90 //Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance,
91 //so it should be used carefully. For instance you could not access data in a derived class via this second instance.
92 explicit OptionContext(GOptionContext* castitem, bool take_ownership = false);
93 virtual ~OptionContext();
96 /** Enables or disables automatic generation of <option>--help</option>
97 * output. By default, g_option_context_parse() recognizes
98 * <option>--help</option>, <option>-?</option>, <option>--help-all</option>
99 * and <option>--help-</option><replaceable>groupname</replaceable> and creates
100 * suitable output to stdout.
103 * @param help_enabled <tt>true</tt> to enable <option>--help</option>, <tt>false</tt> to disable it.
105 void set_help_enabled(bool help_enabled = true);
107 /** Returns: <tt>true</tt> if automatic help generation is turned on.
108 * @return <tt>true</tt> if automatic help generation is turned on.
112 bool get_help_enabled() const;
114 /** Sets whether to ignore unknown options or not. If an argument is
115 * ignored, it is left in the @a argv array after parsing. By default,
116 * g_option_context_parse() treats unknown options as error.
118 * This setting does not affect non-option arguments (i.e. arguments
119 * which don't start with a dash). But note that GOption cannot reliably
120 * determine whether a non-option belongs to a preceding unknown option.
123 * @param ignore_unknown <tt>true</tt> to ignore unknown options, <tt>false</tt> to produce
124 * an error when unknown options are met.
126 void set_ignore_unknown_options(bool ignore_unknown = true);
128 /** Returns: <tt>true</tt> if unknown options are ignored.
129 * @return <tt>true</tt> if unknown options are ignored.
133 bool get_ignore_unknown_options() const;
136 /** Parses the command line arguments, recognizing options
137 * which have been added to @a context . A side-effect of
138 * calling this function is that g_set_prgname() will be
141 * If the parsing is successful, any parsed arguments are
142 * removed from the array and @a argc and @a argv are updated
143 * accordingly. A '--' option is stripped from @a argv
144 * unless there are unparsed options before and after it,
145 * or some of the options after it start with '-'. In case
146 * of an error, @a argc and @a argv are left unmodified.
148 * If automatic <option>--help</option> support is enabled
149 * (see g_option_context_set_help_enabled()), and the
150 * @a argv array contains one of the recognized help options,
151 * this function will produce help output to stdout and
152 * call <tt>exit (0)</tt>.
154 * Note that function depends on the
156 * automatic character set conversion of string and filename
158 * @param argc A pointer to the number of command line arguments.
159 * @param argv A pointer to the array of command line arguments.
160 * @param error A return location for errors.
161 * @return <tt>true</tt> if the parsing was successful,
162 * <tt>false</tt> if an error occurred
166 #ifdef GLIBMM_EXCEPTIONS_ENABLED
167 bool parse(int& argc, char**& argv);
169 bool parse(int& argc, char**& argv, std::auto_ptr<Glib::Error>& error);
170 #endif //GLIBMM_EXCEPTIONS_ENABLED
173 //g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group()
174 //- a group without callbacks seems to do some simple default parsing.
177 /** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group.
178 * Note that the group will not be copied, so it should exist for as long as the context exists.
180 * @param group The group to add.
182 void add_group(OptionGroup& group);
185 /** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only
186 * difference is that the options in the main group are treated differently when generating --help output.
187 * Note that the group will not be copied, so it should exist for as long as the context exists.
189 * @param group The group to add.
191 void set_main_group(OptionGroup& group);
194 //We don't need this (hopefully), and the memory management would be really awkward.
195 //OptionGroup& get_main_group();
196 //const OptionGroup& get_main_group() const;
199 GOptionContext* gobj() { return gobject_; }
200 const GOptionContext* gobj() const { return gobject_; }
203 /** Adds a string to be displayed in --help output before the list of options. This
204 * is typically a summary of the program functionality.
206 * Note that the summary is translated (see set_translate_func(),
207 * set_translation_domain()).
211 void set_summary(const Glib::ustring& summary);
213 /** Returns: the summary
214 * See set_summary() for more information
215 * @return The summary
219 Glib::ustring get_summary() const;
221 /** Adds a string to be displayed in --help output after the list of
222 * options. This text often includes a bug reporting address.
224 * Note that the summary is translated (see set_translate_func()).
228 void set_description(const Glib::ustring& description);
230 /** Returns: the description
231 * See set_description() for more information
232 * @return The description
236 Glib::ustring get_description() const;
239 /** A convenience function to use gettext() for translating
240 * user-visible strings.
244 void set_translation_domain(const Glib::ustring& domain);
247 * This function is used to translate user-visible strings, for --help output.
248 * The function takes an untranslated string and returns a translated string
250 typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
253 * Sets the function which is used to translate user-visible
254 * strings, for --help output. Different groups can use different functions.
256 * If you are using gettext(), you only need to set the translation domain,
257 * see set_translation_domain().
261 void set_translate_func (const SlotTranslate& slot);
266 GOptionContext* gobject_;
276 #endif /* _GLIBMM_OPTIONCONTEXT_H */