summaryrefslogtreecommitdiff
path: root/include/vcl/vclptr.hxx
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2015-03-30 17:49:20 +0100
committerMichael Meeks <michael.meeks@collabora.com>2015-04-10 13:13:53 +0100
commit582e89610b366c0d887baa6b8de7fa5f065900fa (patch)
tree91f3b723d1485b5616d457e30011fa55914785a4 /include/vcl/vclptr.hxx
parent49dadad0b55f879ebe5daf539a97043d283ad0a8 (diff)
vclptr: create Instance helpers, and set initial ref-count to 1.
Document that in README.lifecycle; the problem is that our constructors currently take and release references left/right on the object being created, which ... means we need an initial reference. Change-Id: I5de952b73ac67888c3fbb150d4a7cde2a7bc9abf
Diffstat (limited to 'include/vcl/vclptr.hxx')
-rw-r--r--include/vcl/vclptr.hxx50
1 files changed, 48 insertions, 2 deletions
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index 6ab6373eaf70..0c29f11d8e2d 100644
--- a/include/vcl/vclptr.hxx
+++ b/include/vcl/vclptr.hxx
@@ -22,6 +22,7 @@
#include <rtl/ref.hxx>
#include <cstddef>
+#include <utility>
/// @cond INTERNAL
namespace vcl { namespace detail {
@@ -90,14 +91,12 @@ public:
: m_rInnerRef()
{}
-
/** Constructor...
*/
inline VclPtr (reference_type * pBody)
: m_rInnerRef(pBody)
{}
-
/** Copy constructor...
*/
inline VclPtr (const VclPtr<reference_type> & handle)
@@ -216,8 +215,31 @@ public:
{
return (m_rInnerRef > handle.m_rInnerRef);
}
+
+protected:
+ inline VclPtr (reference_type * pBody, __sal_NoAcquire)
+ : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
+ {}
}; // class VclPtr
+/**
+ * A construction helper for VclPtr. Since VclPtr types are created
+ * with a reference-count of one - to help fit into the existing
+ * code-flow; this helps us to construct them easily.
+ *
+ * For more details on the design please see vcl/README.lifecycle
+ *
+ * @param reference_type must be a subclass of vcl::Window
+ */
+template <class reference_type>
+class VclPtrInstance : public VclPtr<reference_type>
+{
+public:
+ template<typename... Arg> VclPtrInstance(Arg &&... arg)
+ : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
+ {
+ }
+};
template <class reference_type>
class ScopedVclPtr : public VclPtr<reference_type>
@@ -277,6 +299,30 @@ private:
ScopedVclPtr (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION;
// And certainly we don't want a default assignment operator.
ScopedVclPtr<reference_type>& SAL_CALL operator= (const ScopedVclPtr<reference_type> &) SAL_DELETED_FUNCTION;
+
+protected:
+ inline ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
+ : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
+ {}
+};
+
+/**
+ * A construction helper for ScopedVclPtr. Since VclPtr types are created
+ * with a reference-count of one - to help fit into the existing
+ * code-flow; this helps us to construct them easily.
+ *
+ * For more details on the design please see vcl/README.lifecycle
+ *
+ * @param reference_type must be a subclass of vcl::Window
+ */
+template <class reference_type>
+class ScopedVclPtrInstance : public ScopedVclPtr<reference_type>
+{
+public:
+ template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
+ : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
+ {
+ }
};
#endif // INCLUDED_VCL_PTR_HXX