// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 2 -*- /* Copyright (C) 2007 The gtkmm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include _DEFS(giomm,gio) _PINCLUDE(giomm/private/bufferedinputstream_p.h) namespace Gio { /** * An implementation of BufferedInputStream that allows for high-level data * manipulation of arbitrary data (including binary operations). * * @ingroup Streams * * @newin{2,16} */ class DataInputStream : public Gio::BufferedInputStream { _CLASS_GOBJECT(DataInputStream, GDataInputStream, G_DATA_INPUT_STREAM, Gio::BufferedInputStream, GBufferedInputStream) protected: _WRAP_CTOR(DataInputStream(const Glib::RefPtr& base_stream), g_data_input_stream_new) public: _WRAP_CREATE(const Glib::RefPtr& base_stream) _WRAP_METHOD(void set_byte_order(DataStreamByteOrder order), g_data_input_stream_set_byte_order) _WRAP_METHOD(DataStreamByteOrder get_byte_order() const, g_data_input_stream_get_byte_order) _WRAP_METHOD(void set_newline_type(DataStreamNewlineType type), g_data_input_stream_set_newline_type) _WRAP_METHOD(DataStreamNewlineType get_newline_type() const, g_data_input_stream_get_newline_type) _WRAP_METHOD(guchar read_byte(const Glib::RefPtr& cancellable), g_data_input_stream_read_byte, errthrow) /** non-cancellable version of read_byte() */ guchar read_byte(); _WRAP_METHOD(gint16 read_int16(const Glib::RefPtr& cancellable), g_data_input_stream_read_int16, errthrow) /** non-cancellable version of read_int16() */ gint16 read_int16(); _WRAP_METHOD(guint16 read_uint16(const Glib::RefPtr& cancellable), g_data_input_stream_read_uint16, errthrow) //TODO: Real documentation: /** non-cancellable version of read_uint16() */ guint16 read_uint16(); _WRAP_METHOD(gint32 read_int32(const Glib::RefPtr& cancellable), g_data_input_stream_read_int32, errthrow) /** non-cancellable version of read_int32() */ gint32 read_int32(); _WRAP_METHOD(guint32 read_uint32(const Glib::RefPtr& cancellable), g_data_input_stream_read_uint32, errthrow) /** non-cancellable version of read_uint32() */ guint32 read_uint32(); _WRAP_METHOD(gint64 read_int64(const Glib::RefPtr& cancellable), g_data_input_stream_read_int64, errthrow) /** non-cancellable version of read_int64() */ gint64 read_int64(); _WRAP_METHOD(guint64 read_uint64(const Glib::RefPtr& cancellable), g_data_input_stream_read_uint64, errthrow) /** non-cancellable version of read_uint64() */ guint64 read_uint64(); //Note that we return a bool because we can't use std::string to distinguish between an empty string and a NULL. /** Reads a line from the data input stream. * * The operation can be cancelled by triggering the cancellable object from * another thread. If the operation * was cancelled, a Gio::Error with CANCELLED will be thrown. * * @param data A string to fill with the read data (without the newlines). * @param cancellable A cancellable object. * @result true if the read succeeded without error. */ bool read_line(std::string& line, const Glib::RefPtr& cancellable); _IGNORE(g_data_input_stream_read_line) /** A non-cancellable version of read_line(). * * @param data A string to fill with the read data (without the newlines). * @result true if the read succeeded without error. */ bool read_line(std::string& line); /** The asynchronous version of read_until(). It is * an error to have two outstanding calls to this function. * * @param slot The slot to call when the request is satisfied. * @param cancellable A cancellable object. * @param io_priority The I/O priority of the request. * @result true if the read succeeded without error. */ void read_line_async(const SlotAsyncReady& slot, const Glib::RefPtr& cancellable, int io_priority = Glib::PRIORITY_DEFAULT); _IGNORE(g_data_input_stream_read_line_async) /** Finish an asynchronous call started by read_line_async(). * * @param result The AsyncResult that was provided to the callback slot. * @param data A string to fill with the read data. * @result true if the read succeeded without error. */ bool read_line_finish(const Glib::RefPtr& result, std::string& data); _IGNORE(g_data_input_stream_read_line_finish) /** Reads a string from the data input stream, up to the first * occurrence of any of the stop characters. * * Note that, in contrast to read_until_async(), * this function consumes the stop character that it finds. * * Don't use this function in new code. Its functionality is * inconsistent with read_until_async(). Both * functions will be marked as deprecated in a future release. Use * read_upto() instead, but note that that method * does not consume the stop character. * * @param data A string to fill with the read data. * @param stop_chars Characters to terminate the read. * @param cancellable A cancellable object. * @result true if the read succeeded without error. */ bool read_until(std::string& data, const std::string& stop_chars, const Glib::RefPtr& cancellable); _IGNORE(g_data_input_stream_read_until) //TODO: This will be really deprecated sometime, maybe even before glib 2.28.0. /** A non-cancellable version of read_until(). * * Note that, in contrast to read_until_async(), * this function consumes the stop character that it finds. * * Don't use this function in new code. Its functionality is * inconsistent with read_until_async(). Both * functions will be marked as deprecated in a future release. Use * read_upto() instead, but note that that method * does not consume the stop character. * * @param stop_chars Characters to terminate the read. * @param data A string to fill with the read data. * @result true if the read succeeded without error. */ bool read_until(std::string& data, const std::string& stop_chars); //TODO: This will be really deprecated sometime after glib 2.28.0. /** The asynchronous version of read_until(). It is * an error to have two outstanding calls to this function. * * Note that, in contrast to ead_until(), * this function does not consume the stop character that it finds. You * must read it for yourself. * * * Don't use this function in new code. Its functionality is * inconsistent with read_until(). Both functions * will be marked as deprecated in a future release. Use * read_upto_async() instead. * * @param stop_chars Characters to terminate the read. * @param slot The slot to call when the request is satisfied. * @param cancellable A cancellable object. * @param io_priority The I/O priority of the request. * @result true if the read succeeded without error. */ void read_until_async(const std::string& stop_chars, const SlotAsyncReady& slot, const Glib::RefPtr& cancellable, int io_priority = Glib::PRIORITY_DEFAULT); _IGNORE(g_data_input_stream_read_until_async) //TODO: This will be really deprecated sometime after glib 2.28.0. /** Finish an asynchronous call started by read_until_async(). * * @param result The AsyncResult that was provided to the callback slot. * @param data A string to fill with the read data. * @result true if the read succeeded without error. */ bool read_until_finish(const Glib::RefPtr& result, std::string& data); _IGNORE(g_data_input_stream_read_until_finish) /** Reads a string from the data input stream, up to the first * occurrence of any of the stop characters. * * In contrast to read_until(), this method * does not consume the stop character. You have * to use read_byte() to get it before calling * read_upto() again. * * @param data A string to fill with the read data. * @param stop_chars Characters to terminate the read. * @param cancellable A cancellable object. * @result true if the read succeeded without error. */ bool read_upto(std::string& data, const std::string& stop_chars, const Glib::RefPtr& cancellable); _IGNORE(g_data_input_stream_read_upto) /** A non-cancellable version of read_upto(). * @param stop_chars Characters to terminate the read. * @param data A string to fill with the read data. * @result true if the read succeeded without error. */ bool read_upto(std::string& data, const std::string& stop_chars); //TODO: Add a version that takes the stop_chars length, to allow a 0 in the middle? /** The asynchronous version of read_upto(). It is * an error to have two outstanding calls to this function. * * In contrast to read_until(), this method * does not consume the stop character. You have * to use read_byte() to get it before calling * read_upto() again. * * @param stop_chars Characters to terminate the read. * @param slot The slot to call when the request is satisfied. * @param cancellable A cancellable object. * @param io_priority The I/O priority of the request. * @result true if the read succeeded without error. */ void read_upto_async(const std::string& stop_chars, const SlotAsyncReady& slot, const Glib::RefPtr& cancellable, int io_priority = Glib::PRIORITY_DEFAULT); _IGNORE(g_data_input_stream_read_upto_async) /** Finish an asynchronous call started by read_upto_async(). * * Note that this function does not consume the * stop character. You have to use read_byte() to * get it before calling read_upto_async() again. * * @param result The AsyncResult that was provided to the callback slot. * @param data A string to fill with the read data. * @result true if the read succeeded without error. */ bool read_upto_finish(const Glib::RefPtr& result, std::string& data); _IGNORE(g_data_input_stream_read_upto_finish) _WRAP_PROPERTY("byte-order", DataStreamByteOrder) _WRAP_PROPERTY("newline-type", DataStreamNewlineType) }; } // namespace Gio