[smart_ptr] Don't reinvent the wheel. Leverage std::unique_ptr<>.
[profile/ivi/settings-daemon.git] / include / settingsd / glib_traits.hpp
index 40c26ce..8578b08 100644 (file)
@@ -3,6 +3,8 @@
  *
  * @brief @c GLib traits.
  *
+ * This header contains traits specific to GLib types.
+ *
  * @author Ossama Othman @<ossama.othman@@intel.com@>
  *
  * @copyright @par
@@ -36,53 +38,85 @@ namespace ivi
   {
     template<typename T> struct traits;
 
+    // GVariant traits specialization.
     template<>
     struct traits<GVariant>
     {
-      static void
-      release(GVariant * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_variant_unref(p);
-      }
+        void
+        operator()(GVariant * p) const
+        {
+          if (p != nullptr)
+            g_variant_unref(p);
+        }
+      };
     };
 
+    // GVariantIter traits specialization.
     template<>
     struct traits<GVariantIter>
     {
-      static void release(GVariantIter * p) { g_variant_iter_free(p); }
+      // Functor to be used in std::unique_ptr<> specialization.
+      struct delete_functor
+      {
+        void
+        operator()(GVariantIter * p) const
+        {
+          g_variant_iter_free(p);
+        }
+      };
     };
 
+    // gchar traits specialization.
     template<>
     struct traits<gchar>
     {
-      static void release(gchar * p) { g_free(p); }
+      struct delete_functor
+      {
+        void
+        operator()(gchar * p) const
+        {
+          g_free(p);
+        }
+      };
     };
 
+    // GError traits specialization.
     template<>
     struct traits<GError>
     {
-      static void release(GError * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_error_free(p);
-      }
+        void
+        operator()(GError * p) const
+        {
+          if (p != nullptr)
+            g_error_free(p);
+        }
+      };
     };
 
+    // GMainLoop traits specialization.
     template<>
     struct traits<GMainLoop>
     {
-      static void release(GMainLoop * p)
+      struct delete_functor
       {
-        if (p != nullptr)
-          g_main_loop_unref(p);
-      }
+        void
+        operator()(GMainLoop * p) const
+        {
+          if (p != nullptr)
+            g_main_loop_unref(p);
+        }
+      };
     };
 
   }
 }
 
 
+
 #endif /* IVI_SETTINGS_GLIB_TRAITS_HPP */