[Libreoffice-commits] .: binfilter/inc

Caolán McNamara caolan at kemper.freedesktop.org
Fri Mar 23 07:58:36 PDT 2012


 binfilter/inc/bf_svtools/cancel.hxx |   49 ++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

New commits:
commit 4d74905bf959fcce368f2dbf79021417484b75b8
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Fri Mar 23 12:23:21 2012 +0000

    move SvWeakBase etc into binfilter

diff --git a/binfilter/inc/bf_svtools/cancel.hxx b/binfilter/inc/bf_svtools/cancel.hxx
index 5cbab0a..7dc72c1 100644
--- a/binfilter/inc/bf_svtools/cancel.hxx
+++ b/binfilter/inc/bf_svtools/cancel.hxx
@@ -48,6 +48,55 @@ typedef SvPtrarr SfxCancellables_Impl;
 
 //-------------------------------------------------------------------------
 
+class SvWeakBase;
+class SvWeakHdl : public SvRefBase
+{
+    friend class SvWeakBase;
+    SvWeakBase* _pObj;
+public:
+    void ResetWeakBase( ) { _pObj = 0; }
+private:
+    SvWeakHdl( SvWeakBase* pObj ) : _pObj( pObj ) {}
+public:
+    SvWeakBase* GetObj() { return _pObj; }
+};
+
+SV_DECL_IMPL_REF( SvWeakHdl )
+
+class SvWeakBase
+{
+    SvWeakHdlRef _xHdl;
+public:
+    SvWeakHdl* GetHdl() { return _xHdl; }
+
+    // Wg CompilerWarnung nicht ueber Initializer
+    SvWeakBase() { _xHdl = new SvWeakHdl( this ); }
+    ~SvWeakBase() { _xHdl->ResetWeakBase(); }
+};
+
+#define SV_DECL_WEAK( ClassName )                                   \
+class ClassName##Weak                                               \
+{                                                                   \
+    SvWeakHdlRef _xHdl;                                             \
+public:                                                             \
+    inline               ClassName##Weak( ) {}                      \
+    inline               ClassName##Weak( ClassName* pObj ) {       \
+        if( pObj ) _xHdl = pObj->GetHdl(); }                        \
+    inline void          Clear() { _xHdl.Clear(); }                 \
+    inline ClassName##Weak& operator = ( ClassName * pObj ) {       \
+        _xHdl = pObj ? pObj->GetHdl() : 0; return *this; }          \
+    inline sal_Bool            Is() const {                         \
+        return _xHdl.Is() && _xHdl->GetObj(); }                     \
+    inline ClassName *     operator &  () const {                   \
+        return (ClassName*) ( _xHdl.Is() ? _xHdl->GetObj() : 0 ); } \
+    inline ClassName *     operator -> () const {                   \
+        return (ClassName*) ( _xHdl.Is() ? _xHdl->GetObj() : 0 ); } \
+    inline ClassName &     operator *  () const {                   \
+        return *(ClassName*) _xHdl->GetObj(); }                     \
+    inline operator ClassName * () const {                          \
+        return (ClassName*) (_xHdl.Is() ? _xHdl->GetObj() : 0 ); }  \
+};
+
 class  SfxCancelManager: public SfxBroadcaster
 , public SvWeakBase
 


More information about the Libreoffice-commits mailing list