1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _CPPUHELPER_WEAK_HXX_
20 #define _CPPUHELPER_WEAK_HXX_
22 #include <osl/interlck.h>
23 #include <rtl/alloc.h>
24 #include <cppuhelper/weakref.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26 #include <com/sun/star/uno/XWeak.hpp>
27 #include "cppuhelperdllapi.h"
33 class OWeakConnectionPoint
;
35 /** Base class to implement an UNO object supporting weak references, i.e. the object can be held
36 weakly (by a ::com::sun::star::uno::WeakReference).
37 This implementation copes with reference counting. Upon last release(), the virtual dtor
41 Inherit from this class and delegate acquire()/ release() calls.
43 class CPPUHELPER_DLLPUBLIC OWeakObject
: public ::com::sun::star::uno::XWeak
45 friend class OWeakConnectionPoint
;
51 Despite the fact that a RuntimeException is allowed to be thrown, you must not throw any
52 exception upon destruction!
54 virtual ~OWeakObject() SAL_THROW( (::com::sun::star::uno::RuntimeException
) );
56 /** disposes and resets m_pWeakConnectionPoint
60 void disposeWeakConnectionPoint();
65 Don't modify manually! Use acquire() and release().
67 oslInterlockedCount m_refCount
;
71 /** Container of all weak reference listeners and the connection point from the weak reference.
73 OWeakConnectionPoint
* m_pWeakConnectionPoint
;
75 /** reserved for future use. do not use.
83 // these are here to force memory de/allocation to sal lib.
84 inline static void * SAL_CALL
operator new( size_t nSize
) SAL_THROW(())
85 { return ::rtl_allocateMemory( nSize
); }
86 inline static void SAL_CALL
operator delete( void * pMem
) SAL_THROW(())
87 { ::rtl_freeMemory( pMem
); }
88 inline static void * SAL_CALL
operator new( size_t, void * pMem
) SAL_THROW(())
90 inline static void SAL_CALL
operator delete( void *, void * ) SAL_THROW(())
95 /** Default Constructor. Sets the reference count to zero.
96 Accidentally occurs in msvc mapfile = > had to be outlined.
98 OWeakObject() SAL_THROW(());
100 /** Default Constructor. Sets the reference count to zero.
102 inline OWeakObject() SAL_THROW(())
104 , m_pWeakConnectionPoint( 0 )
107 /** Dummy copy constructor. Set the reference count to zero.
109 @param rObj dummy param
111 inline OWeakObject( const OWeakObject
& rObj
) SAL_THROW(())
112 : com::sun::star::uno::XWeak()
114 , m_pWeakConnectionPoint( 0 )
118 /** Dummy assignment operator. Does not affect reference count.
120 @return this OWeakObject
122 inline OWeakObject
& SAL_CALL
operator = ( const OWeakObject
&)
126 /** Basic queryInterface() implementation supporting \::com::sun::star::uno::XWeak and
127 \::com::sun::star::uno::XInterface.
129 @param rType demanded type
130 @return demanded type or empty any
132 virtual ::com::sun::star::uno::Any SAL_CALL
queryInterface(
133 const ::com::sun::star::uno::Type
& rType
)
134 throw (::com::sun::star::uno::RuntimeException
);
135 /** increasing m_refCount
137 virtual void SAL_CALL
acquire()
139 /** decreasing m_refCount
141 virtual void SAL_CALL
release()
144 /** XWeak::queryAdapter() implementation
146 @return a \::com::sun::star::uno::XAdapter reference
148 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XAdapter
> SAL_CALL
queryAdapter()
149 throw (::com::sun::star::uno::RuntimeException
);
151 /** Cast operator to XInterface reference.
153 @return XInterface reference
155 inline SAL_CALL
operator ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> () SAL_THROW(())
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */