LibreOffice
LibreOffice 4.3 SDK C/C++ API Reference
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  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #ifndef INCLUDED_CPPUHELPER_WEAK_HXX
20 #define INCLUDED_CPPUHELPER_WEAK_HXX
21 
22 #include <osl/interlck.h>
23 #include <rtl/alloc.h>
24 #include <cppuhelper/weakref.hxx>
26 #include <com/sun/star/uno/XWeak.hpp>
28 
29 
30 namespace cppu
31 {
32 
33 class OWeakConnectionPoint;
34 
43 class CPPUHELPER_DLLPUBLIC OWeakObject : public ::com::sun::star::uno::XWeak
44 {
45  friend class OWeakConnectionPoint;
46 
47 protected:
54  virtual ~OWeakObject() SAL_THROW( (::com::sun::star::uno::RuntimeException) );
55 
60  void disposeWeakConnectionPoint();
61 
67  oslInterlockedCount m_refCount;
68 
70 
73  OWeakConnectionPoint * m_pWeakConnectionPoint;
74 
77  void * m_pReserved;
78 
80 
81 public:
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(())
89  { return pMem; }
90  inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
91  {}
93 
94 #ifdef _MSC_VER
95 
98  OWeakObject() SAL_THROW(());
99 #else
100 
102  inline OWeakObject() SAL_THROW(())
103  : m_refCount( 0 )
104  , m_pWeakConnectionPoint( 0 )
105  , m_pReserved(0)
106  {}
107 #endif
108 
112  inline OWeakObject( const OWeakObject & rObj ) SAL_THROW(())
113  : com::sun::star::uno::XWeak()
114  , m_refCount( 0 )
115  , m_pWeakConnectionPoint( 0 )
116  , m_pReserved(0)
117  {
118  (void) rObj;
119  }
124  inline OWeakObject & SAL_CALL operator = ( const OWeakObject &)
125  SAL_THROW(())
126  { return *this; }
127 
134  virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(
135  const ::com::sun::star::uno::Type & rType )
136  throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139  virtual void SAL_CALL acquire()
140  throw () SAL_OVERRIDE;
143  virtual void SAL_CALL release()
144  throw () SAL_OVERRIDE;
145 
150  virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter > SAL_CALL queryAdapter()
151  throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 
157  inline SAL_CALL operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > () SAL_THROW(())
158  { return this; }
159 };
160 
162 
173 static inline ::com::sun::star::uno::XInterface * acquire(OWeakObject * instance)
174 {
175  assert(instance != 0);
176  instance->acquire();
177  return instance;
178 }
180 
181 }
182 
183 #endif
184 
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 oslInterlockedCount
Definition: interlck.h:32
inline::com::sun::star::uno::Any queryInterface(const ::com::sun::star::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.
Definition: queryinterface.hxx:39
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
OWeakObject() SAL_THROW(())
Default Constructor.
Definition: weak.hxx:102
OWeakObject(const OWeakObject &rObj) SAL_THROW(())
Dummy copy constructor.
Definition: weak.hxx:112
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:423
Definition: Enterable.hxx:26
#define SAL_THROW(x)
Exception specification documentation.
Definition: types.h:361
Base class to implement an UNO object supporting weak references, i.e.
Definition: weak.hxx:43
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
Definition: types.h:391