diff options
author | Noel Grandin <noel@peralex.com> | 2015-03-19 13:53:29 +0200 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2015-04-10 12:03:03 +0100 |
commit | 443be937e07b93860c13c960b376389845d0a09d (patch) | |
tree | 3c385b6905fc6d59a41ee03d3a4cac3e5a2f6c9f /include/vcl/vclptr.hxx | |
parent | cf06c0135d44b8f553940d0fabe03918d61d8a8f (diff) |
add ScopedVclPtr
which acts like boost::scoped_ptr to disposeAndClear a vcl::Window when
it leaves scope
Change-Id: I077522734585c19d6bbc3cbf81f1fa45e61ecd02
Diffstat (limited to 'include/vcl/vclptr.hxx')
-rw-r--r-- | include/vcl/vclptr.hxx | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx index b64824b871bf..c75d421583c7 100644 --- a/include/vcl/vclptr.hxx +++ b/include/vcl/vclptr.hxx @@ -220,6 +220,54 @@ public: } }; // class VclPtr + +template <class reference_type> +class ScopedVclPtr : public VclPtr<reference_type> +{ +public: + /** Constructor... + */ + inline ScopedVclPtr() + : VclPtr<reference_type>() + {} + + + /** Constructor... + */ + inline ScopedVclPtr (reference_type * pBody) + : VclPtr<reference_type>(pBody) + {} + + + /** Copy constructor... + */ + inline ScopedVclPtr (const VclPtr<reference_type> & handle) + : VclPtr<reference_type>(handle) + {} + + /** Up-casting conversion constructor: Copies interface reference. + + Does not work for up-casts to ambiguous bases. For the special case of + up-casting to Reference< XInterface >, see the corresponding conversion + operator. + + @param rRef another reference + */ + template< class derived_type > + inline ScopedVclPtr( + const VclPtr< derived_type > & rRef, + typename ::vcl::detail::UpCast< reference_type, derived_type >::t = 0 ) + : VclPtr<reference_type>( rRef ) + { + } + + ~ScopedVclPtr() + { + VclPtr<reference_type>::disposeAndClear(); + } + +}; + #endif // INCLUDED_VCL_PTR_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |