glibmm r803 - in trunk: . examples/keyfile examples/regex gio/src glib/src tests/giomm_ioerror tests/giomm_simple



Author: daniel
Date: Mon Mar 23 11:58:58 2009
New Revision: 803
URL: http://svn.gnome.org/viewvc/glibmm?rev=803&view=rev

Log:
Fix --disable-api-exceptions build

* glib/src/keyfile.{ccg,hg}: Conditionalize all exception-handling
code in order to fix the build with --disable-api-exceptions.
* glib/src/regex.hg: ditto,
* gio/src/appinfo.ccg: ditto,
* gio/src/file.{ccg,hg}: ditto,
* gio/src/outputstream.ccg: ditto,
* examples/keyfile/main.cc: ditto,
* examples/regex/main.cc: ditto,
* tests/giomm_ioerror/main.cc: ditto,
* tests/giomm_simple/main.cc: ditto.


Modified:
   trunk/   (props changed)
   trunk/ChangeLog
   trunk/examples/keyfile/main.cc
   trunk/examples/regex/main.cc
   trunk/gio/src/appinfo.ccg
   trunk/gio/src/file.ccg
   trunk/gio/src/file.hg
   trunk/gio/src/outputstream.ccg
   trunk/glib/src/keyfile.ccg
   trunk/glib/src/keyfile.hg
   trunk/tests/giomm_ioerror/main.cc
   trunk/tests/giomm_simple/main.cc

Modified: trunk/examples/keyfile/main.cc
==============================================================================
--- trunk/examples/keyfile/main.cc	(original)
+++ trunk/examples/keyfile/main.cc	Mon Mar 23 11:58:58 2009
@@ -19,33 +19,24 @@
 #include <iostream>
 
 
-int main(int argc, char** argv)
+int main(int, char**)
 {
-  // This example should be executed like so:
-  // ./example the_ini_file.ini
-  
   Glib::init();
-   
-  std::string filepath = "./example.ini";
+
+  const std::string filepath = "./example.ini";
 
   Glib::KeyFile keyfile;
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   // An exception will be thrown if the file is not there, or if the file is incorrectly formatted:
   try
   {
-    const bool loaded = keyfile.load_from_file(filepath);
-    if(!loaded)
-      std::cerr << "Could not load keyfile." << std::endl;
+    keyfile.load_from_file(filepath);
   }
-  catch(const Glib::FileError& ex)
+  catch(const Glib::Error& ex)
   {
     std::cerr << "Exception while loading key file: " << ex.what() << std::endl;
-    return -1;
-  }
-  catch(const Glib::KeyFileError& ex)
-  {
-    std::cerr << "Exception while loading key file: " << ex.what() << std::endl;
-    return -1;
+    return 1;
   }
 
   // Try to get a value that is not in the file:
@@ -58,7 +49,6 @@
   catch(const Glib::KeyFileError& ex)
   {
     std::cerr << "Exception while getting value: " << ex.what() << std::endl;
-    //return -1;
   }
 
   // Try to get a value that is in the file:
@@ -71,26 +61,60 @@
   catch(const Glib::KeyFileError& ex)
   {
     std::cerr << "Exception while getting value: " << ex.what() << std::endl;
-    //return -1;
   }
 
   // Try to get a list of integers that is in the file:
   // An exception will be thrown if the value is not in the file:
   try
   {
-    typedef std::list<int> type_list_integers;
-    const type_list_integers value_list = keyfile.get_integer_list("Another Group", "Numbers");
-    for(type_list_integers::const_iterator iter = value_list.begin(); iter != value_list.end(); ++iter)
-    {
-      const int value = *iter;
-      std::cout << "Number list value: item=" << value << std::endl;
-    }
+    const std::vector<int> values = keyfile.get_integer_list("Another Group", "Numbers");
+
+    for(std::vector<int>::const_iterator p = values.begin(); p != values.end(); ++p)
+      std::cout << "Number list value: item=" << *p << std::endl;
   }
   catch(const Glib::KeyFileError& ex)
   {
     std::cerr << "Exception while getting list value: " << ex.what() << std::endl;
-    //return -1;
   }
+#else /* !GLIBMM_EXCEPTIONS_ENABLED */
+  std::auto_ptr<Glib::Error> ex;
+
+  if(!keyfile.load_from_file(filepath, Glib::KeyFileFlags(), ex))
+  {
+    std::cerr << "Exception while loading key file: " << ex->what() << std::endl;
+    return 1;
+  }
+
+  // Try to get a value that is not in the file:
+  {
+    const Glib::ustring value = keyfile.get_value("somegroup", "somekey", ex);
+    if (!ex.get())
+      std::cout << "somekey value=" << value << std::endl;
+    else
+      std::cerr << "Exception while getting value: " << ex->what() << std::endl;
+  }
+
+  // Try to get a value that is in the file:
+  {
+    const Glib::ustring value = keyfile.get_value("First Group", "Welcome", ex);
+    if (!ex.get())
+      std::cout << "Welcome value=" << value << std::endl;
+    else
+      std::cerr << "Exception while getting value: " << ex->what() << std::endl;
+  }
+
+  // Try to get a list of integers that is in the file:
+  {
+    const std::vector<int> values = keyfile.get_integer_list("Another Group", "Numbers", ex);
+    if (!ex.get())
+    {
+      for(std::vector<int>::const_iterator p = values.begin(); p != values.end(); ++p)
+        std::cout << "Number list value: item=" << *p << std::endl;
+    }
+    else
+      std::cerr << "Exception while getting list value: " << ex->what() << std::endl;
+  }
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
 
   return 0;
 }

