LibreOffice
LibreOffice 7.1 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 <cassert>
23#include <cstddef>
24#include "osl/interlck.h"
25#include "rtl/alloc.h"
26#include "com/sun/star/uno/XWeak.hpp"
28
29
30namespace cppu
31{
32
33class OWeakConnectionPoint;
34
43class CPPUHELPER_DLLPUBLIC OWeakObject : public css::uno::XWeak
44{
45 friend class OWeakConnectionPoint;
46
47protected:
55
60 void disposeWeakConnectionPoint();
61
68
70
73 OWeakConnectionPoint * m_pWeakConnectionPoint;
74
77 void * m_pReserved;
78
80
81public:
83 // these are here to force memory de/allocation to sal lib.
84 static void * SAL_CALL operator new( size_t nSize )
85 { return ::rtl_allocateMemory( nSize ); }
86 static void SAL_CALL operator delete( void * pMem )
87 { ::rtl_freeMemory( pMem ); }
88 static void * SAL_CALL operator new( size_t, void * pMem )
89 { return pMem; }
90 static void SAL_CALL operator delete( void *, void * )
91 {}
93
94#ifdef _MSC_VER
98 OWeakObject();
99#else
103 : m_refCount( 0 )
104 , m_pWeakConnectionPoint( NULL )
105 , m_pReserved(NULL)
106 {}
107#endif
111 : css::uno::XWeak()
112 , m_refCount( 0 )
113 , m_pWeakConnectionPoint( NULL )
114 , m_pReserved(NULL)
115 {}
120 OWeakObject & SAL_CALL operator = ( const OWeakObject &)
121 { return *this; }
122
129 virtual css::uno::Any SAL_CALL queryInterface(
130 const css::uno::Type & rType ) SAL_OVERRIDE;
133 virtual void SAL_CALL acquire()
134 throw () SAL_OVERRIDE;
137 virtual void SAL_CALL release()
138 throw () SAL_OVERRIDE;
139
144 virtual css::uno::Reference< css::uno::XAdapter > SAL_CALL queryAdapter() SAL_OVERRIDE;
145
150 SAL_CALL operator css::uno::Reference< css::uno::XInterface > ()
151 { return this; }
152};
153
155
166static inline css::uno::XInterface * acquire(OWeakObject * instance)
167{
168 assert(instance != NULL);
169 instance->acquire();
170 return instance;
171}
173
174}
175
176#endif
177
178/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won't throw in practice,...
Definition: types.h:333
#define SAL_OVERRIDE
C++11 "override" feature.
Definition: types.h:387
SAL_DLLPUBLIC void rtl_freeMemory(void *Ptr) SAL_THROW_EXTERN_C()
Free memory.
SAL_DLLPUBLIC void * rtl_allocateMemory(sal_Size Bytes) SAL_THROW_EXTERN_C()
Allocate memory.
sal_Int32 oslInterlockedCount
Definition: interlck.h:40
#define CPPUHELPER_DLLPUBLIC
Definition: cppuhelperdllapi.h:28
Definition: types.h:355
Definition: Enterable.hxx:27
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:44
OWeakObject(const OWeakObject &)
Dummy copy constructor.
Definition: weak.hxx:110
OWeakObject()
Default Constructor.
Definition: weak.hxx:102
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::...
virtual void acquire() SAL_OVERRIDE
increasing m_refCount
virtual ~OWeakObject() COVERITY_NOEXCEPT_FALSE
Virtual dtor.