rollback to 3428, before the mysterious removal of libs/* at 3431/3432
[ardour.git] / libs / glibmm2 / glib / src / optiongroup.hg
1 /* $Id: optiongroup.hg,v 1.10.4.1 2006/03/30 12:19:58 murrayc Exp $ */
2
3 /* Copyright (C) 2004 The glibmm Development Team
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 _DEFS(glibmm,glib)
21
22 #include <glibmm/ustring.h>
23 #include <map>
24 #include <vector>
25 #include <glib/goption.h> //TODO: Try to hide this.
26
27
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 extern "C" { typedef struct _GOptionGroup GOptionGroup; }
30 #endif //DOXYGEN_SHOULD_SKIP_THIS
31
32
33 namespace Glib
34 {
35
36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 class OptionEntry;
38 class OptionContext;
39 #endif //DOXYGEN_SHOULD_SKIP_THIS
40
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.
44  */
45 class OptionGroup
46 {
47   _CLASS_GENERIC(OptionGroup, GOptionGroup)
48 public:
49   OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description = Glib::ustring());
50
51   /** This always takes ownership of the underlying GOptionGroup, 
52    * so it is only useful with C functions that return newly-allocated GOptionGroups. 
53    */
54   explicit OptionGroup(GOptionGroup* castitem);  
55   _IGNORE(g_option_group_new)
56   virtual ~OptionGroup();
57   _IGNORE(g_option_group_free)
58
59
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)
64
65   void add_entry(const OptionEntry& entry);
66   _IGNORE(g_option_group_add_entries)
67
68
69   typedef std::vector<Glib::ustring> vecustrings;
70   typedef std::vector<std::string> vecstrings;
71
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);
78
79 /* TODO:
80 void          g_option_group_set_translate_func     (GOptionGroup       *group,
81                                                      GTranslateFunc      func,
82                                                      gpointer            data,
83                                                      GDestroyNotify      destroy_notify);
84 */
85   _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_group_set_translation_domain)
86
87   GOptionGroup*       gobj()       { return gobject_; }
88   const GOptionGroup* gobj() const { return gobject_; }
89   GOptionGroup* gobj_give_ownership();
90
91 protected:
92
93 #ifndef DOXYGEN_SHOULD_SKIP_THIS
94   /** This is not public API. It is an implementation detail.
95    */
96   class CppOptionEntry
97   {
98   public:
99     CppOptionEntry();
100
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();
105
106     GOptionArg carg_type_;
107     void* carg_;
108     void* cpparg_;
109     OptionEntry* entry_;
110   };
111
112   void add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg);
113
114   //Map of entry names to CppOptionEntry:
115   typedef std::map<Glib::ustring, CppOptionEntry> type_map_entries;
116   type_map_entries map_entries_;
117
118   GOptionGroup* gobject_;
119   bool has_ownership_; //Whether the gobject_ belongs to this C++ instance.
120 #endif //DOXYGEN_SHOULD_SKIP_THIS
121 };
122
123 } // namespace Glib
124