/* $Id: optioncontext.hg,v 1.6 2005/01/10 17:42:17 murrayc Exp $ */ /* Copyright (C) 2004 The glibmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ _DEFS(glibmm,glib) #include #include #include #include #ifndef DOXYGEN_SHOULD_SKIP_THIS extern "C" { typedef struct _GOptionContext GOptionContext; } #endif namespace Glib { /** Exception class for options. */ _WRAP_GERROR(OptionError, GOptionError, G_OPTION_ERROR, NO_GTYPE) /** An OptionContext defines which options are accepted by the commandline option parser. */ class OptionContext { _CLASS_GENERIC(OptionContext, GOptionContext) _IGNORE(g_option_context_free) public: /** Creates a new option context. * @param parameter_string A string which is displayed in the first line of --help output, after programname [OPTION...] */ explicit OptionContext(const Glib::ustring& parameter_string = Glib::ustring()); //Note that, unlike Glib::Wrap(), this would create a second C++ instance for the same C instance, //so it should be used carefully. For instance you could not access data in a derived class via this second instance. explicit OptionContext(GOptionContext* castitem, bool take_ownership = false); virtual ~OptionContext(); _WRAP_METHOD(void set_help_enabled(bool help_enabled = true), g_option_context_set_help_enabled) _WRAP_METHOD(bool get_help_enabled() const, g_option_context_get_help_enabled) _WRAP_METHOD(void set_ignore_unknown_options(bool ignore_unknown = true), g_option_context_set_ignore_unknown_options) _WRAP_METHOD(bool get_ignore_unknown_options() const, g_option_context_get_ignore_unknown_options) #m4 _CONVERSION(`char**&',`gchar***',`&($3)') _WRAP_METHOD(bool parse(int& argc, char**& argv), g_option_context_parse, errthrow) //g_option_context_add_main_entries(), just creates a group internally, adds them to it, and does a set_main_group() //- a group without callbacks seems to do some simple default parsing. _IGNORE(g_option_context_add_main_entries) /** Adds an OptionGroup to the context, so that parsing with context will recognize the options in the group. * Note that the group will not be copied, so it should exist for as long as the context exists. * * @param group The group to add. */ void add_group(OptionGroup& group); _IGNORE(g_option_context_add_group) /** Sets an OptionGroup as the main group of the context. This has the same effect as calling add_group(), the only * difference is that the options in the main group are treated differently when generating --help output. * Note that the group will not be copied, so it should exist for as long as the context exists. * * @param group The group to add. */ void set_main_group(OptionGroup& group); _IGNORE(g_option_context_set_main_group) //We don't need this (hopefully), and the memory management would be really awkward. //OptionGroup& get_main_group(); //const OptionGroup& get_main_group() const; _IGNORE(g_option_context_get_main_group) #m4 _CONVERSION(`const OptionGroup&',`GOptionGroup*',`const_cast(($3).gobj())') _WRAP_METHOD(Glib::ustring get_help(bool main_help, const OptionGroup& group) const, g_option_context_get_help) //TODO: Documentation. Glib::ustring get_help(bool main_help = true) const; GOptionContext* gobj() { return gobject_; } const GOptionContext* gobj() const { return gobject_; } _WRAP_METHOD(void set_summary(const Glib::ustring& summary), g_option_context_set_summary) _WRAP_METHOD(Glib::ustring get_summary() const, g_option_context_get_summary) _WRAP_METHOD(void set_description(const Glib::ustring& description), g_option_context_set_description) _WRAP_METHOD(Glib::ustring get_description() const, g_option_context_get_description) _WRAP_METHOD(void set_translation_domain(const Glib::ustring& domain), g_option_context_set_translation_domain) /** * This function is used to translate user-visible strings, for --help output. * The function takes an untranslated string and returns a translated string */ typedef sigc::slot SlotTranslate; /** * Sets the function which is used to translate user-visible * strings, for --help output. Different groups can use different functions. * * If you are using gettext(), you only need to set the translation domain, * see set_translation_domain(). * * @newin2p14 */ void set_translate_func (const SlotTranslate& slot); _IGNORE(g_option_context_set_translate_func) protected: GOptionContext* gobject_; bool has_ownership_; }; } // namespace Glib