add new sigc++2 directory
[ardour.git] / libs / glibmm2 / glib / glibmm / optioncontext.h
1 // -*- c++ -*-
2 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #ifndef _GLIBMM_OPTIONCONTEXT_H
4 #define _GLIBMM_OPTIONCONTEXT_H
5
6
7 /* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */
8
9 /* Copyright (C) 2004 The glibmm Development Team
10  *
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.
15  *
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.
20  *
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.
24  */
25
26
27 #include <glibmm/optionentry.h>
28 #include <glibmm/optiongroup.h>
29 #include <glibmm/error.h>
30 #include <sigc++/signal.h>
31
32 #ifndef DOXYGEN_SHOULD_SKIP_THIS
33 extern "C" { typedef struct _GOptionContext GOptionContext; }
34 #endif
35
36
37 namespace Glib
38 {
39
40 /** Exception class for options.
41  */
42 class OptionError : public Glib::Error
43 {
44 public:
45   enum Code
46   {
47     UNKNOWN_OPTION,
48     BAD_VALUE,
49     FAILED
50   };
51
52   OptionError(Code error_code, const Glib::ustring& error_message);
53   explicit OptionError(GError* gobject);
54   Code code() const;
55
56 #ifndef DOXYGEN_SHOULD_SKIP_THIS
57 private:
58
59 #ifdef GLIBMM_EXCEPTIONS_ENABLED
60   static void throw_func(GError* gobject);
61 #else
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
65
66   friend void wrap_init(); // uses throw_func()
67 #endif
68 };
69
70
71 /** An OptionContext defines which options are accepted by the commandline option parser.
72  */
73 class OptionContext
74 {
75   public:
76 #ifndef DOXYGEN_SHOULD_SKIP_THIS
77   typedef OptionContext CppObjectType;
78   typedef GOptionContext BaseObjectType;
79 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
80
81 private:
82
83 public:
84
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...]
87    */
88   explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring());
89   
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();
94   
95   
96   /** Enables or disables automatic generation of &lt;option&gt;--help&lt;/option&gt; 
97    * output. By default, g_option_context_parse() recognizes
98    * &lt;option&gt;--help&lt;/option&gt;, &lt;option&gt;-?&lt;/option&gt;, &lt;option&gt;--help-all&lt;/option&gt;
99    * and &lt;option&gt;--help-&lt;/option&gt;&lt;replaceable&gt;groupname&lt;/replaceable&gt; and creates
100    * suitable output to stdout. 
101    * 
102    * @newin2p6
103    * @param help_enabled <tt>true</tt> to enable &lt;option&gt;--help&lt;/option&gt;, <tt>false</tt> to disable it.
104    */
105   void set_help_enabled(bool help_enabled = true);
106   
107   /** Returns: <tt>true</tt> if automatic help generation is turned on.
108    * @return <tt>true</tt> if automatic help generation is turned on.
109    * 
110    * @newin2p6.
111    */
112   bool get_help_enabled() const;
113   
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.
117    * 
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.
121    * 
122    * @newin2p6
123    * @param ignore_unknown <tt>true</tt> to ignore unknown options, <tt>false</tt> to produce
124    * an error when unknown options are met.
125    */
126   void set_ignore_unknown_options(bool ignore_unknown = true);
127   
128   /** Returns: <tt>true</tt> if unknown options are ignored.
129    * @return <tt>true</tt> if unknown options are ignored.
130    * 
131    * @newin2p6.
132    */
133   bool get_ignore_unknown_options() const;
134
135  
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
139    * called.
140    * 
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. 
147    * 
148    * If automatic &lt;option&gt;--help&lt;/option&gt; 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>.
153    * 
154    * Note that function depends on the 
155    * current locale for 
156    * automatic character set conversion of string and filename
157    * arguments.
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
163    * 
164    * @newin2p6.
165    */
166 #ifdef GLIBMM_EXCEPTIONS_ENABLED
167   bool parse(int& argc, char**& argv);
168 #else
169   bool parse(int& argc, char**& argv, std::auto_ptr<Glib::Error>& error);
170 #endif //GLIBMM_EXCEPTIONS_ENABLED
171
172
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.
175   
176   
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.
179    *
180    * @param group The group to add.
181    */
182   void add_group(OptionGroup& group);
183   
184   
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.
188    *
189    * @param group The group to add.
190    */
191   void set_main_group(OptionGroup& group);
192   
193   
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;
197   
198
199   GOptionContext*       gobj()       { return gobject_; }
200   const GOptionContext* gobj() const { return gobject_; }
201
202   
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. 
205    * 
206    *             Note that the summary is translated (see set_translate_func(),
207    *             set_translation_domain()).
208    * 
209    *             @newin2p14
210    */
211   void set_summary(const Glib::ustring& summary);
212   
213   /** Returns: the summary
214    *             See set_summary() for more information
215    * @return The summary
216    * 
217    *             @newin2p14.
218    */
219   Glib::ustring get_summary() const;
220   
221   /** Adds a string to be displayed in --help output after the list of
222    *             options. This text often includes a bug reporting address.
223    * 
224    *             Note that the summary is translated (see set_translate_func()).
225    * 
226    *             @newin2p14
227    */
228   void set_description(const Glib::ustring& description);
229   
230   /** Returns: the description
231    *             See set_description() for more information
232    * @return The description
233    * 
234    *             @newin2p14.
235    */
236   Glib::ustring get_description() const;
237
238   
239   /** A convenience function to use gettext() for translating
240    *             user-visible strings. 
241    * 
242    *             @newin2p14
243    */
244   void set_translation_domain(const Glib::ustring& domain);
245
246   /**
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
249    */
250   typedef sigc::slot<Glib::ustring, const Glib::ustring&> SlotTranslate;
251
252   /**
253    * Sets the function which is used to translate user-visible
254    * strings, for --help output.  Different groups can use different functions.
255    *
256    * If you are using gettext(), you only need to set the translation domain,
257    * see set_translation_domain().
258    *
259    * @newin2p14
260    */
261   void set_translate_func (const SlotTranslate& slot);
262   
263
264 protected:
265
266   GOptionContext* gobject_;
267   bool has_ownership_;
268
269
270 };
271
272
273 } // namespace Glib
274
275
276 #endif /* _GLIBMM_OPTIONCONTEXT_H */
277