~ubuntu-branches/ubuntu/trusty/glibmm2.4/trusty

« back to all changes in this revision

Viewing changes to gio/giomm/converter.h

  • Committer: Package Import Robot
  • Author(s): Robert Ancell
  • Date: 2012-09-12 09:46:50 UTC
  • mfrom: (1.2.76)
  • Revision ID: package-import@ubuntu.com-20120912094650-36b1cyv60x66yv8m
Tags: 2.33.12-0ubuntu1
* New upstream bugfix release
* debian/control:
  - Bump build-depends on libglib2.0-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c++ -*-
 
2
// Generated by gtkmmproc -- DO NOT MODIFY!
 
3
#ifndef _GIOMM_CONVERTER_H
 
4
#define _GIOMM_CONVERTER_H
 
5
 
 
6
 
 
7
#include <glibmm/ustring.h>
 
8
#include <sigc++/sigc++.h>
 
9
 
 
10
// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 
11
 
 
12
/* Copyright (C) 2012 The giomm Development Team
 
13
 *
 
14
 * This library is free software; you can redistribute it and/or
 
15
 * modify it under the terms of the GNU Lesser General Public
 
16
 * License as published by the Free Software Foundation; either
 
17
 * version 2.1 of the License, or (at your option) any later version.
 
18
 *
 
19
 * This library is distributed in the hope that it will be useful,
 
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
22
 * Lesser General Public License for more details.
 
23
 *
 
24
 * You should have received a copy of the GNU Lesser General Public
 
25
 * License along with this library; if not, write to the Free
 
26
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
27
 */
 
28
 
 
29
#include <glibmm/interface.h>
 
30
 
 
31
 
 
32
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
33
typedef struct _GConverterIface GConverterIface;
 
34
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
35
 
 
36
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
37
typedef struct _GConverter GConverter;
 
38
typedef struct _GConverterClass GConverterClass;
 
39
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
40
 
 
41
 
 
42
namespace Gio
 
43
{ class Converter_Class; } // namespace Gio
 
44
namespace Gio
 
45
{
 
46
 
 
47
/** @addtogroup giommEnums giomm Enums and Flags */
 
48
 
 
49
/**
 
50
 * @ingroup giommEnums
 
51
 */
 
52
enum ConverterResult
 
53
{
 
54
  CONVERTER_ERROR,
 
55
  CONVERTER_CONVERTED,
 
56
  CONVERTER_FINISHED,
 
57
  CONVERTER_FLUSHED
 
58
};
 
59
 
 
60
} // namespace Gio
 
61
 
 
62
 
 
63
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
64
namespace Glib
 
65
{
 
66
 
 
67
template <>
 
68
class Value<Gio::ConverterResult> : public Glib::Value_Enum<Gio::ConverterResult>
 
69
{
 
70
public:
 
71
  static GType value_type() G_GNUC_CONST;
 
72
};
 
73
 
 
74
} // namespace Glib
 
75
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
76
 
 
77
 
 
78
namespace Gio
 
