1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY! 2 #ifndef _GLIBMM_OPTIONGROUP_H 3 #define _GLIBMM_OPTIONGROUP_H 4 5 6 /* Copyright (C) 2004 The glibmm Development Team 7 * 8 * This library is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU Lesser General Public 10 * License as published by the Free Software Foundation; either 11 * version 2.1 of the License, or (at your option) any later version. 12 * 13 * This library is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * Lesser General Public License for more details. 17 * 18 * You should have received a copy of the GNU Lesser General Public 19 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 23 #include <glibmm/ustring.h> 24 #include <sigc++/slot.h> 25 #include <map> 26 #include <vector> 27 #include <glib.h> //TODO: Try to hide this. 28 29 30 #ifndef DOXYGEN_SHOULD_SKIP_THIS 31 extern "C" { typedef struct _GOptionGroup GOptionGroup; } 32 #endif //DOXYGEN_SHOULD_SKIP_THIS 33 34 35 namespace Glib 36 { 37 38 #ifndef DOXYGEN_SHOULD_SKIP_THIS 39 class GLIBMM_API OptionEntry; 40 class GLIBMM_API OptionContext; 41 #endif //DOXYGEN_SHOULD_SKIP_THIS 42 43 //TODO: GOptionGroup is now refcounted. See https://bugzilla.gnome.org/show_bug.cgi?id=743349 44 //When we can break API/ABI, make Glib::OptionGroup refcounted. _CLASS_OPAQUE_REFCOUNTED? 45 /** An OptionGroup defines the options in a single group. 46 * Libraries which need to parse commandline options are expected to provide a function that allows their OptionGroups to 47 * be added to the application's OptionContext. 48 */ 49 class GLIBMM_API OptionGroup 50 { 51 public: 52 #ifndef DOXYGEN_SHOULD_SKIP_THIS 53 using CppObjectType = OptionGroup; 54 using BaseObjectType = GOptionGroup; 55 #endif /* DOXYGEN_SHOULD_SKIP_THIS */ 56 57 private: 58 59 public: 60 /** For example Glib::ustring on_translate(const Glib::ustring& original);. 61 */ 62 using SlotTranslate = sigc::slot<Glib::ustring, const Glib::ustring&>; 63 64 /** For example bool on_option_arg_string(const Glib::ustring& option_name, 65 * const Glib::ustring& value, bool has_value);. 66 */ 67 using SlotOptionArgString = sigc::slot<bool, const Glib::ustring&, const Glib::ustring&, bool>; 68 69 /** For example bool on_option_arg_filename(const Glib::ustring& option_name, 70 * const std::string& value, bool has_value);. 71 */ 72 using SlotOptionArgFilename = sigc::slot<bool, const Glib::ustring&, const std::string&, bool>; 73 74 OptionGroup(const Glib::ustring& name, const Glib::ustring& description, const Glib::ustring& help_description = Glib::ustring()); 75 76 /** This always takes ownership of the underlying GOptionGroup, 77 * so it is only useful with C functions that return newly-allocated GOptionGroups. 78 */ 79 explicit OptionGroup(GOptionGroup* castitem); 80 81 82 OptionGroup(OptionGroup&& other) noexcept; 83 OptionGroup& operator=(OptionGroup&& other) noexcept; 84 85 virtual ~OptionGroup(); 86 87 88 virtual bool on_pre_parse(OptionContext& context, OptionGroup& group); 89 virtual bool on_post_parse(OptionContext& context, OptionGroup& group); 90 virtual void on_error(OptionContext& context, OptionGroup& group); 91 92 93 void add_entry(const OptionEntry& entry); 94 95 96 using vecustrings = std::vector<Glib::ustring>; 97 using vecstrings = std::vector<std::string>; 98 99 /** Add a boolean option @a entry. 100 * If the option exists among the parsed arguments, the @a arg parameter will 101 * be set to <tt>true</tt> or, if @a entry contains OptionEntry::FLAG_REVERSE, 102 * to <tt>false</tt> after OptionContext::parse() has returned. 103 */ 104 void add_entry(const OptionEntry& entry, bool& arg); 105 106 /** Add an integer option @a entry. 107 * The @a arg parameter will be set to the option's extra argument 108 * after OptionContext::parse() has returned. 109 */ 110 void add_entry(const OptionEntry& entry, int& arg); 111 112 /** Add a double option @a entry. 113 * The @a arg parameter will be set to the option's extra argument 114 * after OptionContext::parse() has returned. 115 */ 116 void add_entry(const OptionEntry& entry, double& arg); 117 118 /** Add a UTF-8 string option @a entry. 119 * The @a arg parameter will be set to the option's extra argument 120 * after OptionContext::parse() has returned. 121 * 122 * As indicated by the Glib::ustring type, the string will be 123 * UTF-8 encoded. 124 */ 125 void add_entry(const OptionEntry& entry, Glib::ustring& arg); 126 127 /** Add a filename string option @a entry. 128 * The @a arg parameter will be set to the option's extra argument 129 * after OptionContext::parse() has returned. 130 * 131 * The string will be in glib's filename encoding. 132 */ 133 void add_entry_filename(const OptionEntry& entry, std::string& arg); 134 135 /** Add an option @a entry that provides a list of UTF-8 strings. 136 * The @a arg parameter will be set to the option's extra argument 137 * after OptionContext::parse() has returned. 138 * 139 * As indicated by the Glib::ustring type, the strings will be 140 * UTF-8 encoded. 141 */ 142 void add_entry(const OptionEntry& entry, vecustrings& arg); 143 144 /** Add an option @a entry that provides a list of filename strings. 145 * The @a arg parameter will be set to the option's extra argument 146 * after OptionContext::parse() has returned. 147 * 148 * The strings will be in glib's filename encoding. 149 */ 150 void add_entry_filename(const OptionEntry& entry, vecstrings& arg); 151 152 /** Add a string option @a entry, but let a callback slot parse the extra argument 153 * instead of just setting a variable to its value. 154 */ 155 void add_entry(const OptionEntry& entry, const SlotOptionArgString& slot); 156 157 /** Add a filename option @a entry, but let a callback slot parse the extra argument 158 * instead of just setting a variable to its value. 159 */ 160 void add_entry_filename(const OptionEntry& entry, const SlotOptionArgFilename& slot); 161 162 /** Sets the function which is used to translate user-visible strings, for 163 * --help output. Different groups can use a different SlotTranslate. If a 164 * translate function is not set, strings are not translated. 165 * 166 * If you are using gettext(), you only need to set the translation domain, 167 * see set_translation_domain(). 168 * 169 * @param slot the slot to be used for translation. 170 * 171 * @newin{2,28} 172 */ 173 void set_translate_func(const SlotTranslate& slot); 174 175 176 /** A convenience function to use gettext() for translating 177 * user-visible strings. 178 * 179 * @newin{2,6} 180 * 181 * @param domain The domain to use. 182 */ 183 void set_translation_domain(const Glib::ustring& domain); 184 gobj()185 GOptionGroup* gobj() { return gobject_; } gobj()186 const GOptionGroup* gobj() const { return gobject_; } 187 GOptionGroup* gobj_give_ownership(); 188 189 protected: 190 191 #ifndef DOXYGEN_SHOULD_SKIP_THIS 192 /** This is not public API. It is an implementation detail. 193 */ 194 class CppOptionEntry 195 { 196 public: 197 CppOptionEntry(); 198 199 void allocate_c_arg(); 200 void set_c_arg_default(void* cpp_arg); 201 void convert_c_to_cpp(); 202 void release_c_arg(); 203 204 GOptionArg carg_type_; 205 void* carg_; 206 void* cpparg_; 207 OptionEntry* entry_; 208 }; 209 210 void add_entry_with_wrapper(const OptionEntry& entry, GOptionArg arg_type, void* cpp_arg); 211 212 static gboolean post_parse_callback(GOptionContext* context, 213 GOptionGroup* group, gpointer data, GError** error); 214 215 static gboolean option_arg_callback(const gchar* option_name, const gchar* value, 216 gpointer data, GError** error); 217 218 //Map of entry names to CppOptionEntry: 219 typedef std::map<Glib::ustring, CppOptionEntry> type_map_entries; 220 type_map_entries map_entries_; 221 222 GOptionGroup* gobject_; 223 bool has_ownership_; //Whether the gobject_ belongs to this C++ instance. 224 #endif //DOXYGEN_SHOULD_SKIP_THIS 225 226 private: 227 void release_gobject() noexcept; 228 229 230 }; 231 232 } // namespace Glib 233 234 235 #endif /* _GLIBMM_OPTIONGROUP_H */ 236 237