LibreOffice: cppuhelper/weak.hxx Source File

LibreOffice LibreOffice 4.4 SDK C/C++ API Reference

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 <cassert>
23 #include <osl/interlck.h>
24 #include <rtl/alloc.h>
25 #include <com/sun/star/uno/XWeak.hpp>
26 #include <cppuhelper/cppuhelperdllapi.h>
27
28
29 namespace cppu
30 {
31
32 class OWeakConnectionPoint;
33
42 class CPPUHELPER_DLLPUBLIC OWeakObject : public ::com::sun::star::uno::XWeak
43 {
44 friend class OWeakConnectionPoint;
45
46 protected:
53 virtual ~OWeakObject();
54
59 void disposeWeakConnectionPoint();
60
66 oslInterlockedCount m_refCount;
67
69
72 OWeakConnectionPoint * m_pWeakConnectionPoint;
73
76 void * m_pReserved;
77
79
80 public:
82 // these are here to force memory de/allocation to sal lib.
83 inline static void * SAL_CALL operator new( size_t nSize )
84 { return ::rtl_allocateMemory( nSize ); }
85 inline static void SAL_CALL operator delete( void * pMem )
86 { ::rtl_freeMemory( pMem ); }
87 inline static void * SAL_CALL operator new( size_t, void * pMem )
88 { return pMem; }
89 inline static void SAL_CALL operator delete( void *, void * )
90 {}
92
93 #ifdef _MSC_VER
94
97 OWeakObject();
98 #else
99
101 inline OWeakObject()
102 : m_refCount( 0 )
103 , m_pWeakConnectionPoint( 0 )
104 , m_pReserved(0)
105 {}
106 #endif
107
111 inline OWeakObject( const OWeakObject & rObj )
112 : com::sun::star::uno::XWeak()
113 , m_refCount( 0 )
114 , m_pWeakConnectionPoint( 0 )
115 , m_pReserved(0)
116 {
117 (void) rObj;
118 }
123 inline OWeakObject & SAL_CALL operator = ( const OWeakObject &)
124 { return *this; }
125
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, std::exception) SAL_OVERRIDE;
137 virtual void SAL_CALL acquire()
138 throw () SAL_OVERRIDE;
141 virtual void SAL_CALL release()
142 throw () SAL_OVERRIDE;
143
148 virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter > SAL_CALL queryAdapter()
149 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150
155 inline SAL_CALL operator ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > ()
156 { return this; }
157 };
158
160
171 static inline ::com::sun::star::uno::XInterface * acquire(OWeakObject * instance)
172 {
173 assert(instance != 0);
174 instance->acquire();
175 return instance;
176 }
178
179 }
180
181 #endif
182
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
cppu::OWeakObject
Base class to implement an UNO object supporting weak references, i.e.
Definition: weak.hxx:42
cppu::OWeakObject::OWeakObject
OWeakObject()
Default Constructor.
Definition: weak.hxx:101
com
Definition: types.h:375
interlck.h
cppu
Definition: Enterable.hxx:26
alloc.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
cppu::OWeakObject::m_refCount
oslInterlockedCount m_refCount
reference count.
Definition: weak.hxx:66
cppuhelperdllapi.h
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition: interlck.h:32
CPPUHELPER_DLLPUBLIC
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
SAL_OVERRIDE
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:407
rtl_allocateMemory
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
cppu::queryInterface
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
cppu::OWeakObject::OWeakObject
OWeakObject(const OWeakObject &rObj)
Dummy copy constructor.
Definition: weak.hxx:111