[gtkmm] Pixbuf: add const version of save() and friends



commit e8372b895442470ba013b21fc1b7ac2cecd50a64
Author: Mark Vender <markv743 yahoo co uk>
Date:   Sun Jul 1 16:33:20 2012 +0200

    Pixbuf: add const version of save() and friends
    
    * gdk/src/pixbuf.[hg|ccg]: save() and save_to_buffer() don't have any user-
    visible effects on the pixbuf being saved, thus they should be const.
    Add const versions, deprecate the non-const ones. Bug #678886.

 ChangeLog          |    8 +++++++
 gdk/src/pixbuf.ccg |   55 ++++++++++++++++++++++++++++++++++++++++++-------
 gdk/src/pixbuf.hg  |   58 +++++++++++++++++++++++++++++++++++++++++++++++----
 3 files changed, 108 insertions(+), 13 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 4df9f6b..17305b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-07-01  Mark Vender  <markv743 yahoo co uk>
+
+	Pixbuf: add const version of save() and friends
+
+	* gdk/src/pixbuf.[hg|ccg]: save() and save_to_buffer() don't have any user-
+	visible effects on the pixbuf being saved, thus they should be const.
+	Add const versions, deprecate the non-const ones. Bug #678886.
+
 2012-06-18  Kjell Ahlstedt  <kjell ahlstedt bredband net>
 
 	AppChooserDialog: Fix property name in constructors.
diff --git a/gdk/src/pixbuf.ccg b/gdk/src/pixbuf.ccg
index be1cd16..0d74ad8 100644
--- a/gdk/src/pixbuf.ccg
+++ b/gdk/src/pixbuf.ccg
@@ -110,24 +110,32 @@ Glib::RefPtr<Pixbuf> Pixbuf::create_from_stream_at_scale(const Glib::RefPtr<Gio:
   return retvalue;
 }
 
-void Pixbuf::save(const std::string& filename, const Glib::ustring& type)
+void Pixbuf::save(const std::string& filename, const Glib::ustring& type) const
 {
   GError* gerror = 0;
-  gdk_pixbuf_savev(gobj(), filename.c_str(), type.c_str(), 0, 0, &gerror);
+  gdk_pixbuf_savev(const_cast<GdkPixbuf*>(gobj()),
+                   filename.c_str(), type.c_str(), 0, 0, &gerror);
 
   if(gerror)
     ::Glib::Error::throw_exception(gerror);
 }
 
+#ifndef GDKMM_DISABLE_DEPRECATED
+
+void Pixbuf::save(const std::string& filename, const Glib::ustring& type)
+{
+  const_cast<const Pixbuf*>(this)->save(filename, type);
+}
+#endif // GDKMM_DISABLE_DEPRECATED
 
 void Pixbuf::save(const std::string& filename, const Glib::ustring& type,
                   const std::vector<Glib::ustring>& option_keys,
-                  const std::vector<Glib::ustring>& option_values)
+                  const std::vector<Glib::ustring>& option_values) const
 {
   GError* gerror = 0;
 
   gdk_pixbuf_savev(
-      gobj(), filename.c_str(), type.c_str(),
+      const_cast<GdkPixbuf*>(gobj()), filename.c_str(), type.c_str(),
       const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array(option_keys).data ()),
       const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array(option_values).data ()),
       &gerror);
@@ -136,14 +144,23 @@ void Pixbuf::save(const std::string& filename, const Glib::ustring& type,
     ::Glib::Error::throw_exception(gerror);
 }
 
+#ifndef GDKMM_DISABLE_DEPRECATED
+
+void Pixbuf::save(const std::string& filename, const Glib::ustring& type,
+                  const std::vector<Glib::ustring>& option_keys,
+                  const std::vector<Glib::ustring>& option_values)
+{
+  const_cast<const Pixbuf*>(this)->save(filename, type, option_keys, option_values);
+}
+#endif // GDKMM_DISABLE_DEPRECATED
 
 void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
-                            const Glib::ustring& type)
+                            const Glib::ustring& type) const
 {
   GError* gerror = 0;
 
   gdk_pixbuf_save_to_buffer(
-      gobj(), &buffer, &buffer_size,
+      const_cast<GdkPixbuf*>(gobj()), &buffer, &buffer_size,
       type.c_str(),
       &gerror, (void*)0);
 
@@ -151,15 +168,25 @@ void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
     ::Glib::Error::throw_exception(gerror);
 }
 
+#ifndef GDKMM_DISABLE_DEPRECATED
+
+void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
+                            const Glib::ustring& type)
+{
+  const_cast<const Pixbuf*>(this)->save_to_buffer(buffer, buffer_size, type);
+}
+#endif // GDKMM_DISABLE_DEPRECATED
+
 void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
                             const Glib::ustring& type,
                             const std::vector<Glib::ustring>& option_keys,
-                            const std::vector<Glib::ustring>& option_values)
+                            const std::vector<Glib::ustring>& option_values) const
 {
   GError* gerror = 0;
 
   gdk_pixbuf_save_to_bufferv(
-      gobj(), &buffer, &buffer_size,
+      const_cast<GdkPixbuf*>(gobj()),
+      &buffer, &buffer_size,
       type.c_str(),
       const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array(option_keys).data ()),
       const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array(option_values).data ()),
@@ -169,6 +196,18 @@ void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
     ::Glib::Error::throw_exception(gerror);
 }
 
