AlterOffice
AlterOffice 3.4 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
weak.hxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 
3 #ifndef INCLUDED_CPPUHELPER_WEAK_HXX
4 #define INCLUDED_CPPUHELPER_WEAK_HXX
5 
6 #include <cassert>
7 #include <cstddef>
8 #include "osl/interlck.h"
9 #include "rtl/alloc.h"
10 #include "com/sun/star/uno/XWeak.hpp"
12 
13 
14 namespace cppu
15 {
16 
17 class OWeakConnectionPoint;
18 
27 class CPPUHELPER_DLLPUBLIC OWeakObject : public css::uno::XWeak
28 {
29  friend class OWeakConnectionPoint;
30 
31 protected:
39 
44  void disposeWeakConnectionPoint();
45 
51  oslInterlockedCount m_refCount;
52 
54 
57  OWeakConnectionPoint * m_pWeakConnectionPoint;
58 
61  void * m_pReserved;
62 
64 
65 public:
67  // these are here to force memory de/allocation to sal lib.
68  static void * SAL_CALL operator new( size_t nSize )
69  { return ::rtl_allocateMemory( nSize ); }
70  static void SAL_CALL operator delete( void * pMem )
71  { ::rtl_freeMemory( pMem ); }
72  static void * SAL_CALL operator new( size_t, void * pMem )
73  { return pMem; }
74  static void SAL_CALL operator delete( void *, void * )
75  {}
77 
81  : m_refCount( 0 )
82  , m_pWeakConnectionPoint( NULL )
83  , m_pReserved(NULL)
84  {}
85 
89  : css::uno::XWeak()
90  , m_refCount( 0 )
91  , m_pWeakConnectionPoint( NULL )
92  , m_pReserved(NULL)
93  {}
98  OWeakObject & SAL_CALL operator = ( const OWeakObject &)
99  { return *this; }
100 
107  virtual css::uno::Any SAL_CALL queryInterface(
108  const css::uno::Type & rType ) SAL_OVERRIDE;
111  virtual void SAL_CALL acquire()
115  virtual void SAL_CALL release()
116  SAL_NOEXCEPT SAL_OVERRIDE;
117 
122  virtual css::uno::Reference< css::uno::XAdapter > SAL_CALL queryAdapter() SAL_OVERRIDE;
123 
128  SAL_CALL operator css::uno::Reference< css::uno::XInterface > ()
129  { return this; }
130 };
131 
133 
144 static inline css::uno::XInterface * acquire(OWeakObject * instance)
145 {
146  assert(instance != NULL);
147  instance->acquire();
148  return instance;
149 }
151 
152 }
153 
154 #endif
155 
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
OWeakObject(const OWeakObject &)
Dummy copy constructor.
Definition: weak.hxx:88
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:329
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:12
css::uno::Any queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
Definition: queryinterface.hxx:23
#define SAL_NOEXCEPT
Macro for C++11 &quot;noexcept&quot; vs.
Definition: types.h:396
OWeakObject()
Default Constructor.
Definition: weak.hxx:80
sal_Int32 oslInterlockedCount
Definition: interlck.h:24
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
#define SAL_OVERRIDE
C++11 &quot;override&quot; feature.
Definition: types.h:371
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:27