glibmm r629 - in trunk: . gio/src glib/src



Author: murrayc
Date: Mon Mar  3 20:35:47 2008
New Revision: 629
URL: http://svn.gnome.org/viewvc/glibmm?rev=629&view=rev

Log:
2008-03-03  Murray Cumming  <murrayc murrayc com>

* gio/src/file.ccg:
* gio/src/file.hg: load_contents(), load_contents_finish(), 
load_partial_contents_finish(): Use char*& instead of char** for contents, 
though that is not that great either. Use std::string& instead of char** 
for etag_out. Added method overloads without cancellable.
We might want other method overloads in future. 

Modified:
   trunk/ChangeLog
   trunk/gio/src/file.ccg
   trunk/gio/src/file.hg
   trunk/glib/src/checksum.ccg
   trunk/glib/src/checksum.hg

Modified: trunk/gio/src/file.ccg
==============================================================================
--- trunk/gio/src/file.ccg	(original)
+++ trunk/gio/src/file.ccg	Mon Mar  3 20:35:47 2008
@@ -1293,7 +1293,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gchar* c_etag_new = NULL;
+  gchar* c_etag_new = 0;
   g_file_replace_contents(gobj(), contents, length, etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), &c_etag_new, const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -1316,7 +1316,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gchar* c_etag_new = NULL;
+  gchar* c_etag_new = 0;
   g_file_replace_contents(gobj(), contents, length, etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), &c_etag_new, NULL, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -1339,7 +1339,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gchar* c_etag_new = NULL;
+  gchar* c_etag_new = 0;
   g_file_replace_contents(gobj(), contents.c_str(), contents.size(), etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), &c_etag_new, const_cast<GCancellable*>(Glib::unwrap(cancellable)), &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -1362,7 +1362,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gchar* c_etag_new = NULL;
+  gchar* c_etag_new = 0;
   g_file_replace_contents(gobj(), contents.c_str(), contents.size(), etag.c_str(), static_cast<int>(make_backup), ((GFileCreateFlags)(flags)), &c_etag_new, NULL, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -1481,7 +1481,7 @@
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 {
   GError* gerror = 0;
-  gchar* c_new_etag = NULL;
+  gchar* c_new_etag = 0;
   g_file_replace_contents_finish(gobj(), Glib::unwrap(result), &c_new_etag, &(gerror));
 #ifdef GLIBMM_EXCEPTIONS_ENABLED
   if(gerror)
@@ -2016,4 +2016,92 @@
   return retvalue;
 }
 
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool File::load_contents(const Glib::RefPtr<Cancellable>& cancellable, char*& contents, gsize& length, std::string& etag_out)
+#else
+bool File::load_contents(const Glib::RefPtr<Cancellable>& cancellable, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  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));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  etag_out = Glib::convert_return_gchar_ptr_to_stdstring(cetag_out);
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool File::load_contents(char*& contents, gsize& length, std::string& etag_out)
+#else
+bool File::load_contents(char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  gchar* cetag_out = 0;
+  bool retvalue = g_file_load_contents(gobj(), NULL, &contents, &(length), &cetag_out, &(gerror));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  etag_out = Glib::convert_return_gchar_ptr_to_stdstring(cetag_out);
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool File::load_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out)
+#else
+bool File::load_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  gchar* cetag_out = 0;
+  bool retvalue = g_file_load_contents_finish(gobj(), Glib::unwrap(result), &contents, &(length), &cetag_out, &(gerror));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  etag_out = Glib::convert_return_gchar_ptr_to_stdstring(cetag_out);
+
+  return retvalue;
+}
+
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+bool File::load_partial_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out)
+#else
+bool File::load_partial_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error)
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+{
+  GError* gerror = 0;
+  gchar* cetag_out = 0;
+  bool retvalue = g_file_load_partial_contents_finish(gobj(), Glib::unwrap(result), &contents, &(length), &cetag_out, &(gerror));
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  if(gerror)
+    ::Glib::Error::throw_exception(gerror);
+#else
+  if(gerror)
+    error = ::Glib::Error::throw_exception(gerror);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+
+  etag_out = Glib::convert_return_gchar_ptr_to_stdstring(cetag_out);
+
+  return retvalue;
+}
+
 } // namespace Gio

Modified: trunk/gio/src/file.hg
==============================================================================
--- trunk/gio/src/file.hg	(original)
+++ trunk/gio/src/file.hg	Mon Mar  3 20:35:47 2008
@@ -1639,13 +1639,32 @@
   Glib::RefPtr<AppInfo> query_default_handler(std::auto_ptr<Glib::Error>& error);
 #endif //GLIBMM_EXCEPTIONS_ENABLED
 
