1 /* $Id: optiongroup.hg,v 1.10.4.1 2006/03/30 12:19:58 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/ustring.h>
25 #include <glib/goption.h> //TODO: Try to hide this.
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 extern "C" { typedef struct _GOptionGroup GOptionGroup; }
30 #endif //DOXYGEN_SHOULD_SKIP_THIS
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39 #endif //DOXYGEN_SHOULD_SKIP_THIS
41 /** An OptionGroup defines the options in a single group.
42 * Libraries which need to parse commandline options are expected to provide a function that allows their OptionGroups to
43 * be added to the application's OptionContext.
47 _CLASS_GENERIC(OptionGroup, GOptionGroup)
49 OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description = Glib::ustring());
51 /** This always takes ownership of the underlying GOptionGroup,
52 * so it is only useful with C functions that return newly-allocated GOptionGroups.
54 explicit OptionGroup(GOptionGroup* castitem);
55 _IGNORE(g_option_group_new)
56 virtual ~OptionGroup();
57 _IGNORE(g_option_group_free)
60 virtual bool on_pre_parse(OptionContext& context, OptionGroup& group);
61 virtual bool on_post_parse(OptionContext& context, OptionGroup& group);
62 virtual void on_error(OptionContext& context, OptionGroup& group);
63 _IGNORE(g_option_group_set_parse_hooks, g_option_group_set_error_hook)
65 void add_entry(const OptionEntry& entry);
66 _IGNORE(g_option_group_add_entries)
69 typedef std::vector<Glib::ustring> vecustrings;
70 typedef std::vector<std::string> vecstrings;
72 void add_entry(const OptionEntry& entry, bool& arg);
73 void add_entry(const OptionEntry& entry, int& arg);
74 void add_entry(const OptionEntry& entry, Glib::ustring& arg);
75 void add_entry_filename(const OptionEntry& entry, std::string& arg);
76 void add_entry(const OptionEntry& entry, vecustrings& arg);
77 void add_entry_filename(const OptionEntry& entry, vecstrings& arg);
80 void g_option_group_set_translate_func (GOptionGroup *group,
83 GDestroyNotify destroy_notify);
85 _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_group_set_translation_domain)
87 GOptionGroup* gobj() { return gobject_; }
88 const GOptionGroup* gobj() const { return gobject_; }
89 GOptionGroup* gobj_give_ownership();
93 #ifndef DOXYGEN_SHOULD_SKIP_THIS
94 /** This is not public API. It is an implementation detail.
101 void allocate_c_arg();
102 void set_c_arg_default(void* cpp_arg);
103 void convert_c_to_cpp();
104 void release_c_arg();
106 GOptionArg carg_type_;
112 void add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg);
114 //Map of entry names to CppOptionEntry:
115 typedef std::map<Glib::ustring, CppOptionEntry> type_map_entries;
116 type_map_entries map_entries_;
118 GOptionGroup* gobject_;
119 bool has_ownership_; //Whether the gobject_ belongs to this C++ instance.
120 #endif //DOXYGEN_SHOULD_SKIP_THIS