summaryrefslogtreecommitdiff
path: root/glib/glibmm/utility.h
diff options
context:
space:
mode:
authorMurray Cumming <murrayc@murrayc.com>2016-01-18 11:14:02 +0100
committerMurray Cumming <murrayc@murrayc.com>2016-01-18 11:14:38 +0100
commit931fccd08c793f1ed44013663f8a52835a328831 (patch)
tree67b25b475af49f27495b0bee920c3c682133bfcd /glib/glibmm/utility.h
parentc72c8e709888e0bd2bd58bb5d96354d352bd0c5f (diff)
downloadglibmm-931fccd08c793f1ed44013663f8a52835a328831.tar.gz
Replace ScopedPtr with make_unique_ptr_gfree().
Using std::unique_ptr. ScopedPtr is now deprecated. Bug #760223
Diffstat (limited to 'glib/glibmm/utility.h')
-rw-r--r--glib/glibmm/utility.h25
1 files changed, 21 insertions, 4 deletions
diff --git a/glib/glibmm/utility.h b/glib/glibmm/utility.h
index 379b524a..d49947c5 100644
--- a/glib/glibmm/utility.h
+++ b/glib/glibmm/utility.h
@@ -21,6 +21,7 @@
#include <glibmmconfig.h>
#include <glibmm/ustring.h>
#include <glib.h>
+#include <memory> //For std::unique_ptr.
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -57,9 +58,13 @@ namespace Glib
// These are used by gtkmmproc-generated type conversions:
+#ifdef GLIBMM_DISABLE_DEPRECATED
// TODO: Replace this with std::unique_ptr?
-// Helper to deal with memory allocated
-// by GLib functions in an exception-safe manner.
+/** Helper to deal with memory allocated
+ * by GLib functions in an exception-safe manner.
+ *
+ * @deprecated Use UniquePtrGFree instead.
+ */
template <typename T>
class ScopedPtr
{
@@ -75,6 +80,18 @@ public:
T* get() const { return ptr_; }
T** addr() { return &ptr_; }
};
+#endif //GLIBMM_DISABLE_DEPRECATED
+
+/** Helper to deal with memory allocated
+ * by GLib functions in an exception-safe manner.
+ *
+ * This just creates a unique_ptr that uses g_free as its deleter.
+ */
+template <typename T>
+std::unique_ptr<T[], decltype(&g_free)> make_unique_ptr_gfree(T* p)
+{
+ return std::unique_ptr<T[], decltype(&g_free)>(p, &g_free);
+}
//TODO: Deprecate this? We don't use it ourselves.
/** Removes the const nature of a ptr
@@ -102,7 +119,7 @@ std::string convert_const_gchar_ptr_to_stdstring(const char* str)
inline
Glib::ustring convert_return_gchar_ptr_to_ustring(char* str)
{
- return (str) ? Glib::ustring(Glib::ScopedPtr<char>(str).get())
+ return (str) ? Glib::ustring(Glib::make_unique_ptr_gfree(str).get())
: Glib::ustring();
}
@@ -110,7 +127,7 @@ Glib::ustring convert_return_gchar_ptr_to_ustring(char* str)
inline
std::string convert_return_gchar_ptr_to_stdstring(char* str)
{
- return (str) ? std::string(Glib::ScopedPtr<char>(str).get())
+ return (str) ? std::string(Glib::make_unique_ptr_gfree(str).get())
: std::string();
}