summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2020-08-26 12:55:12 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2020-08-26 12:55:12 +0200
commit8f85a66e1b0798715d0d5020c8a315988e6822d9 (patch)
treec0cd9fe3999b7685a252df74e7f713eea2268e35
parent6768cc1d9b1f79128ed9fb0b84bd7d3f4a05cdcc (diff)
Remove RefPtrDeleter()
It's right for C++ classes wrapping GObject subclasses in glibmm and gtkmm, but it is not right for wrappers in cairomm. Fixes #23
-rw-r--r--cairomm/refptr.h52
1 files changed, 24 insertions, 28 deletions
diff --git a/cairomm/refptr.h b/cairomm/refptr.h
index 664fb59..e6b603f 100644
--- a/cairomm/refptr.h
+++ b/cairomm/refptr.h
@@ -1,11 +1,5 @@
-// -*- c++ -*-
-#ifndef _cairo_REFPTR_H
-#define _cairo_REFPTR_H
-
-#include <memory>
-
-/* $Id: refptr.h,v 1.6 2006-09-27 18:38:57 murrayc Exp $ */
-
+#ifndef __CAIROMM_REFPTR_H
+#define __CAIROMM_REFPTR_H
/* Copyright 2005 The cairomm Development Team
*
* This library is free software; you can redistribute it and/or
@@ -24,44 +18,46 @@
* 02110-1301, USA.
*/
-#include <utility>
+#include <memory>
namespace Cairo
{
-template <class T_CppObject>
-void RefPtrDeleter(T_CppObject* object)
-{
- if (!object)
- return;
-
- object->unreference();
-}
-
-/** RefPtr<> is a reference-counting shared smartpointer.
+/** %RefPtr<> is a reference-counting shared smartpointer.
*
* Reference counting means that a shared reference count is incremented each
- * time a RefPtr is copied, and decremented each time a RefPtr is destroyed,
+ * time a %RefPtr is copied, and decremented each time a %RefPtr is destroyed,
* for instance when it leaves its scope. When the reference count reaches
* zero, the contained object is deleted
*
- * cairomm uses RefPtr so that you don't need to remember
+ * cairomm uses %RefPtr so that you don't need to remember
* to delete the object explicitly, or know when a method expects you to delete
* the object that it returns, and to prevent any need to manually reference
- * and unreference() cairo objects.
+ * and unreference cairo objects.
+ *
+ * @see Cairo::make_refptr_for_instance()
*/
-template <class T_CppObject>
+template <typename T_CppObject>
using RefPtr = std::shared_ptr<T_CppObject>;
-template <class T_CppObject>
+// Cairo::make_refptr_for_instance() is not strictly necessary. It's used because
+// 1. Similar to glibmm. Compare Glib::make_refptr_for_instance().
+// 2. When the RefPtr constructor is called only from make_refptr_for_instance(),
+// future changes, if necessary, are easier to make.
+/** Create a %RefPtr<> to an instance of any reference-counted class whose
+ * destructor is noexcept (the default for destructors).
+ *
+ * Normal application code should not need to use this. However, this is necessary
+ * when implementing create() methods for derived classes, such as a derived
+ * Cairo::UserFontFace.
+ */
+template <typename T_CppObject>
RefPtr<T_CppObject>
make_refptr_for_instance(T_CppObject* object)
{
- return RefPtr<T_CppObject>(object, &RefPtrDeleter<T_CppObject>);
+ return RefPtr<T_CppObject>(object);
}
} // namespace Cairo
-#endif /* _cairo_REFPTR_H */
-
-// vim: ts=2 sw=2 et
+#endif /* __CAIROMM_REFPTR_H */