diff options
-rw-r--r-- | cairomm/refptr.h | 52 |
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 */ |