1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY!
2
3
4 #include <glibmm.h>
5
6 #include <glibmm/optioncontext.h>
7 #include <glibmm/private/optioncontext_p.h>
8
9
10 /* Copyright (C) 2002 The gtkmm Development Team
11 *
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26 #include <glibmm/utility.h>
27 #include <glibmm/exceptionhandler.h>
28 #include <glib.h>
29
30 namespace Glib
31 {
32
33 namespace OptionContextPrivate
34 {
35 static const gchar*
SignalProxy_translate_gtk_callback(const gchar * str,gpointer data)36 SignalProxy_translate_gtk_callback(const gchar* str, gpointer data)
37 {
38 Glib::ustring translated_str;
39 Glib::OptionContext::SlotTranslate* the_slot =
40 static_cast<Glib::OptionContext::SlotTranslate*>(data);
41
42 try
43 {
44 translated_str = (*the_slot)(str);
45 }
46 catch (...)
47 {
48 Glib::exception_handlers_invoke();
49 }
50 return translated_str.c_str();
51 }
52
53 static void
SignalProxy_translate_gtk_callback_destroy(gpointer data)54 SignalProxy_translate_gtk_callback_destroy(gpointer data)
55 {
56 delete static_cast<Glib::OptionContext::SlotTranslate*>(data);
57 }
58
59 } // namespace OptionContextPrivate
60
OptionContext(const Glib::ustring & parameter_string)61 OptionContext::OptionContext(const Glib::ustring& parameter_string)
62 : gobject_(g_option_context_new(parameter_string.c_str())), has_ownership_(true)
63 {
64 }
65
OptionContext(GOptionContext * castitem,bool take_ownership)66 OptionContext::OptionContext(GOptionContext* castitem, bool take_ownership)
67 : gobject_(castitem), has_ownership_(take_ownership)
68 {
69 }
70
OptionContext(OptionContext && other)71 OptionContext::OptionContext(OptionContext&& other) noexcept
72 : gobject_(std::move(other.gobject_)),
73 has_ownership_(std::move(other.has_ownership_))
74 {
75 other.gobject_ = nullptr;
76 other.has_ownership_ = false;
77 }
78
79 OptionContext&
operator =(OptionContext && other)80 OptionContext::operator=(OptionContext&& other) noexcept
81 {
82 if (has_ownership_)
83 g_option_context_free(gobj());
84
85 gobject_ = std::move(other.gobject_);
86 has_ownership_ = std::move(other.has_ownership_);
87
88 other.gobject_ = nullptr;
89 other.has_ownership_ = false;
90
91 return *this;
92 }
93
~OptionContext()94 OptionContext::~OptionContext()
95 {
96 if (has_ownership_)
97 g_option_context_free(gobj());
98
99 gobject_ = nullptr;
100 }
101
102 void
add_group(OptionGroup & group)103 OptionContext::add_group(OptionGroup& group)
104 {
105 // Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
106 g_option_context_add_group(gobj(), (group).gobj_give_ownership());
107 }
108
109 void
set_main_group(OptionGroup & group)110 OptionContext::set_main_group(OptionGroup& group)
111 {
112 // Strangely, GObjectContext actually takes ownership of the GOptionGroup, deleting it later.
113 g_option_context_set_main_group(gobj(), (group).gobj_give_ownership());
114 }
115
116 /*
117 OptionGroup OptionContext::get_main_group() const
118 {
119 const auto cobj = g_option_context_get_main_group(const_cast<GOptionContext*>( gobj()) );
120 OptionGroup cppObj(const_cast<GOptionGroup*>(cobj), true); // take_copy
121 return cppObj;
122 }
123
124 */
125
126 void
set_translate_func(const SlotTranslate & slot)127 OptionContext::set_translate_func(const SlotTranslate& slot)
128 {
129 // Create a copy of the slot. A pointer to this will be passed through the callback's data
130 // parameter.
131 // It will be deleted when SignalProxy_translate_gtk_callback_destroy() is called.
132 auto slot_copy = new SlotTranslate(slot);
133
134 g_option_context_set_translate_func(gobj(),
135 &OptionContextPrivate::SignalProxy_translate_gtk_callback, slot_copy,
136 &OptionContextPrivate::SignalProxy_translate_gtk_callback_destroy);
137 }
138
139 Glib::ustring
get_help(bool main_help) const140 OptionContext::get_help(bool main_help) const
141 {
142 return Glib::convert_return_gchar_ptr_to_ustring(g_option_context_get_help(
143 const_cast<GOptionContext*>(gobj()), static_cast<int>(main_help), nullptr));
144 }
145
146 } // namespace Glib
147
148 namespace
149 {
150 } // anonymous namespace
151
152
OptionError(Glib::OptionError::Code error_code,const Glib::ustring & error_message)153 Glib::OptionError::OptionError(Glib::OptionError::Code error_code, const Glib::ustring& error_message)
154 :
155 Glib::Error (G_OPTION_ERROR, error_code, error_message)
156 {}
157
OptionError(GError * gobject)158 Glib::OptionError::OptionError(GError* gobject)
159 :
160 Glib::Error (gobject)
161 {}
162
code() const163 Glib::OptionError::Code Glib::OptionError::code() const
164 {
165 return static_cast<Code>(Glib::Error::code());
166 }
167
throw_func(GError * gobject)168 void Glib::OptionError::throw_func(GError* gobject)
169 {
170 throw Glib::OptionError(gobject);
171 }
172
173
174 namespace Glib
175 {
176
177
set_help_enabled(bool help_enabled)178 void OptionContext::set_help_enabled(bool help_enabled)
179 {
180 g_option_context_set_help_enabled(gobj(), static_cast<int>(help_enabled));
181 }
182
get_help_enabled() const183 bool OptionContext::get_help_enabled() const
184 {
185 return g_option_context_get_help_enabled(const_cast<GOptionContext*>(gobj()));
186 }
187
set_ignore_unknown_options(bool ignore_unknown)188 void OptionContext::set_ignore_unknown_options(bool ignore_unknown)
189 {
190 g_option_context_set_ignore_unknown_options(gobj(), static_cast<int>(ignore_unknown));
191 }
192
get_ignore_unknown_options() const193 bool OptionContext::get_ignore_unknown_options() const
194 {
195 return g_option_context_get_ignore_unknown_options(const_cast<GOptionContext*>(gobj()));
196 }
197
set_strict_posix(bool strict_posix)198 void OptionContext::set_strict_posix(bool strict_posix)
199 {
200 g_option_context_set_strict_posix(gobj(), static_cast<int>(strict_posix));
201 }
202
get_strict_posix() const203 bool OptionContext::get_strict_posix() const
204 {
205 return g_option_context_get_strict_posix(const_cast<GOptionContext*>(gobj()));
206 }
207
parse(int & argc,char ** & argv)208 bool OptionContext::parse(int& argc, char**& argv)
209 {
210 GError* gerror = nullptr;
211 bool retvalue = g_option_context_parse(gobj(), &(argc), &(argv), &(gerror));
212 if(gerror)
213 ::Glib::Error::throw_exception(gerror);
214 return retvalue;
215 }
216
parse(char ** & argv)217 bool OptionContext::parse(char**& argv)
218 {
219 GError* gerror = nullptr;
220 bool retvalue = g_option_context_parse_strv(gobj(), &(argv), &(gerror));
221 if(gerror)
222 ::Glib::Error::throw_exception(gerror);
223 return retvalue;
224 }
225
get_help(bool main_help,const OptionGroup & group) const226 Glib::ustring OptionContext::get_help(bool main_help, const OptionGroup& group) const
227 {
228 return Glib::convert_return_gchar_ptr_to_ustring(g_option_context_get_help(const_cast<GOptionContext*>(gobj()), static_cast<int>(main_help), const_cast<GOptionGroup*>((group).gobj())));
229 }
230
set_summary(const Glib::ustring & summary)231 void OptionContext::set_summary(const Glib::ustring& summary)
232 {
233 g_option_context_set_summary(gobj(), summary.c_str());
234 }
235
get_summary() const236 Glib::ustring OptionContext::get_summary() const
237 {
238 return Glib::convert_const_gchar_ptr_to_ustring(g_option_context_get_summary(const_cast<GOptionContext*>(gobj())));
239 }
240
set_description(const Glib::ustring & description)241 void OptionContext::set_description(const Glib::ustring& description)
242 {
243 g_option_context_set_description(gobj(), description.c_str());
244 }
245
get_description() const246 Glib::ustring OptionContext::get_description() const
247 {
248 return Glib::convert_const_gchar_ptr_to_ustring(g_option_context_get_description(const_cast<GOptionContext*>(gobj())));
249 }
250
set_translation_domain(const Glib::ustring & domain)251 void OptionContext::set_translation_domain(const Glib::ustring& domain)
252 {
253 g_option_context_set_translation_domain(gobj(), domain.c_str());
254 }
255
256
257 } // namespace Glib
258
259
260