1 // Generated by gmmproc 2.64.2 -- DO NOT MODIFY!
2 
3 
4 #include <glibmm.h>
5 
6 #include <glibmm/markup.h>
7 #include <glibmm/private/markup_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/markup.h>
27 #include <glibmm/exceptionhandler.h>
28 #include <glibmm/utility.h>
29 #include <glib.h>
30 
31 namespace Glib
32 {
33 
34 namespace Markup
35 {
36 
37 Glib::ustring
escape_text(const Glib::ustring & text)38 escape_text(const Glib::ustring& text)
39 {
40   const auto buf = make_unique_ptr_gfree(g_markup_escape_text(text.data(), text.bytes()));
41   return Glib::ustring(buf.get());
42 }
43 
44 /**** Glib::Markup::AttributeKeyLess ***************************************/
45 
46 bool
operator ()(const Glib::ustring & lhs,const Glib::ustring & rhs) const47 AttributeKeyLess::operator()(const Glib::ustring& lhs, const Glib::ustring& rhs) const
48 {
49   return (lhs.raw() < rhs.raw());
50 }
51 
52 /**** Glib::Markup::ParserCallbacks ****************************************/
53 
54 class ParserCallbacks
55 {
56 public:
57   static const GMarkupParser vfunc_table;
58 
59   static void start_element(GMarkupParseContext* context, const char* element_name,
60     const char** attribute_names, const char** attribute_values, void* user_data, GError** error);
61 
62   static void end_element(
63     GMarkupParseContext* context, const char* element_name, void* user_data, GError** error);
64 
65   static void text(GMarkupParseContext* context, const char* text, gsize text_len, void* user_data,
66     GError** error);
67 
68   static void passthrough(GMarkupParseContext* context, const char* passthrough_text,
69     gsize text_len, void* user_data, GError** error);
70 
71   static void error(GMarkupParseContext* context, GError* error, void* user_data);
72 };
73 
74 const GMarkupParser ParserCallbacks::vfunc_table = {
75   &ParserCallbacks::start_element, &ParserCallbacks::end_element, &ParserCallbacks::text,
76   &ParserCallbacks::passthrough, &ParserCallbacks::error,
77 };
78 
79 void
start_element(GMarkupParseContext * context,const char * element_name,const char ** attribute_names,const char ** attribute_values,void * user_data,GError ** error)80 ParserCallbacks::start_element(GMarkupParseContext* context, const char* element_name,
81   const char** attribute_names, const char** attribute_values, void* user_data, GError** error)
82 {
83   ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
84   g_return_if_fail(context == cpp_context.gobj());
85 
86   try
87   {
88     Parser::AttributeMap attributes;
89 
90     if (attribute_names && attribute_values)
91     {
92       const char* const* pname = attribute_names;
93       const char* const* pvalue = attribute_values;
94 
95       for (; *pname && *pvalue; ++pname, ++pvalue)
96         attributes.insert(Parser::AttributeMap::value_type(*pname, *pvalue));
97 
98       g_return_if_fail(*pname == nullptr && *pvalue == nullptr);
99     }
100 
101     cpp_context.get_parser()->on_start_element(cpp_context, element_name, attributes);
102   }
103   catch (MarkupError& err)
104   {
105     err.propagate(error);
106   }
107   catch (...)
108   {
109     Glib::exception_handlers_invoke();
110   }
111 }
112 
113 void
end_element(GMarkupParseContext * context,const char * element_name,void * user_data,GError ** error)114 ParserCallbacks::end_element(
115   GMarkupParseContext* context, const char* element_name, void* user_data, GError** error)
116 {
117   ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
118   g_return_if_fail(context == cpp_context.gobj());
119 
120   try
121   {
122     cpp_context.get_parser()->on_end_element(cpp_context, element_name);
123   }
124   catch (MarkupError& err)
125   {
126     err.propagate(error);
127   }
128   catch (...)
129   {
130     Glib::exception_handlers_invoke();
131   }
132 }
133 
134 void
text(GMarkupParseContext * context,const char * text,gsize text_len,void * user_data,GError ** error)135 ParserCallbacks::text(
136   GMarkupParseContext* context, const char* text, gsize text_len, void* user_data, GError** error)
137 {
138   ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
139   g_return_if_fail(context == cpp_context.gobj());
140 
141   try
142   {
143     cpp_context.get_parser()->on_text(cpp_context, Glib::ustring(text, text + text_len));
144   }
145   catch (MarkupError& err)
146   {
147     err.propagate(error);
148   }
149   catch (...)
150   {
151     Glib::exception_handlers_invoke();
152   }
153 }
154 
155 void
passthrough(GMarkupParseContext * context,const char * passthrough_text,gsize text_len,void * user_data,GError ** error)156 ParserCallbacks::passthrough(GMarkupParseContext* context, const char* passthrough_text,
157   gsize text_len, void* user_data, GError** error)
158 {
159   ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
160   g_return_if_fail(context == cpp_context.gobj());
161 
162   try
163   {
164     cpp_context.get_parser()->on_passthrough(
165       cpp_context, Glib::ustring(passthrough_text, passthrough_text + text_len));
166   }
167   catch (MarkupError& err)
168   {
169     err.propagate(error);
170   }
171   catch (...)
172   {
173     Glib::exception_handlers_invoke();
174   }
175 }
176 
177 void
error(GMarkupParseContext * context,GError * error,void * user_data)178 ParserCallbacks::error(GMarkupParseContext* context, GError* error, void* user_data)
179 {
180   ParseContext& cpp_context = *static_cast<ParseContext*>(user_data);
181 
182   g_return_if_fail(context == cpp_context.gobj());
183   g_return_if_fail(error->domain == G_MARKUP_ERROR);
184 
185   try
186   {
187     cpp_context.get_parser()->on_error(cpp_context, MarkupError(g_error_copy(error)));
188   }
189   catch (...)
190   {
191     Glib::exception_handlers_invoke();
192   }
193 }
194 
195 /**** Glib::Markup::Parser *************************************************/
196 
Parser()197 Parser::Parser()
198 {
199 }
200 
Parser(Parser && other)201 Parser::Parser(Parser&& other) noexcept : sigc::trackable(std::move(other))
202 {
203 }
204 
205 Parser&
operator =(Parser && other)206 Parser::operator=(Parser&& other) noexcept
207 {
208   sigc::trackable::operator=(std::move(other));
209   return *this;
210 }
211 
~Parser()212 Parser::~Parser()
213 {
214 }
215 
216 void
on_start_element(ParseContext &,const Glib::ustring &,const Parser::AttributeMap &)217 Parser::on_start_element(ParseContext&, const Glib::ustring&, const Parser::AttributeMap&)
218 {
219 }
220 
221 void
on_end_element(ParseContext &,const Glib::ustring &)222 Parser::on_end_element(ParseContext&, const Glib::ustring&)
223 {
224 }
225 
226 void
on_text(ParseContext &,const Glib::ustring &)227 Parser::on_text(ParseContext&, const Glib::ustring&)
228 {
229 }
230 
231 void
on_passthrough(ParseContext &,const Glib::ustring &)232 Parser::on_passthrough(ParseContext&, const Glib::ustring&)
233 {
234 }
235 
236 void
on_error(ParseContext &,const MarkupError &)237 Parser::on_error(ParseContext&, const MarkupError&)
238 {
239 }
240 
241 /**** Glib::Markup::ParseContext *******************************************/
242 
ParseContext(Parser & parser,ParseFlags flags)243 ParseContext::ParseContext(Parser& parser, ParseFlags flags)
244 : parser_(&parser),
245   gobject_(g_markup_parse_context_new(&ParserCallbacks::vfunc_table, (GMarkupParseFlags)flags, this,
246     &ParseContext::destroy_notify_callback))
247 {
248 }
249 
ParseContext(ParseContext && other)250 ParseContext::ParseContext(ParseContext&& other) noexcept : sigc::trackable(std::move(other)),
251                                                             parser_(std::move(other.parser_)),
252                                                             gobject_(std::move(other.gobject_))
253 {
254 }
255 
256 ParseContext&
operator =(ParseContext && other)257 ParseContext::operator=(ParseContext&& other) noexcept
258 {
259   sigc::trackable::operator=(std::move(other));
260 
261   parser_ = std::move(other.parser_);
262   gobject_ = std::move(other.gobject_);
263 
264   other.parser_ = nullptr;
265   other.gobject_ = nullptr;
266 
267   return *this;
268 }
269 
~ParseContext()270 ParseContext::~ParseContext()
271 {
272   parser_ = nullptr;
273   g_markup_parse_context_free(gobject_);
274 }
275 
276 void
parse(const Glib::ustring & text)277 ParseContext::parse(const Glib::ustring& text)
278 {
279   GError* error = nullptr;
280   g_markup_parse_context_parse(gobject_, text.data(), text.bytes(), &error);
281 
282   if (error)
283     Glib::Error::throw_exception(error);
284 }
285 
286 void
parse(const char * text_begin,const char * text_end)287 ParseContext::parse(const char* text_begin, const char* text_end)
288 {
289   GError* error = nullptr;
290   g_markup_parse_context_parse(gobject_, text_begin, text_end - text_begin, &error);
291 
292   if (error)
293     Glib::Error::throw_exception(error);
294 }
295 
296 void
end_parse()297 ParseContext::end_parse()
298 {
299   GError* error = nullptr;
300   g_markup_parse_context_end_parse(gobject_, &error);
301 
302   if (error)
303     Glib::Error::throw_exception(error);
304 }
305 
306 Glib::ustring
get_element() const307 ParseContext::get_element() const
308 {
309   const char* const element_name = g_markup_parse_context_get_element(gobject_);
310   return convert_const_gchar_ptr_to_ustring(element_name);
311 }
312 
313 int
get_line_number() const314 ParseContext::get_line_number() const
315 {
316   int line_number = 0;
317   g_markup_parse_context_get_position(gobject_, &line_number, nullptr);
318   return line_number;
319 }
320 
321 int
get_char_number() const322 ParseContext::get_char_number() const
323 {
324   int char_number = 0;
325   g_markup_parse_context_get_position(gobject_, nullptr, &char_number);
326   return char_number;
327 }
328 
329 // static
330 void
destroy_notify_callback(void * data)331 ParseContext::destroy_notify_callback(void* data)
332 {
333   ParseContext* const self = static_cast<ParseContext*>(data);
334 
335   // Detect premature destruction.
336   g_return_if_fail(self->parser_ == nullptr);
337 }
338 
339 } // namespace Markup
340 
341 } // namespace Glib
342 
343 namespace
344 {
345 } // anonymous namespace
346 
347 
MarkupError(Glib::MarkupError::Code error_code,const Glib::ustring & error_message)348 Glib::MarkupError::MarkupError(Glib::MarkupError::Code error_code, const Glib::ustring& error_message)
349 :
350   Glib::Error (G_MARKUP_ERROR, error_code, error_message)
351 {}
352 
MarkupError(GError * gobject)353 Glib::MarkupError::MarkupError(GError* gobject)
354 :
355   Glib::Error (gobject)
356 {}
357 
code() const358 Glib::MarkupError::Code Glib::MarkupError::code() const
359 {
360   return static_cast<Code>(Glib::Error::code());
361 }
362 
throw_func(GError * gobject)363 void Glib::MarkupError::throw_func(GError* gobject)
364 {
365   throw Glib::MarkupError(gobject);
366 }
367 
368 
369