diff options
author | Kjell Ahlstedt <kjell.ahlstedt@bredband.net> | 2015-09-15 11:50:59 +0200 |
---|---|---|
committer | Murray Cumming <murrayc@murrayc.com> | 2015-09-16 10:28:19 +0200 |
commit | 9412bc0b1e849466209661be02173003cc762c14 (patch) | |
tree | 70a1d6dac6707248fe74073bc039e182c0e0891b /glib | |
parent | 3938d56e7500310af3e73869b8b5eaaf0e4b6aa1 (diff) | |
download | glibmm-9412bc0b1e849466209661be02173003cc762c14.tar.gz |
Glib::RefPtr: Enable disallowance with certain classes
* glib/glibmm/refptr.h: Make it possible to stop use of RefPtr with
certain classes. Bug #755048.
Diffstat (limited to 'glib')
-rw-r--r-- | glib/glibmm/refptr.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/glib/glibmm/refptr.h b/glib/glibmm/refptr.h index b4e2b419..a7ca0fca 100644 --- a/glib/glibmm/refptr.h +++ b/glib/glibmm/refptr.h @@ -52,6 +52,41 @@ namespace Glib template <class T_CppObject> class RefPtr { +private: +#ifndef DOXYGEN_SHOULD_SKIP_THIS + /** Helper class for disallowing use of Glib::RefPtr with certain classes. + * + * Disallow for instance in Gtk::Widget and its subclasses. + * Glib::RefPtr<T>::is_allowed_type::value is false if + * T:dont_allow_use_in_glib_refptr_ is a public type, else it's true. + * Example: + * @code + * typedef int dont_allow_use_in_glib_refptr_; + * @endcode + */ + class is_allowed_type + { + private: + struct big + { + int memory[64]; + }; + + static big check(...); + + // If X::dont_allow_use_in_glib_refptr_ is not a type, this check() overload + // is ignored because of the SFINAE rule (Substitution Failure Is Not An Error). + template <typename X> + static typename X::dont_allow_use_in_glib_refptr_ check(X* obj); + + public: + static const bool value = sizeof(check(static_cast<T_CppObject*>(nullptr))) == sizeof(big); + }; + + static_assert(is_allowed_type::value, + "Glib::RefPtr must not be used with this class."); +#endif /* DOXYGEN_SHOULD_SKIP_THIS */ + public: /** Default constructor * |