alternative to assert
[gtkD.git] / gtkD / src / glib / OptionGroup.d
blobe78185110d6cbdc9799706d58ac6255b80ba31af
1 /*
2 * This file is part of gtkD.
4 * gtkD is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * gtkD is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with gtkD; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile =
26 * outPack = glib
27 * outFile = OptionGroup
28 * strct = GOptionGroup
29 * realStrct=
30 * ctorStrct=
31 * clss = OptionGroup
32 * interf =
33 * class Code: No
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - g_option_group_
40 * omit structs:
41 * omit prefixes:
42 * omit code:
43 * imports:
44 * - glib.Dataset
45 * - glib.OptionContext
46 * - glib.Str
47 * structWrap:
48 * - GDataset* -> Dataset
49 * - GOptionContext* -> OptionContext
50 * module aliases:
51 * local aliases:
54 module glib.OptionGroup;
56 version(noAssert)
58 version(Tango)
60 import tango.io.Stdout; // use the tango loging?
64 private import gtkc.glibtypes;
66 private import gtkc.glib;
69 private import glib.Dataset;
70 private import glib.OptionContext;
71 private import glib.Str;
76 /**
77 * Description
78 * The GOption commandline parser is intended to be a simpler replacement for the
79 * popt library. It supports short and long commandline options, as shown in the
80 * following example:
81 * testtreemodel -r 1 --max-size 20 --rand --display=:1.0 -vb -- file1 file2
82 * The example demonstrates a number of features of the GOption commandline parser
83 * Options can be single letters, prefixed by a single dash. Multiple
84 * short options can be grouped behind a single dash.
85 * Long options are prefixed by two consecutive dashes.
86 * Options can have an extra argument, which can be a number, a string or a
87 * filename. For long options, the extra argument can be appended with an
88 * equals sign after the option name.
89 * Non-option arguments are returned to the application as rest arguments.
90 * An argument consisting solely of two dashes turns off further parsing,
91 * any remaining arguments (even those starting with a dash) are returned
92 * to the application as rest arguments.
93 * Another important feature of GOption is that it can automatically generate
94 * nicely formatted help output. Unless it is explicitly turned off with
95 * g_option_context_set_help_enabled(), GOption will recognize the
96 * --help, -?, --help-all
97 * and --help-groupname options
98 * (where groupname is the name of a GOptionGroup)
99 * and write a text similar to the one shown in the following example to stdout.
100 * Usage:
101 * testtreemodel [OPTION...] - test tree model performance
102 * Help Options:
103 * -?, --help Show help options
104 * --help-all Show all help options
105 * --help-gtk Show GTK+ Options
106 * Application Options:
107 * -r, --repeats=N Average over N repetitions
108 * -m, --max-size=M Test up to 2^M items
109 * --display=DISPLAY X display to use
110 * -v, --verbose Be verbose
111 * -b, --beep Beep when done
112 * --rand Randomize the data
113 * GOption groups options in GOptionGroups, which makes it easy to
114 * incorporate options from multiple sources. The intended use for this is
115 * to let applications collect option groups from the libraries it uses,
116 * add them to their GOptionContext, and parse all options by a single call
117 * to g_option_context_parse(). See gtk_get_option_group() for an example.
118 * If an option is declared to be of type string or filename, GOption takes
119 * care of converting it to the right encoding; strings are returned in UTF-8,
120 * filenames are returned in the GLib filename encoding. Note that this only
121 * works if setlocale() has been called before g_option_context_parse().
122 * Here is a complete example of setting up GOption to parse the example
123 * commandline above and produce the example help output.
124 * static gint repeats = 2;
125 * static gint max_size = 8;
126 * static gboolean verbose = FALSE;
127 * static gboolean beep = FALSE;
128 * static gboolean rand = FALSE;
129 * static GOptionEntry entries[] =
131 * { "repeats", 'r', 0, G_OPTION_ARG_INT, repeats, "Average over N repetitions", "N" },
132 * { "max-size", 'm', 0, G_OPTION_ARG_INT, max_size, "Test up to 2^M items", "M" },
133 * { "verbose", 'v', 0, G_OPTION_ARG_NONE, verbose, "Be verbose", NULL },
134 * { "beep", 'b', 0, G_OPTION_ARG_NONE, beep, "Beep when done", NULL },
135 * { "rand", 0, 0, G_OPTION_ARG_NONE, rand, "Randomize the data", NULL },
136 * { NULL }
137 * };
138 * int
139 * main (int argc, char *argv[])
141 * GError *error = NULL;
142 * GOptionContext *context;
143 * context = g_option_context_new ("- test tree model performance");
144 * g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
145 * g_option_context_add_group (context, gtk_get_option_group (TRUE));
146 * g_option_context_parse (context, argc, argv, error);
147 * /+* ... +/
150 public class OptionGroup
153 /** the main Gtk struct */
154 protected GOptionGroup* gOptionGroup;
157 public GOptionGroup* getOptionGroupStruct()
159 return gOptionGroup;
163 /** the main Gtk struct as a void* */
164 protected void* getStruct()
166 return cast(void*)gOptionGroup;
170 * Sets our main struct and passes it to the parent class
172 public this (GOptionGroup* gOptionGroup)
174 version(noAssert)
176 if ( gOptionGroup is null )
178 int zero = 0;
179 version(Tango)
181 Stdout("struct gOptionGroup is null on constructor").newline;
183 else
185 printf("struct gOptionGroup is null on constructor");
187 zero = zero / zero;
190 else
192 assert(gOptionGroup !is null, "struct gOptionGroup is null on constructor");
194 this.gOptionGroup = gOptionGroup;
228 * Creates a new GOptionGroup.
229 * name:
230 * the name for the option group, this is used to provide
231 * help for the options in this group with --help-name
232 * description:
233 * a description for this group to be shown in
234 * --help. This string is translated using the translation
235 * domain or translation function of the group
236 * help_description:
237 * a description for the --help-name option.
238 * This string is translated using the translation domain or translation function
239 * of the group
240 * user_data:
241 * user data that will be passed to the pre- and post-parse hooks,
242 * the error hook and to callbacks of G_OPTION_ARG_CALLBACK options, or NULL
243 * destroy:
244 * a function that will be called to free user_data, or NULL
245 * Returns:
246 * a newly created option group. It should be added
247 * to a GOptionContext or freed with g_option_group_free().
248 * Since 2.6
250 public this (char[] name, char[] description, char[] helpDescription, void* userData, GDestroyNotify destroy)
252 // GOptionGroup* g_option_group_new (const gchar *name, const gchar *description, const gchar *help_description, gpointer user_data, GDestroyNotify destroy);
253 this(cast(GOptionGroup*)g_option_group_new(Str.toStringz(name), Str.toStringz(description), Str.toStringz(helpDescription), userData, destroy) );
257 * Frees a GOptionGroup. Note that you must not
258 * free groups which have been added to a GOptionContext.
259 * group:
260 * a GOptionGroup
261 * Since 2.6
263 public void free()
265 // void g_option_group_free (GOptionGroup *group);
266 g_option_group_free(gOptionGroup);
270 * Adds the options specified in entries to group.
271 * group:
272 * a GOptionGroup
273 * entries:
274 * a NULL-terminated array of GOptionEntrys
275 * Since 2.6
277 public void addEntries(GOptionEntry* entries)
279 // void g_option_group_add_entries (GOptionGroup *group, const GOptionEntry *entries);
280 g_option_group_add_entries(gOptionGroup, entries);
285 * Associates two functions with group which will be called
286 * from g_option_context_parse() before the first option is parsed
287 * and after the last option has been parsed, respectively.
288 * Note that the user data to be passed to pre_parse_func and
289 * post_parse_func can be specified when constructing the group
290 * with g_option_group_new().
291 * group:
292 * a GOptionGroup
293 * pre_parse_func:
294 * a function to call before parsing, or NULL
295 * post_parse_func:
296 * a function to call after parsing, or NULL
297 * Since 2.6
299 public void setParseHooks(GOptionParseFunc preParseFunc, GOptionParseFunc postParseFunc)
301 // void g_option_group_set_parse_hooks (GOptionGroup *group, GOptionParseFunc pre_parse_func, GOptionParseFunc post_parse_func);
302 g_option_group_set_parse_hooks(gOptionGroup, preParseFunc, postParseFunc);
307 * Associates a function with group which will be called
308 * from g_option_context_parse() when an error occurs.
309 * Note that the user data to be passed to pre_parse_func and
310 * post_parse_func can be specified when constructing the group
311 * with g_option_group_new().
312 * group:
313 * a GOptionGroup
314 * error_func:
315 * a function to call when an error occurs
316 * Since 2.6
318 public void setErrorHook(GOptionErrorFunc errorFunc)
320 // void g_option_group_set_error_hook (GOptionGroup *group, GOptionErrorFunc error_func);
321 g_option_group_set_error_hook(gOptionGroup, errorFunc);
325 * Sets the function which is used to translate user-visible
326 * strings, for --help output. Different
327 * groups can use different GTranslateFuncs. If func
328 * is NULL, strings are not translated.
329 * If you are using gettext(), you only need to set the translation
330 * domain, see g_option_group_set_translation_domain().
331 * group:
332 * a GOptionGroup
333 * func:
334 * the GTranslateFunc, or NULL
335 * data:
336 * user data to pass to func, or NULL
337 * destroy_notify:
338 * a function which gets called to free data, or NULL
339 * Since 2.6
341 public void setTranslateFunc(GTranslateFunc func, void* data, GDestroyNotify destroyNotify)
343 // void g_option_group_set_translate_func (GOptionGroup *group, GTranslateFunc func, gpointer data, GDestroyNotify destroy_notify);
344 g_option_group_set_translate_func(gOptionGroup, func, data, destroyNotify);
348 * A convenience function to use gettext() for translating
349 * user-visible strings.
350 * group:
351 * a GOptionGroup
352 * domain:
353 * the domain to use
354 * Since 2.6
356 public void setTranslationDomain(char[] domain)
358 // void g_option_group_set_translation_domain (GOptionGroup *group, const gchar *domain);
359 g_option_group_set_translation_domain(gOptionGroup, Str.toStringz(domain));