+#ifndef GDKMM_DISABLE_DEPRECATED
+
+void Pixbuf::save_to_buffer(gchar*& buffer, gsize& buffer_size,
+                            const Glib::ustring& type,
+                            const std::vector<Glib::ustring>& option_keys,
+                            const std::vector<Glib::ustring>& option_values)
+{
+  const_cast<const Pixbuf*>(this)->save_to_buffer(buffer, buffer_size, type,
+                                                  option_keys, option_values);
+}
+#endif // GDKMM_DISABLE_DEPRECATED
+
 std::vector<PixbufFormat> Pixbuf::get_formats()
 {
   return Glib::SListHandler<PixbufFormat, PixbufFormatTraits>::slist_to_vector(gdk_pixbuf_get_formats(), Glib::OWNERSHIP_SHALLOW);
diff --git a/gdk/src/pixbuf.hg b/gdk/src/pixbuf.hg
index f0465cc..c9059aa 100644
--- a/gdk/src/pixbuf.hg
+++ b/gdk/src/pixbuf.hg
@@ -268,9 +268,11 @@ public:
   _WRAP_METHOD(void fill(guint32 pixel), gdk_pixbuf_fill)
 
   /** Saves pixbuf to a file in format @a type.
-   * By default, "jpeg", "png", "ico" and "bmp" are possible file formats to save in, but more formats may be installed.
-   * The list of all writable formats can be determined by using get_formats() with
-   * is_writable().
+   * By default, "jpeg", "png", "ico" and "bmp" are possible file formats to
+   * save in, but more formats may be installed. The list of all writable
+   * formats can be determined by using get_formats() with is_writable().
+   *
+   * @newin{3,6}
    *
    * @param filename The path of the file to be created.
    * @param type The file type.
@@ -278,7 +280,16 @@ public:
    * @throw Glib::FileError
    * @throw Gdk::PixbufError
    */
+  void save(const std::string& filename, const Glib::ustring& type) const;
+
+#ifndef GDKMM_DISABLE_DEPRECATED
+  /**
+   * Same as the const version.
+   * @deprecated 3.6: Use the const version instead.
+   */
   void save(const std::string& filename, const Glib::ustring& type);
+#endif // GDKMM_DISABLE_DEPRECATED
+
   _IGNORE(gdk_pixbuf_save)
 
   /** Saves pixbuf to a file in format @a type.
@@ -295,6 +306,8 @@ public:
    * saved in depth 16, 24, or 32, by using the "depth" parameter. When the ICO saver is given "x_hot" and "y_hot"
    * parameters, it produces a CUR instead of an ICO.
    *
+   * @newin{3,6}
+   *
    * @param filename The path of the file to be created.
    * @param type The file type.
    * @param option_keys
@@ -305,7 +318,17 @@ public:
    */
   void save(const std::string& filename, const Glib::ustring& type,
             const std::vector<Glib::ustring>& option_keys,
+            const std::vector<Glib::ustring>& option_values) const;
+
+#ifndef GDKMM_DISABLE_DEPRECATED
+  /**
+   * Same as the const version.
+   * @deprecated 3.6: Use the const version instead.
+   */
+  void save(const std::string& filename, const Glib::ustring& type,
+            const std::vector<Glib::ustring>& option_keys,
             const std::vector<Glib::ustring>& option_values);
+#endif // GDKMM_DISABLE_DEPRECATED
 
   _IGNORE(gdk_pixbuf_savev)
   
@@ -347,10 +370,12 @@ gboolean gdk_pixbuf_save_to_callbackv   (GdkPixbuf  *pixbuf,
 
 */
 
-  /* Saves the pixbuf to a new buffer in format @a type.
+  /** Saves the pixbuf to a new buffer in format @a type.
    * Note that the buffer is not nul-terminated and may contain embedded nulls.
    * @see save().
    *
+   * @newin{3,6}
+   *
    * @param buffer This will be set to the address of a new buffer.
    * @param size This will be set to the size of the @a buffer.
    * @param type Currently "jpeg", "png", "ico" or "bmp".
@@ -359,12 +384,23 @@ gboolean gdk_pixbuf_save_to_callbackv   (GdkPixbuf  *pixbuf,
    * @throw Gdk::PixbufError
    */
   void save_to_buffer(gchar*& buffer, gsize& buffer_size,
+                      const Glib::ustring& type = "png") const;
+
+#ifndef GDKMM_DISABLE_DEPRECATED
+  /**
+   * Same as the const version.
+   * @deprecated 3.6: Use the const version instead.
+   */
+  void save_to_buffer(gchar*& buffer, gsize& buffer_size,
                       const Glib::ustring& type = "png");
+#endif // GDKMM_DISABLE_DEPRECATED
 
-  /* Saves the pixbuf to a new buffer in format @a type.
+  /** Saves the pixbuf to a new buffer in format @a type.
    * Note that the buffer is not nul-terminated and may contain embedded nulls.
    * @see save().
    *
+   * @newin{3,6}
+   *
    * @param buffer This will be set to the address of a new buffer.
    * @param size This will be set to the size of the @a buffer.
    * @param type Currently "jpeg", "png", "ico" or "bmp".
@@ -375,7 +411,19 @@ gboolean gdk_pixbuf_save_to_callbackv   (GdkPixbuf  *pixbuf,
   void save_to_buffer(gchar*& buffer, gsize& buffer_size,
                       const Glib::ustring& type,
                       const std::vector<Glib::ustring>& option_keys,
+                      const std::vector<Glib::ustring>& option_values) const;
+
+#ifndef GDKMM_DISABLE_DEPRECATED
+  /**
+   * Same as the const version.
+   * @deprecated 3.6: Use the const version instead.
+   */
+  void save_to_buffer(gchar*& buffer, gsize& buffer_size,
+                      const Glib::ustring& type,
+                      const std::vector<Glib::ustring>& option_keys,
                       const std::vector<Glib::ustring>& option_values);
+#endif // GDKMM_DISABLE_DEPRECATED
+
   _IGNORE(gdk_pixbuf_save_to_bufferv, gdk_pixbuf_save_to_buffer)
 
 



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