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