79
{
 
80
 
 
81
/**
 
82
 * @ingroup giommEnums
 
83
 * @par Bitwise operators:
 
84
 * <tt>%ConverterFlags operator|(ConverterFlags, ConverterFlags)</tt><br>
 
85
 * <tt>%ConverterFlags operator&(ConverterFlags, ConverterFlags)</tt><br>
 
86
 * <tt>%ConverterFlags operator^(ConverterFlags, ConverterFlags)</tt><br>
 
87
 * <tt>%ConverterFlags operator~(ConverterFlags)</tt><br>
 
88
 * <tt>%ConverterFlags& operator|=(ConverterFlags&, ConverterFlags)</tt><br>
 
89
 * <tt>%ConverterFlags& operator&=(ConverterFlags&, ConverterFlags)</tt><br>
 
90
 * <tt>%ConverterFlags& operator^=(ConverterFlags&, ConverterFlags)</tt><br>
 
91
 */
 
92
enum ConverterFlags
 
93
{
 
94
  CONVERTER_NO_FLAGS = 0x0,
 
95
  CONVERTER_INPUT_AT_END = (1 << 0),
 
96
  CONVERTER_FLUSH = (1 << 1)
 
97
};
 
98
 
 
99
/** @ingroup giommEnums */
 
100
inline ConverterFlags operator|(ConverterFlags lhs, ConverterFlags rhs)
 
101
  { return static_cast<ConverterFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
 
102
 
 
103
/** @ingroup giommEnums */
 
104
inline ConverterFlags operator&(ConverterFlags lhs, ConverterFlags rhs)
 
105
  { return static_cast<ConverterFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
 
106
 
 
107
/** @ingroup giommEnums */
 
108
inline ConverterFlags operator^(ConverterFlags lhs, ConverterFlags rhs)
 
109
  { return static_cast<ConverterFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
 
110
 
 
111
/** @ingroup giommEnums */
 
112
inline ConverterFlags operator~(ConverterFlags flags)
 
113
  { return static_cast<ConverterFlags>(~static_cast<unsigned>(flags)); }
 
114
 
 
115
/** @ingroup giommEnums */
 
116
inline ConverterFlags& operator|=(ConverterFlags& lhs, ConverterFlags rhs)
 
117
  { return (lhs = static_cast<ConverterFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
 
118
 
 
119
/** @ingroup giommEnums */
 
120
inline ConverterFlags& operator&=(ConverterFlags& lhs, ConverterFlags rhs)
 
121
  { return (lhs = static_cast<ConverterFlags>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
 
122
 
 
123
/** @ingroup giommEnums */
 
124
inline ConverterFlags& operator^=(ConverterFlags& lhs, ConverterFlags rhs)
 
125
  { return (lhs = static_cast<ConverterFlags>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
 
126
 
 
127
} // namespace Gio
 
128
 
 
129
 
 
130
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
131
namespace Glib
 
132
{
 
133
 
 
134
template <>
 
135
class Value<Gio::ConverterFlags> : public Glib::Value_Flags<Gio::ConverterFlags>
 
136
{
 
137
public:
 
138
  static GType value_type() G_GNUC_CONST;
 
139
};
 
140
 
 
141
} // namespace Glib
 
142
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
143
 
 
144
 
 
145
namespace Gio
 
146
{
 
147
 
 
148
 
 
149
/** Converter - Data conversion interface.
 
150
 * Converter is implemented by objects that convert binary data in various
 
151
 * ways. The conversion can be stateful and may fail at any place.
 
152
 *
 
153
 * Some example conversions are: character set conversion, compression,
 
154
 * decompression and regular expression replace. 
 
155
 *
 
156
 * @newin{2,34}
 
157
 */
 
158
 
 
159
class Converter : public Glib::Interface
 
160
{
 
161
  
 
162
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
163
 
 
164
public:
 
165
  typedef Converter CppObjectType;
 
166
  typedef Converter_Class CppClassType;
 
167
  typedef GConverter BaseObjectType;
 
168
  typedef GConverterIface BaseClassType;
 
169
 
 
170
private:
 
171
  friend class Converter_Class;
 
172
  static CppClassType converter_class_;
 
173
 
 
174
  // noncopyable
 
175
  Converter(const Converter&);
 
176
  Converter& operator=(const Converter&);
 
177
 
 
178
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
179
protected:
 
180
  /**
 
181
   * You should derive from this class to use it.
 
182
   */
 
183
  Converter();
 
184
  
 
185
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
186
  /** Called by constructors of derived classes. Provide the result of 
 
187
   * the Class init() function to ensure that it is properly 
 
188
   * initialized.
 
189
   * 
 
190
   * @param interface_class The Class object for the derived type.
 
191
   */
 
192
  explicit Converter(const Glib::Interface_Class& interface_class);
 
193
 
 
194
public:
 
195
  // This is public so that C++ wrapper instances can be
 
196
  // created for C instances of unwrapped types.
 
197
  // For instance, if an unexpected C type implements the C interface. 
 
198
  explicit Converter(GConverter* castitem);
 
199
 
 
200
protected:
 
201
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
 
202
 
 
203
public:
 
204
  virtual ~Converter();
 
205
 
 
206
  static void add_interface(GType gtype_implementer);
 
207
 
 
208
  /** Get the GType for this class, for use with the underlying GObject type system.
 
209
   */
 
210
  static GType get_type()      G_GNUC_CONST;
 
211
 
 
212
#ifndef DOXYGEN_SHOULD_SKIP_THIS
 
213
  static GType get_base_type() G_GNUC_CONST;
 
214
#endif
 
215
 
 
216
  ///Provides access to the underlying C GObject.
 
217
  GConverter*       gobj()       { return reinterpret_cast<GConverter*>(gobject_); }
 
218
 
 
219
  ///Provides access to the underlying C GObject.
 
220
  const GConverter* gobj() const { return reinterpret_cast<GConverter*>(gobject_); }
 
221
 
 
222
private:
 
223
 
 
224
 
 
225
public:
 
226
  
 
227
  /** This is the main operation used when converting data. It is to be called
 
228
   * multiple times in a loop, and each time it will do some work, i.e.
 
229
   * producing some output (in @a outbuf) or consuming some input (from @a inbuf) or
 
230
   * both. If its not possible to do any work an error is returned.
 
231
   * 
 
232
   * Note that a single call may not consume all input (or any input at all).
 
233
   * Also a call may produce output even if given no input, due to state stored
 
234
   * in the converter producing output.
 
235
   * 
 
236
   * If any data was either produced or consumed, and then an error happens, then
 
237
   * only the successful conversion is reported and the error is returned on the
 
238
   * next call.
 
239
   * 
 
240
   * A full conversion loop involves calling this method repeatedly, each time
 
241
   * giving it new input and space output space. When there is no more input
 
242
   * data after the data in @a inbuf, the flag CONVERTER_INPUT_AT_END must be set.
 
243
   * The loop will be (unless some error happens) returning CONVERTER_CONVERTED
 
244
   * each time until all data is consumed and all output is produced, then
 
245
   * CONVERTER_FINISHED is returned instead. Note, that CONVERTER_FINISHED
 
246
   * may be returned even if CONVERTER_INPUT_AT_END is not set, for instance
 
247
   * in a decompression converter where the end of data is detectable from the
 
248
   * data (and there might even be other data after the end of the compressed data).
 
249
   * 
 
250
   * When some data has successfully been converted @a bytes_read and is set to
 
251
   * the number of bytes read from @a inbuf, and @a bytes_written is set to indicate
 
252
   * how many bytes was written to @a outbuf. If there are more data to output
 
253
   * or consume (i.e. unless the CONVERTER_INPUT_AT_END is specified) then
 
254
   * CONVERTER_CONVERTED is returned, and if no more data is to be output
 
255
   * then CONVERTER_FINISHED is returned.
 
256
   * 
 
257
   * On error CONVERTER_ERROR is returned and @a error is set accordingly.
 
258
   * Some errors need special handling:
 
259
   * 
 
260
   * IO_ERROR_NO_SPACE is returned if there is not enough space
 
261
   * to write the resulting converted data, the application should
 
262
   * call the function again with a larger @a outbuf to continue.
 
263
   * 
 
264
   * IO_ERROR_PARTIAL_INPUT is returned if there is not enough
 
265
   * input to fully determine what the conversion should produce,
 
266
   * and the CONVERTER_INPUT_AT_END flag is not set. This happens for
 
267
   * example with an incomplete multibyte sequence when converting text,
 
268
   * or when a regexp matches up to the end of the input (and may match
 
269
   * further input). It may also happen when @a inbuf_size is zero and
 
270
   * there is no more data to produce.
 
271
   * 
 
272
   * When this happens the application should read more input and then
 
273
   * call the function again. If further input shows that there is no
 
274
   * more data call the function again with the same data but with
 
275
   * the CONVERTER_INPUT_AT_END flag set. This may cause the conversion
 
276
   * to finish as e.g. in the regexp match case (or, to fail again with
 
277
   * IO_ERROR_PARTIAL_INPUT in e.g. a charset conversion where the
 
278
   * input is actually partial).
 
279
   * 
 
280
   * After g_converter_convert() has returned CONVERTER_FINISHED the
 
281
   * converter object is in an invalid state where its not allowed
 
282
   * to call g_converter_convert() anymore. At this time you can only
 
283
   * free the object or call g_converter_reset() to reset it to the
 
284
   * initial state.
 
285
   * 
 
286
   * If the flag CONVERTER_FLUSH is set then conversion is modified
 
287
   * to try to write out all internal state to the output. The application
 
288
   * has to call the function multiple times with the flag set, and when
 
289
   * the available input has been consumed and all internal state has
 
290
   * been produced then CONVERTER_FLUSHED (or CONVERTER_FINISHED if
 
291
   * really at the end) is returned instead of CONVERTER_CONVERTED.
 
292
   * This is somewhat similar to what happens at the end of the input stream,
 
293
   * but done in the middle of the data.
 
294
   * 
 
295
   * This has different meanings for different conversions. For instance
 
296
   * in a compression converter it would mean that we flush all the
 
297
   * compression state into output such that if you uncompress the
 
298
   * compressed data you get back all the input data. Doing this may
 
299
   * make the final file larger due to padding though. Another example
 
300
   * is a regexp conversion, where if you at the end of the flushed data
 
301
   * have a match, but there is also a potential longer match. In the
 
302
   * non-flushed case we would ask for more input, but when flushing we
 
303
   * treat this as the end of input and do the match.
 
304
   * 
 
305
   * Flushing is not always possible (like if a charset converter flushes
 
306
   * at a partial multibyte sequence). Converters are supposed to try
 
307
   * to produce as much output as possible and then return an error
 
308
   * (typically IO_ERROR_PARTIAL_INPUT).
 
309
   * 
 
310
   * @newin{2,24}
 
311
   * @param inbuf The buffer
 
312
   * containing the data to convert.
 
313
   * @param inbuf_size The number of bytes in @a inbuf.
 
314
   * @param outbuf A buffer to write converted data in.
 
315
   * @param outbuf_size The number of bytes in @a outbuf, must be at least one.
 
316
   * @param flags A ConverterFlags controlling the conversion details.
 
317
   * @param bytes_read Will be set to the number of bytes read from @a inbuf on success.
 
318
   * @param bytes_written Will be set to the number of bytes written to @a outbuf on success.
 
319
   * @return A ConverterResult, CONVERTER_ERROR on error.
 
320
   */
 
321
  ConverterResult convert(const void* inbuf, gsize inbuf_size, void* outbuf, gsize outbuf_size, ConverterFlags flags, gsize& bytes_read, gsize& bytes_written);
 
322
  
 
323
  /** Resets all internal state in the converter, making it behave
 
324
   * as if it was just created. If the converter has any internal
 
325
   * state that would produce output then that output is lost.
 
326
   * 
 
327
   * @newin{2,24}
 
328
   */
 
329
  void reset();
 
330
 
 
331
 
 
332
    virtual ConverterResult convert_vfunc(const void* inbuf, gsize inbuf_size, void* outbuf, gsize outbuf_size, ConverterFlags flags, gsize& bytes_read, gsize& bytes_written);
 
333
 
 
334
 
 
335
    virtual void reset_vfunc();
 
336
 
 
337
 
 
338
public:
 
339
 
 
340
public:
 
341
  //C++ methods used to invoke GTK+ virtual functions:
 
342
 
 
343
protected:
 
344
  //GTK+ Virtual Functions (override these to change behaviour):
 
345
 
 
346
  //Default Signal Handlers::
 
347
 
 
348
 
 
349
};
 
350
 
 
351
} // namespace Gio
 
352
 
 
353
 
 
354
namespace Glib
 
355
{
 
356
  /** A Glib::wrap() method for this object.
 
357
   * 
 
358
   * @param object The C instance.
 
359
   * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
 
360
   * @result A C++ instance that wraps this C instance.
 
361
   *
 
362
   * @relates Gio::Converter
 
363
   */
 
364
  Glib::RefPtr<Gio::Converter> wrap(GConverter* object, bool take_copy = false);
 
365
 
 
366
} // namespace Glib
 
367
 
 
368
 
 
369
#endif /* _GIOMM_CONVERTER_H */
 
370