Modified: trunk/examples/regex/main.cc
==============================================================================
--- trunk/examples/regex/main.cc	(original)
+++ trunk/examples/regex/main.cc	Mon Mar 23 11:58:58 2009
@@ -17,31 +17,35 @@
 
 #include <glibmm.h>
 #include <iostream>
+#include <iomanip>
 
-Glib::ustring bool_text (bool val)
-{
-	return val ? "true" : "false";
-}
-
-int main(int argc, char** argv)
+int main(int, char**)
 {
   Glib::init();
-  
-  /* Reusing one regex pattern: */ 
-  Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create ("(a)?(b)");
+
+  /* Reusing one regex pattern: */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("(a)?(b)");
+#else
+  std::auto_ptr<Glib::Error> error;
+  Glib::RefPtr<Glib::Regex> regex = Glib::Regex::create("(a)?(b)",
+                                                        Glib::RegexCompileFlags(),
+                                                        Glib::RegexMatchFlags(),
+                                                        error);
+#endif
   std::cout << "Pattern=" << regex->get_pattern() 
      << ", with string=abcd, result=" 
-     << bool_text( regex->match("abcd") )
+     << std::boolalpha << regex->match("abcd")
      << std::endl;
   std::cout << "Pattern=" << regex->get_pattern()
      << ", with string=1234, result=" 
-     << bool_text( regex->match("1234") )
+     << std::boolalpha << regex->match("1234")
      << std::endl;
   std::cout << std::endl;
 
   /* Using the static function without a regex instance: */
   std::cout << "Pattern=b* with string=abcd, result=" 
-    << bool_text( Glib::Regex::match_simple("b*", "abcd") )
+    << std::boolalpha << Glib::Regex::match_simple("b*", "abcd")
     << std::endl;
 
   return 0;

Modified: trunk/gio/src/appinfo.ccg
==============================================================================
--- trunk/gio/src/appinfo.ccg	(original)
+++ trunk/gio/src/appinfo.ccg	Mon Mar 23 11:58:58 2009
@@ -44,11 +44,10 @@
                                                  static_cast<GAppInfoCreateFlags>(flags),
                                                  &gerror);
 
-#ifdef GLIBMM_EXCEPTIONS_ENABLED
   if (gerror)
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
     ::Glib::Error::throw_exception(gerror);
 #else
-  if (error)
     error = ::Glib::Error::throw_exception(gerror);
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 

