LibreOffice: cppuhelper/weak.hxx Source File

LibreOffice LibreOffice 25.2 SDK C/C++ API Reference

Loading...
Searching...
No Matches
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
20/*
21 * This file is part of LibreOffice published API.
22 */
23#ifndef INCLUDED_CPPUHELPER_WEAK_HXX
24#define INCLUDED_CPPUHELPER_WEAK_HXX
25
26#include <cassert>
27#include <cstddef>
28#include "osl/interlck.h"
29#include "rtl/alloc.h"
30#include "com/sun/star/uno/XWeak.hpp"
31#include "cppuhelper/cppuhelperdllapi.h"
32
33
34namespace cppu
35{
36
37class OWeakConnectionPoint;
38
47 class CPPUHELPER_DLLPUBLIC OWeakObject : public css::uno::XWeak
48{
49 friend class OWeakConnectionPoint;
50
51protected:
58 virtual ~OWeakObject() COVERITY_NOEXCEPT_FALSE;
59
64 void disposeWeakConnectionPoint();
65
71 oslInterlockedCount m_refCount;
72
74
77 OWeakConnectionPoint * m_pWeakConnectionPoint;
78
81 void * m_pReserved;
82
84
85public:
87 // these are here to force memory de/allocation to sal lib.
88 static void * SAL_CALL operator new( size_t nSize )
89 { return ::rtl_allocateMemory( nSize ); }
90 static void SAL_CALL operator delete( void * pMem )
91 { ::rtl_freeMemory( pMem ); }
92 static void * SAL_CALL operator new( size_t, void * pMem )
93 { return pMem; }
94 static void SAL_CALL operator delete( void *, void * )
95 {}
97
100 OWeakObject()
101 : m_refCount( 0 )
102 , m_pWeakConnectionPoint( NULL )
103 , m_pReserved(NULL)
104 {}
105
108 OWeakObject( const OWeakObject & )
109 : css::uno::XWeak()
110 , m_refCount( 0 )
111 , m_pWeakConnectionPoint( NULL )
112 , m_pReserved(NULL)
113 {}
114
118 OWeakObject & SAL_CALL operator = ( const OWeakObject &)
119 { return *this; }
120
127 virtual css::uno::Any SAL_CALL queryInterface(
128 const css::uno::Type & rType ) SAL_OVERRIDE;
131 virtual void SAL_CALL acquire()
132 SAL_NOEXCEPT SAL_OVERRIDE;
135 virtual void SAL_CALL release()
136 SAL_NOEXCEPT SAL_OVERRIDE;
137
142 virtual css::uno::Reference< css::uno::XAdapter > SAL_CALL queryAdapter() SAL_OVERRIDE;
143
148 SAL_CALL operator css::uno::Reference< css::uno::XInterface > ()
149 { return this; }
150
151#if defined LIBO_INTERNAL_ONLY
152 css::uno::XWeak* getXWeak() { return this; }
153#endif
154};
155
157
168static inline css::uno::XInterface * acquire(OWeakObject * instance)
169{
170 assert(instance != NULL);
171 instance->acquire();
172 return instance;
173}
174
175#if defined LIBO_INTERNAL_ONLY
176static inline css::uno::XWeak* getXWeak(OWeakObject* instance) { return instance; }
177#endif
179
180}
181
182#endif
183
184/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_NOEXCEPT
#define SAL_NOEXCEPT
Macro for C++11 "noexcept" vs.
Definition types.h:434
COVERITY_NOEXCEPT_FALSE
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won't throw in practice,...
Definition types.h:367
SAL_OVERRIDE
#define SAL_OVERRIDE
C++11 "override" feature.
Definition types.h:409
alloc.h
rtl_freeMemory
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
interlck.h
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition interlck.h:44
cppuhelperdllapi.h
CPPUHELPER_DLLPUBLIC
#define CPPUHELPER_DLLPUBLIC
Definition cppuhelperdllapi.h:32
com::sun::star
Definition types.h:377
cppu
Definition Enterable.hxx:31
cppu::OWeakObject
Base class to implement a UNO object supporting weak references, i.e.
Definition weak.hxx:48
cppu::OWeakObject::m_refCount
oslInterlockedCount m_refCount
reference count.
Definition weak.hxx:71
cppu::OWeakObject::OWeakObject
OWeakObject(const OWeakObject &)
Dummy copy constructor.
Definition weak.hxx:108
cppu::OWeakObject::disposeWeakConnectionPoint
void disposeWeakConnectionPoint()
disposes and resets m_pWeakConnectionPoint
cppu::OWeakObject::queryAdapter
virtual css::uno::Reference< css::uno::XAdapter > queryAdapter() SAL_OVERRIDE
XWeak::queryAdapter() implementation.
cppu::OWeakObject::OWeakObject
OWeakObject()
Default Constructor.
Definition weak.hxx:100
cppu::OWeakObject::OWeakConnectionPoint
friend class OWeakConnectionPoint
Definition weak.hxx:49
cppu::OWeakObject::queryInterface
virtual css::uno::Any queryInterface(const css::uno::Type &rType) SAL_OVERRIDE
Basic queryInterface() implementation supporting com::sun::star::uno::XWeak and com::sun::star::uno::...
cppu::OWeakObject::acquire
virtual void acquire() SAL_NOEXCEPT SAL_OVERRIDE
increasing m_refCount
cppu::OWeakObject::release
virtual void release() SAL_NOEXCEPT SAL_OVERRIDE
decreasing m_refCount
cppu::OWeakObject::~OWeakObject
virtual ~OWeakObject() COVERITY_NOEXCEPT_FALSE
Virtual dtor.
com::sun::star::uno::Any
C++ class representing an IDL any.
Definition Any.h:58
com::sun::star::uno::Type
C++ class representing an IDL meta type.
Definition Type.h:59