glibmm r587 - in trunk: . gio/src
- From: jjongsma svn gnome org
- To: svn-commits-list gnome org
- Subject: glibmm r587 - in trunk: . gio/src
- Date: Thu, 7 Feb 2008 03:04:40 +0000 (GMT)
Author: jjongsma
Date: Thu Feb 7 03:04:40 2008
New Revision: 587
URL: http://svn.gnome.org/viewvc/glibmm?rev=587&view=rev
Log:
* gio/src/datainputstream.ccg:
* gio/src/datainputstream.hg: change the read_line() and read_until() APIs
so that they are actually useable. These functions now return a boolean
value to indicate that the end of the stream was reached and return the
string data via reference argument. See bug #514097 for more information
Modified:
trunk/ChangeLog
trunk/gio/src/datainputstream.ccg
trunk/gio/src/datainputstream.hg
Modified: trunk/gio/src/datainputstream.ccg
==============================================================================
--- trunk/gio/src/datainputstream.ccg (original)
+++ trunk/gio/src/datainputstream.ccg Thu Feb 7 03:04:40 2008
@@ -157,17 +157,16 @@
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-std::string DataInputStream::read_line(const Glib::RefPtr<Cancellable>& cancellable)
+bool DataInputStream::read_line(std::string& line, const Glib::RefPtr<Cancellable>& cancellable)
#else
-std::string DataInputStream::read_line(const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
+bool DataInputStream::read_line(std::string& line, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- std::string s =
- Glib::convert_return_gchar_ptr_to_stdstring(g_data_input_stream_read_line(gobj(),
- NULL, // pass NULL since we can easily determine the length from the returned std::string
- cancellable->gobj(),
- &gerror));
+ char* c_line = g_data_input_stream_read_line(gobj(),
+ NULL, // pass NULL since we can easily determine the length from the returned std::string
+ cancellable->gobj(),
+ &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -175,21 +174,26 @@
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
- return s;
+ if (c_line) {
+ line = c_line;
+ g_free (c_line);
+ return true;
+ }
+ // end of stream reached, return failure status
+ return false;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-std::string DataInputStream::read_line()
+bool DataInputStream::read_line(std::string& line)
#else
-std::string DataInputStream::read_line(std::auto_ptr<Glib::Error>& error)
+bool DataInputStream::read_line(std::string& line, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- std::string s =
- Glib::convert_return_gchar_ptr_to_stdstring(g_data_input_stream_read_line(gobj(),
- NULL, // pass NULL since we can easily determine the length from the returned std::string
- NULL,
- &gerror));
+ char* c_line = g_data_input_stream_read_line(gobj(),
+ NULL, // pass NULL since we can easily determine the length from the returned std::string
+ NULL,
+ &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -197,23 +201,28 @@
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
- return s;
+ if (c_line) {
+ line = c_line;
+ g_free(c_line);
+ return true;
+ }
+ // end of stream reached, return failure status
+ return false;
}
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-std::string DataInputStream::read_until(const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable)
+bool DataInputStream::read_until(std::string& data, const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable)
#else
-std::string DataInputStream::read_until(const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
+bool DataInputStream::read_until(std::string& data, const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- std::string s =
- Glib::convert_return_gchar_ptr_to_stdstring(g_data_input_stream_read_until(gobj(),
- stop_chars.c_str(),
- NULL, // pass NULL since we can easily determine the length from the returned std::string
- cancellable->gobj(),
- &gerror));
+ char* c_str = g_data_input_stream_read_until(gobj(),
+ stop_chars.c_str(),
+ NULL, // pass NULL since we can easily determine the length from the returned std::string
+ cancellable->gobj(),
+ &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -221,24 +230,29 @@
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
- return s;
+ if (c_str) {
+ data = c_str;
+ g_free (c_str);
+ return true;
+ }
+ // end of stream reached, return failure status
+ return false;
}
/** non-cancellable version of read_until()
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
-std::string DataInputStream::read_until(const std::string& stop_chars)
+bool DataInputStream::read_until(std::string& data, const std::string& stop_chars)
#else
-std::string DataInputStream::read_until(const std::string& stop_chars, std::auto_ptr<Glib::Error>& error)
+bool DataInputStream::read_until(std::string& data, const std::string& stop_chars, std::auto_ptr<Glib::Error>& error)
#endif //GLIBMM_EXCEPTIONS_ENABLED
{
GError* gerror = 0;
- std::string s =
- Glib::convert_return_gchar_ptr_to_stdstring(g_data_input_stream_read_until(gobj(),
- stop_chars.c_str(),
- NULL, // pass NULL since we can easily determine the length from the returned std::string
- NULL,
- &gerror));
+ char* c_str = g_data_input_stream_read_until(gobj(),
+ stop_chars.c_str(),
+ NULL, // pass NULL since we can easily determine the length from the returned std::string
+ NULL,
+ &gerror);
#ifdef GLIBMM_EXCEPTIONS_ENABLED
if(gerror)
::Glib::Error::throw_exception(gerror);
@@ -246,7 +260,13 @@
if(gerror)
error = ::Glib::Error::throw_exception(gerror);
#endif //GLIBMM_EXCEPTIONS_ENABLED
- return s;
+ if (c_str) {
+ data = c_str;
+ g_free (c_str);
+ return true;
+ }
+ // end of stream reached, return failure status
+ return false;
}
} // namespace Gio
Modified: trunk/gio/src/datainputstream.hg
==============================================================================
--- trunk/gio/src/datainputstream.hg (original)
+++ trunk/gio/src/datainputstream.hg Thu Feb 7 03:04:40 2008
@@ -118,32 +118,32 @@
// empty string from NULL. Perhaps we should use raw pointers as in C, but
// that would mean we need to worry about freeing the C string...
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- std::string read_line(const Glib::RefPtr<Cancellable>& cancellable);
+ bool read_line(std::string& line, const Glib::RefPtr<Cancellable>& cancellable);
#else
- std::string read_line(const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error);
+ bool read_line(std::string& line, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** non-cancellable version of read_line()
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- std::string read_line();
+ bool read_line(std::string& line);
#else
- std::string read_line(std::auto_ptr<Glib::Error>& error);
+ bool read_line(std::string& line, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- std::string read_until(const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable);
+ bool read_until(std::string& data, const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable);
#else
- std::string read_until(const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error);
+ bool read_until(std::string& data, const std::string& stop_chars, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
/** non-cancellable version of read_until()
*/
#ifdef GLIBMM_EXCEPTIONS_ENABLED
- std::string read_until(const std::string& stop_chars);
+ bool read_until(std::string& data, const std::string& stop_chars);
#else
- std::string read_until(const std::string& stop_chars, std::auto_ptr<Glib::Error>& error);
+ bool read_until(std::string& data, const std::string& stop_chars, std::auto_ptr<Glib::Error>& error);
#endif //GLIBMM_EXCEPTIONS_ENABLED
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]