-  //TODO: Documentation.
-  //TODO: atm I don't understand what's etag_out:
-  // "a pointer to the current entity tag for the document" - sounds like it
-  // should be kept as char**
-  _WRAP_METHOD(bool load_contents(const Glib::RefPtr<Cancellable>& cancellable, char** contents, gsize& length, char** etag_out),
-               g_file_load_contents,
-               errthrow)
+  //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.
+   * 
+   * The operation can be cancelled by triggering the cancellable object from another thread. 
+   * If the operation was cancelled, a Gio::Error exception with CANCELLED will be returned.
+   *
+   * @param cancellable A cancellable object.
+   * @param contents A location to place the contents of the file. 
+   * @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.
+   */
+  bool load_contents(const Glib::RefPtr<Cancellable>& cancellable, char*& contents, gsize& length, std::string& etag_out);
+
+  //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.
+   *
+   * @param contents A location to place the contents of the file. 
+   * @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.
+   */
+  bool load_contents(char*& contents, gsize& length, std::string& etag_out);
+
+
+  _IGNORE(g_file_load_contents)
 
   /** Starts an asynchronous load of the file's contents.
    * For more details, see load_contents() which is the synchronous version of this call.
@@ -1672,9 +1691,23 @@
   void load_contents_async(const SlotAsyncReady& slot);
   _IGNORE(g_file_load_contents_async)
 
-  _WRAP_METHOD(bool load_contents_finish(const Glib::RefPtr<AsyncResult>& result, char** contents, gsize& length, char** etag_out),
-               g_file_load_contents_finish,
-               errthrow)
+  /** Finishes an asynchronous load of the @a file's contents. 
+   * The contents are placed in @a contents, and @a length is set to the 
+   * size of the @a contents string. If @a etag_out is present, it will be 
+   * set to the new entity tag for the @a file.
+   * @param res A AsyncResult.
+   * @param contents A location to place the contents of the file.
+   * @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.
+   * @return <tt>true</tt> if the load was successful. If <tt>false</tt> and @a error is 
+   * present, it will be set appropriately.
+   */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  bool load_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out);
+#else
+  bool load_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+  _IGNORE(g_file_load_contents_finish)
 
 
   /** A signal handler would be, for instance:
@@ -1713,12 +1746,22 @@
   void load_partial_contents_async(const SlotReadMore& slot_read_more, const SlotAsyncReady& slot_async_ready);
   _IGNORE(g_file_load_partial_contents_async)
 
-  //TODO: atm I don't understand what's etag_out:
-  // "a pointer to the current entity tag for the document" - sounds like it
-  // should be kept as char**
-  _WRAP_METHOD(bool load_partial_contents_finish(const Glib::RefPtr<AsyncResult>& result, char** contents, gsize& length, char** etag_out),
-               g_file_load_partial_contents_finish,
-               errthrow)
+
+  /** Finishes an asynchronous partial load operation that was started
+   * with load_partial_contents_async().
+   * @param res A AsyncResult.
+   * @param contents A location to place the contents of the file.
+   * @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.
+   * @return <tt>true</tt> if the load was successful. If <tt>false</tt> and @a error is 
+   * present, it will be set appropriately.
+   */
+#ifdef GLIBMM_EXCEPTIONS_ENABLED
+  bool load_partial_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out);
+#else
+  bool load_partial_contents_finish(const Glib::RefPtr<AsyncResult>& result, char*& contents, gsize& length, std::string& etag_out, std::auto_ptr<Glib::Error>& error);
+#endif //GLIBMM_EXCEPTIONS_ENABLED
+  _IGNORE(g_file_load_partial_contents_finish)
 
   /** Replaces the contents of the file with @a contents of @a length bytes.
    *  

Modified: trunk/glib/src/checksum.ccg
==============================================================================
--- trunk/glib/src/checksum.ccg	(original)
+++ trunk/glib/src/checksum.ccg	Mon Mar  3 20:35:47 2008
@@ -42,7 +42,7 @@
 
 std::string Checksum::compute_checksum(ChecksumType type, const std::string& data)
 {
-  return Glib::convert_return_gchar_ptr_to_ustring(g_compute_checksum_for_string(((GChecksumType)type), data.c_str(), -1));
+  return Glib::convert_return_gchar_ptr_to_ustring(g_compute_checksum_for_string(((GChecksumType)type), data.c_str(), data.size()));
 }
 
 void Checksum::update(const std::string& data)

Modified: trunk/glib/src/checksum.hg
==============================================================================
--- trunk/glib/src/checksum.hg	(original)
+++ trunk/glib/src/checksum.hg	Mon Mar  3 20:35:47 2008
@@ -33,7 +33,7 @@
  * This is a generic API for computing checksums (or "digests") for a sequence of arbitrary bytes, 
  * using various hashing algorithms like MD5, SHA-1 and SHA-256. Checksums are commonly used in various environments and specifications.
  *
- * glibmm supports incremental checksums by calling g_checksum_update() as long as there's data available and then using get_string() 
+ * glibmm supports incremental checksums by calling update() as long as there's data available and then using get_string() 
  * or get_digest() to compute the checksum and return it either as a string in hexadecimal form, or as a raw sequence of bytes. 
  * To compute the checksum for binary blobs and NULL-terminated strings in one go, use the static compute_checksum() convenience functions().
  *



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