Modified: trunk/gio/src/file.ccg
==============================================================================
--- trunk/gio/src/file.ccg	(original)
+++ trunk/gio/src/file.ccg	Mon Mar 23 11:58:58 2009
@@ -2061,7 +2061,7 @@
 {
   GError* gerror = 0;
   gchar* cetag_out = 0;
-  bool retvalue = g_file_load_contents(gobj(), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &contents, &(length), &cetag_out, &(gerror));
+  bool retvalue = g_file_load_contents(gobj(), Glib::unwrap(cancellable), &contents, &(length), &cetag_out, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);

Modified: trunk/gio/src/file.hg
==============================================================================
--- trunk/gio/src/file.hg	(original)
+++ trunk/gio/src/file.hg	Mon Mar 23 11:58:58 2009
@@ -295,7 +295,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::RefPtr<FileOutputStream> create_file(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags = FILE_CREATE_NONE);
 #else
-  Glib::RefPtr<FileOutputStream> create_file(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags = FILE_CREATE_NONE, std::auto_ptr<Glib::Error>& error);
+  Glib::RefPtr<FileOutputStream> create_file(const Glib::RefPtr<Cancellable>& cancellable, FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 
   /** Creates a new file and returns an output stream for writing to it.
@@ -322,7 +322,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::RefPtr<FileOutputStream> create_file(FileCreateFlags flags = FILE_CREATE_NONE);
 #else
-  Glib::RefPtr<FileOutputStream> create_file(FileCreateFlags flags = FILE_CREATE_NONE, std::auto_ptr<Glib::Error>& error);
+  Glib::RefPtr<FileOutputStream> create_file(FileCreateFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif //GLIBMM_EXCEPTIONS_ENABLED
   _IGNORE(g_file_create)
 
@@ -994,7 +994,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool copy(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE);
 #else
-  bool copy(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE, std::auto_ptr<Glib::Error>& error);
+  bool copy(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif
 
   //TODO: Documentation.
@@ -1103,7 +1103,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool move(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE);
 #else
-  bool move(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE, std::auto_ptr<Glib::Error>& error);
+  bool move(const Glib::RefPtr<File>& destination, const SlotFileProgress& slot, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif
 
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
@@ -1576,7 +1576,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool copy_attributes(const Glib::RefPtr<File>& destination, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE);
 #else
-  bool copy_attributes(const Glib::RefPtr<File>& destination, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags = FILE_COPY_NONE, std::auto_ptr<Glib::Error>& error);
+  bool copy_attributes(const Glib::RefPtr<File>& destination, const Glib::RefPtr<Cancellable>& cancellable, FileCopyFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif
 
   /** Copies the file attributes from @a source to @a destination. 
@@ -1594,7 +1594,7 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool copy_attributes(const Glib::RefPtr<File>& destination, FileCopyFlags flags = FILE_COPY_NONE);
 #else
-  bool copy_attributes(const Glib::RefPtr<File>& destination, FileCopyFlags flags = FILE_COPY_NONE, std::auto_ptr<Glib::Error>& error);
+  bool copy_attributes(const Glib::RefPtr<File>& destination, FileCopyFlags flags, std::auto_ptr<Glib::Error>& error);
 #endif
   _IGNORE(g_file_copy_attributes)
  
@@ -1726,8 +1726,11 @@
    * @param length A location to place the length of the contents of the file.
    * @param etag_out A location to place the current entity tag for the file.
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool load_contents(const Glib::RefPtr<Cancellable>& cancellable, char*& contents, gsize& length, std::string& etag_out);
-
+#else
+  bool load_contents(const Glib::RefPtr<Cancellable>& cancellable, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error);
+#endif
   //TODO: Something better than char*& for contents?
   /** Loads the content of the file into memory, returning the size of the data. 
    * The data is always zero terminated, but this is not included in the resultant @a length.
@@ -1736,9 +1739,12 @@
    * @param length A location to place the length of the contents of the file.
    * @param etag_out A location to place the current entity tag for the file.
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   bool load_contents(char*& contents, gsize& length, std::string& etag_out);
-
-
+#else
+  bool load_contents(char*& contents, gsize& length, std::string& etag_out,
+                     std::auto_ptr<Glib::Error>& error);
+#endif
   _IGNORE(g_file_load_contents)
 
   /** Starts an asynchronous load of the file's contents.

Modified: trunk/gio/src/outputstream.ccg
==============================================================================
--- trunk/gio/src/outputstream.ccg	(original)
+++ trunk/gio/src/outputstream.ccg	Mon Mar 23 11:58:58 2009
@@ -53,7 +53,7 @@
                               buffer,
                               count,
                               io_priority,
-                              NULL,
+                              0,
                               &SignalProxy_async_callback,
                               slot_copy);
 }
@@ -87,7 +87,7 @@
                                source->gobj(),
                                static_cast<GOutputStreamSpliceFlags>(flags),
                                io_priority,
-                               NULL,
+                               0,
                                &SignalProxy_async_callback,
                                slot_copy);
 }
@@ -102,7 +102,7 @@
 
   g_output_stream_flush_async(gobj(),
                               io_priority,
-                              const_cast<GCancellable*>(Glib::unwrap(cancellable)),
+                              Glib::unwrap(cancellable),
                               &SignalProxy_async_callback,
                               slot_copy);
 }
@@ -117,7 +117,7 @@
 
   g_output_stream_flush_async(gobj(),
                               io_priority,
-                              NULL,
+                              0,
                               &SignalProxy_async_callback,
                               slot_copy);
 }
@@ -132,7 +132,7 @@
 
   g_output_stream_close_async(gobj(),
                               io_priority,
-                              const_cast<GCancellable*>(Glib::unwrap(cancellable)),
+                              Glib::unwrap(cancellable),
                               &SignalProxy_async_callback,
                               slot_copy);
 }
@@ -147,7 +147,7 @@
 
   g_output_stream_close_async(gobj(),
                               io_priority,
-                              NULL,
+                              0,
                               &SignalProxy_async_callback,
                               slot_copy);
 }
@@ -160,7 +160,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gssize retvalue = g_output_stream_write(gobj(), buffer, count, NULL, &(gerror));
+  gssize retvalue = g_output_stream_write(gobj(), buffer, count, 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -175,11 +175,11 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
 gssize OutputStream::write(const std::string& buffer, const Glib::RefPtr<Cancellable>& cancellable)
 #else
-gssize OutputStream::write(const std::string&, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
+gssize OutputStream::write(const std::string& buffer, const Glib::RefPtr<Cancellable>& cancellable, std::auto_ptr<Glib::Error>& error)
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gssize retvalue = g_output_stream_write(gobj(), buffer.c_str(), buffer.size(), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror));
+  gssize retvalue = g_output_stream_write(gobj(), buffer.data(), buffer.size(), Glib::unwrap(cancellable), &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -194,11 +194,11 @@
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
 gssize OutputStream::write(const std::string& buffer)
 #else
-gssize OutputStream::write(const std::string&, std::auto_ptr<Glib::Error>& error)
+gssize OutputStream::write(const std::string& buffer, std::auto_ptr<Glib::Error>& error)
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gssize retvalue = g_output_stream_write(gobj(), buffer.c_str(), buffer.size(), NULL, &(gerror));
+  gssize retvalue = g_output_stream_write(gobj(), buffer.data(), buffer.size(), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -217,7 +217,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  bool retvalue = g_output_stream_write_all(gobj(), buffer, count, &(bytes_written), NULL, &(gerror));
+  bool retvalue = g_output_stream_write_all(gobj(), buffer, count, &(bytes_written), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -236,7 +236,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  bool retvalue = g_output_stream_write_all(gobj(), buffer.c_str(), buffer.size(), &(bytes_written), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror));
+  bool retvalue = g_output_stream_write_all(gobj(), buffer.data(), buffer.size(), &(bytes_written), Glib::unwrap(cancellable), &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -255,7 +255,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  bool retvalue = g_output_stream_write_all(gobj(), buffer.c_str(), buffer.size(), &(bytes_written), NULL, &(gerror));
+  bool retvalue = g_output_stream_write_all(gobj(), buffer.data(), buffer.size(), &(bytes_written), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -274,7 +274,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gssize retvalue = g_output_stream_splice(gobj(), const_cast<GInputStream*>(Glib::unwrap(source)), ((GOutputStreamSpliceFlags)(flags)), const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror));
+  gssize retvalue = g_output_stream_splice(gobj(), Glib::unwrap(source), ((GOutputStreamSpliceFlags)(flags)), Glib::unwrap(cancellable), &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -293,7 +293,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gssize retvalue = g_output_stream_splice(gobj(), const_cast<GInputStream*>(Glib::unwrap(source)), ((GOutputStreamSpliceFlags)(flags)), NULL, &(gerror));
+  gssize retvalue = g_output_stream_splice(gobj(), Glib::unwrap(source), ((GOutputStreamSpliceFlags)(flags)), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -312,7 +312,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  bool retvalue = g_output_stream_flush(gobj(), NULL, &(gerror));
+  bool retvalue = g_output_stream_flush(gobj(), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
@@ -331,7 +331,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  bool retvalue = g_output_stream_close(gobj(), NULL, &(gerror));
+  bool retvalue = g_output_stream_close(gobj(), 0, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
     ::Glib::Error::throw_exception(gerror);

Modified: trunk/glib/src/keyfile.ccg
==============================================================================
--- trunk/glib/src/keyfile.ccg	(original)
+++ trunk/glib/src/keyfile.ccg	Mon Mar 23 11:58:58 2009
@@ -167,87 +167,96 @@
   g_key_file_set_double(gobj(), 0, key.c_str(), value); 
 }
 
-// TODO: alternative code path with exceptions disabled
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+# define GLIBMM_ERROR_ARG
+# define GLIBMM_THROW(err) if (err) Glib::Error::throw_exception(err)
+#else
+# define GLIBMM_ERROR_ARG , std::auto_ptr<Glib::Error>& error
+# define GLIBMM_THROW(err) if (err) error = Glib::Error::throw_exception(err)
+#endif
+
 Glib::ArrayHandle<Glib::ustring> KeyFile::get_string_list(const Glib::ustring& group_name,
-                                                          const Glib::ustring& key) const
+                                                          const Glib::ustring& key
+                                                          GLIBMM_ERROR_ARG) const
 {
-  gsize length  = 0;
-  GError* error = 0;
+  gsize   length = 0;
+  GError* gerror = 0;
 
   char** const array = g_key_file_get_string_list(
       const_cast<GKeyFile*>(gobj()),
       (group_name.empty()) ? 0 : group_name.c_str(),
-      key.c_str(), &length, &error);
+      key.c_str(), &length, &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 
   return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP);
 }
 
-// TODO: alternative code path with exceptions disabled
 Glib::ArrayHandle<Glib::ustring> KeyFile::get_locale_string_list(const Glib::ustring& group_name,
                                                                  const Glib::ustring& key,
-                                                                 const Glib::ustring& locale) const
+                                                                 const Glib::ustring& locale
+                                                                 GLIBMM_ERROR_ARG) const
 {
-  gsize length  = 0;
-  GError* error = 0;
+  gsize   length = 0;
+  GError* gerror = 0;
 
   char** const array = g_key_file_get_locale_string_list(
       const_cast<GKeyFile*>(gobj()),
       (group_name.empty()) ? 0 : group_name.c_str(),
-      key.c_str(), locale.c_str(), &length, &error);
+      key.c_str(), locale.c_str(), &length, &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 
   return Glib::ArrayHandle<Glib::ustring>(array, length, Glib::OWNERSHIP_DEEP);
 }
 
-// TODO: alternative code path with exceptions disabled
 Glib::ArrayHandle<bool> KeyFile::get_boolean_list(const Glib::ustring& group_name,
-                                                  const Glib::ustring& key) const
+                                                  const Glib::ustring& key
+                                                  GLIBMM_ERROR_ARG) const
 {
-  gsize length  = 0;
-  GError* error = 0;
+  gsize   length = 0;
+  GError* gerror = 0;
 
   gboolean *const array = g_key_file_get_boolean_list(
       const_cast<GKeyFile*>(gobj()),
       (group_name.empty()) ? 0 : group_name.c_str(),
-      key.c_str(), &length, &error);
+      key.c_str(), &length, &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 
   return Glib::ArrayHandle<bool>(array, length, Glib::OWNERSHIP_SHALLOW);
 }
 
 Glib::ArrayHandle<int> KeyFile::get_integer_list(const Glib::ustring& group_name,
-                                                 const Glib::ustring& key) const
+                                                 const Glib::ustring& key
+                                                 GLIBMM_ERROR_ARG) const
 {
-  gsize length  = 0;
-  GError* error = 0;
+  gsize   length = 0;
+  GError* gerror = 0;
 
   int *const array = g_key_file_get_integer_list(
       const_cast<GKeyFile*>(gobj()),
       (group_name.empty()) ? 0 : group_name.c_str(),
-      key.c_str(), &length, &error);
+      key.c_str(), &length, &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 
   return Glib::ArrayHandle<int>(array, length, Glib::OWNERSHIP_SHALLOW);
 }
 
-Glib::ArrayHandle<double> KeyFile::get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const
-{
-  gdouble* integer_list   = 0;
-  gsize length_of_list = 0; 
-  GError* error        = 0;
-  integer_list = g_key_file_get_double_list(const_cast<GKeyFile*>(gobj()), group_name.c_str(), key.c_str(), &length_of_list, &error);
-  if(error)
-    Glib::Error::throw_exception(error);
-  return Glib::ArrayHandle<double>(integer_list, length_of_list, Glib::OWNERSHIP_DEEP);
+Glib::ArrayHandle<double> KeyFile::get_double_list(const Glib::ustring& group_name,
+                                                   const Glib::ustring& key
+                                                   GLIBMM_ERROR_ARG) const
+{
+  gsize   length = 0;
+  GError* gerror = 0;
+
+  double *const array = g_key_file_get_double_list(const_cast<GKeyFile*>(gobj()),
+                                                   group_name.c_str(), key.c_str(),
+                                                   &length, &gerror);
+  GLIBMM_THROW(gerror);
+
+  return Glib::ArrayHandle<double>(array, length, Glib::OWNERSHIP_SHALLOW);
 }
 
 void KeyFile::set_string_list(const Glib::ustring& group_name, const Glib::ustring& key,
@@ -286,45 +295,46 @@
                               key.c_str(), const_cast<gboolean*>(list.data()), list.size());
 }
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
 Glib::ustring KeyFile::get_comment() const
+#else
+Glib::ustring KeyFile::get_comment(std::auto_ptr<Glib::Error>& error) const
+#endif
 {
-  GError* error = 0;
-  char *const str = g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), 0, 0, &error);
+  GError* gerror = 0;
+  char *const str = g_key_file_get_comment(const_cast<GKeyFile*>(gobj()), 0, 0, &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 
   return Glib::convert_return_gchar_ptr_to_ustring(str);
 }
 
-Glib::ustring KeyFile::get_comment(const Glib::ustring& group_name) const
+Glib::ustring KeyFile::get_comment(const Glib::ustring& group_name GLIBMM_ERROR_ARG) const
 {
-  GError* error = 0;
+  GError* gerror = 0;
   char *const str = g_key_file_get_comment(const_cast<GKeyFile*>(gobj()),
                                            (group_name.empty()) ? 0 : group_name.c_str(),
-                                           0, &error);
-  if(error)
-    Glib::Error::throw_exception(error);
+                                           0, &gerror);
+  GLIBMM_THROW(gerror);
 
   return Glib::convert_return_gchar_ptr_to_ustring(str);
 }
 
-void KeyFile::set_comment(const Glib::ustring& comment)
+void KeyFile::set_comment(const Glib::ustring& comment GLIBMM_ERROR_ARG)
 {
-  GError* error = 0;
-  g_key_file_set_comment(gobj(), 0, 0, comment.c_str(), &error);
+  GError* gerror = 0;
+  g_key_file_set_comment(gobj(), 0, 0, comment.c_str(), &gerror);
 
-  if(error)
-    Glib::Error::throw_exception(error);
+  GLIBMM_THROW(gerror);
 }
 
-void KeyFile::set_comment(const Glib::ustring& group_name, const Glib::ustring& comment)
+void KeyFile::set_comment(const Glib::ustring& group_name, const Glib::ustring& comment
+                          GLIBMM_ERROR_ARG)
 {
-  GError* error = 0;
+  GError* gerror = 0;
   g_key_file_set_comment(gobj(), (group_name.empty()) ? 0 : group_name.c_str(),
-                         0, comment.c_str(), &error);
-  if(error)
-    Glib::Error::throw_exception(error);
+                         0, comment.c_str(), &gerror);
+  GLIBMM_THROW(gerror);
 }
 
 } // namespace Glib

Modified: trunk/glib/src/keyfile.hg
==============================================================================
--- trunk/glib/src/keyfile.hg	(original)
+++ trunk/glib/src/keyfile.hg	Mon Mar 23 11:58:58 2009
@@ -194,8 +194,11 @@
    * @return The value of @a key as an integer
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   int get_integer(const Glib::ustring& key) const;
-
+#else
+  int get_integer(const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const;
+#endif
   _WRAP_METHOD(int get_integer(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_integer, errthrow)
 
   /** Gets the value in the first group, under @a key, interpreting it as
@@ -206,8 +209,11 @@
    *
    * @newin2p14
    */
-   double get_double(const Glib::ustring& key) const;
-
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  double get_double(const Glib::ustring& key) const;
+#else
+  double get_double(const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const;
+#endif
   _WRAP_METHOD(double get_double(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_double, errthrow)
 
   _WRAP_METHOD(void set_double(const Glib::ustring& group_name, const Glib::ustring& key, double value), g_key_file_set_double)
@@ -227,7 +233,11 @@
    * @return A list containing the values requested
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<Glib::ustring> get_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
+#else
+  Glib::ArrayHandle<Glib::ustring> get_string_list(const Glib::ustring& group_name, const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const;
+#endif
   _IGNORE(g_key_file_get_string_list)
 	
   /** Returns the values associated with @a key under @a group_name
@@ -237,8 +247,12 @@
    * @return A list containing the values requested
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
-	
+#else
+  Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, std::auto_ptr<Glib::Error>& error) const;
+#endif
+
   /** Returns the values associated with @a key under @a group_name
    * translated into @a locale, if available.
    * @param group_name The name of a group
@@ -247,7 +261,11 @@
    * @return A list containing the values requested
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale) const;
+#else
+  Glib::ArrayHandle<Glib::ustring> get_locale_string_list(const Glib::ustring& group_name, const Glib::ustring& key, const Glib::ustring& locale, std::auto_ptr<Glib::Error>& error) const;
+#endif
   _IGNORE(g_key_file_get_locale_string_list)
 
   /** Returns the values associated with @a key under @a group_name
@@ -256,7 +274,12 @@
    * @return A list of booleans
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<bool> get_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
+#else
+  Glib::ArrayHandle<bool> get_boolean_list(const Glib::ustring& group_name, const Glib::ustring& key,
+                                           std::auto_ptr<Glib::Error>& error) const;
+#endif
   _IGNORE(g_key_file_get_boolean_list)
 
   /** Returns the values associated with @a key under @a group_name
@@ -265,7 +288,12 @@
    * @return A list of integers
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<int> get_integer_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
+#else
+  Glib::ArrayHandle<int> get_integer_list(const Glib::ustring& group_name, const Glib::ustring& key,
+                                          std::auto_ptr<Glib::Error>& error) const;
+#endif
   _IGNORE(g_key_file_get_integer_list)
 
   /** Returns the values associated with @a key under @a group_name
@@ -274,19 +302,32 @@
    * @return A list of doubles
    * @throws Glib::KeyFileError
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ArrayHandle<double> get_double_list(const Glib::ustring& group_name, const Glib::ustring& key) const;
+#else
+  Glib::ArrayHandle<double> get_double_list(const Glib::ustring& group_name, const Glib::ustring& key,
+                                            std::auto_ptr<Glib::Error>& error) const;
+#endif
   _IGNORE(g_key_file_get_double_list)
 
   /** Get comment from top of file
    * @return The comment
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ustring get_comment() const;
+#else
+  Glib::ustring get_comment(std::auto_ptr<Glib::Error>& error) const;
+#endif
 
   /** Get comment from above a group
    * @param group_name The group
    * @return The comment
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   Glib::ustring get_comment(const Glib::ustring& group_name) const;
+#else
+  Glib::ustring get_comment(const Glib::ustring& group_name, std::auto_ptr<Glib::Error>& error) const;
+#endif
 
   _WRAP_METHOD(Glib::ustring get_comment(const Glib::ustring& group_name, const Glib::ustring& key) const, g_key_file_get_comment, errthrow)
 	
@@ -351,13 +392,22 @@
   /** Places @a comment at the start of the file, before the first group.
    * @param comment The Comment
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   void set_comment(const Glib::ustring& comment);
+#else
+  void set_comment(const Glib::ustring& comment, std::auto_ptr<Glib::Error>& error);
+#endif
 
   /** Places @a comment above @a group_name.
    * @param group_name The Group the comment should be above
    * @param comment The comment
    */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   void set_comment(const Glib::ustring& group_name, const Glib::ustring& comment);
+#else
+  void set_comment(const Glib::ustring& group_name, const Glib::ustring& comment,
+                   std::auto_ptr<Glib::Error>& error);
+#endif
 
   /** Places a comment above @a key from @a group_name.
    * @param key Key comment should be above

Modified: trunk/tests/giomm_ioerror/main.cc
==============================================================================
--- trunk/tests/giomm_ioerror/main.cc	(original)
+++ trunk/tests/giomm_ioerror/main.cc	Mon Mar 23 11:58:58 2009
@@ -19,6 +19,7 @@
   Glib::init();
   Gio::init();
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
     Glib::RefPtr<Gio::File> file = Gio::File::create_for_path("/etc/fstab");
@@ -30,14 +31,13 @@
       std::cerr << "Gio::File::read() returned an empty RefPtr." << std::endl;
 
     gchar buffer[1000]; //TODO: This is unpleasant.
-    memset(buffer, 0, 1000);
-    const gsize bytes_read = stream->read(buffer, 1000);
-    
+    memset(buffer, 0, sizeof buffer);
+    const gsize bytes_read = stream->read(buffer, sizeof buffer - 1);
+
     if(bytes_read)
       std::cout << "File contents read: " << buffer << std::endl;
     else
       std::cerr << "Gio::InputStream::read() read 0 bytes." << std::endl;
-
   }
   catch(const Gio::Error& ex)
   {
@@ -55,7 +55,37 @@
   {
     std::cerr << "Exception caught: " << ex.what() << std::endl; 
   }
+#else /* !GLIBMM_EXCEPTIONS_ENABLED */
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_path("/home/murrayc/test.txt");
+  if(!file)
+    std::cerr << "Gio::File::create_for_path() returned an empty RefPtr." << std::endl;
+
+  std::auto_ptr<Glib::Error> error;
+
+  Glib::RefPtr<Gio::FileInputStream> stream = file->read(error);
+  if(!stream)
+    std::cerr << "Gio::File::read() returned an empty RefPtr." << std::endl;
+  if(error.get())
+  {
+    std::cerr << "Exception caught: " << error->what() << std::endl;
+    return 1;
+  }
 
+  gchar buffer[1000]; //TODO: This is unpleasant.
+  memset(buffer, 0, sizeof buffer);
+  const gsize bytes_read = stream->read(buffer, sizeof buffer - 1, error);
+
+  if(bytes_read)
+    std::cout << "File contents read: " << buffer << std::endl;
+  else
+    std::cerr << "Gio::InputStream::read() read 0 bytes." << std::endl;
+
+  if(error.get())
+  {
+    std::cerr << "Exception caught: " << error->what() << std::endl;
+    return 1;
+  }
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
 
   return 0;
 }

Modified: trunk/tests/giomm_simple/main.cc
==============================================================================
--- trunk/tests/giomm_simple/main.cc	(original)
+++ trunk/tests/giomm_simple/main.cc	Mon Mar 23 11:58:58 2009
@@ -2,11 +2,12 @@
 #include <iostream>
 #include <string.h>
 
-int main(int argc, char** argv)
+int main(int, char**)
 {
   Glib::init();
   Gio::init();
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
   try
   {
     Glib::RefPtr<Gio::File> file = Gio::File::create_for_path("/etc/fstab");
@@ -18,20 +19,48 @@
       std::cerr << "Gio::File::read() returned an empty RefPtr." << std::endl;
 
     gchar buffer[1000]; //TODO: This is unpleasant.
-    memset(buffer, 0, 1000);
-    const gsize bytes_read = stream->read(buffer, 1000);
-    
+    memset(buffer, 0, sizeof buffer);
+    const gsize bytes_read = stream->read(buffer, sizeof buffer - 1);
+
     if(bytes_read)
       std::cout << "File contents read: " << buffer << std::endl;
     else
       std::cerr << "Gio::InputStream::read() read 0 bytes." << std::endl;
-
   }
   catch(const Glib::Exception& ex)
   {
     std::cerr << "Exception caught: " << ex.what() << std::endl; 
   }
+#else /* !GLIBMM_EXCEPTIONS_ENABLED */
+  Glib::RefPtr<Gio::File> file = Gio::File::create_for_path("/home/murrayc/test.txt");
+  if(!file)
+    std::cerr << "Gio::File::create_for_path() returned an empty RefPtr." << std::endl;
+
+  std::auto_ptr<Glib::Error> error;
+
+  Glib::RefPtr<Gio::FileInputStream> stream = file->read(error);
+  if(!stream)
+    std::cerr << "Gio::File::read() returned an empty RefPtr." << std::endl;
+  if(error.get())
+  {
+    std::cerr << "Exception caught: " << error->what() << std::endl;
+    return 1;
+  }
+  gchar buffer[1000]; //TODO: This is unpleasant.
+  memset(buffer, 0, sizeof buffer);
+  const gsize bytes_read = stream->read(buffer, sizeof buffer - 1, error);
+
+  if(bytes_read)
+    std::cout << "File contents read: " << buffer << std::endl;
+  else
+    std::cerr << "Gio::InputStream::read() read 0 bytes." << std::endl;
 
+  if(error.get())
+  {
+    std::cerr << "Exception caught: " << error->what() << std::endl;
+    return 1;
+  }
+#endif /* !GLIBMM_EXCEPTIONS_ENABLED */
 
   return 0;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]