LibreOffice Module cppuhelper (master)  1
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"
32 
33 
34 namespace cppu
35 {
36 
37 class OWeakConnectionPoint;
38 
47 class CPPUHELPER_DLLPUBLIC OWeakObject : public css::uno::XWeak
48 {
49  friend class OWeakConnectionPoint;
50 
51 protected:
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 
85 public:
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 
98 #ifdef _MSC_VER
99 
102  OWeakObject();
103 #else
104 
107  : m_refCount( 0 )
108  , m_pWeakConnectionPoint( NULL )
109  , m_pReserved(NULL)
110  {}
111 #endif
112 
115  : css::uno::XWeak()
116  , m_refCount( 0 )
117  , m_pWeakConnectionPoint( NULL )
118  , m_pReserved(NULL)
119  {}
124  OWeakObject & SAL_CALL operator = ( const OWeakObject &)
125  { return *this; }
126 
133  virtual css::uno::Any SAL_CALL queryInterface(
134  const css::uno::Type & rType ) SAL_OVERRIDE;
137  virtual void SAL_CALL acquire()
138  SAL_NOEXCEPT SAL_OVERRIDE;
141  virtual void SAL_CALL release()
142  SAL_NOEXCEPT SAL_OVERRIDE;
143 
148  virtual css::uno::Reference< css::uno::XAdapter > SAL_CALL queryAdapter() SAL_OVERRIDE;
149 
154  SAL_CALL operator css::uno::Reference< css::uno::XInterface > ()
155  { return this; }
156 };
157 
159 
170 static inline css::uno::XInterface * acquire(OWeakObject * instance)
171 {
172  assert(instance != NULL);
173  instance->acquire();
174  return instance;
175 }
177 
178 }
179 
180 #endif
181 
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ULONG m_refCount
OWeakObject(const OWeakObject &)
Dummy copy constructor.
Definition: weak.hxx:114
OWeakObject()
Default Constructor.
Definition: weak.hxx:106
return NULL
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
Base class to implement a UNO object supporting weak references, i.e.
Definition: weak.hxx:47
#define CPPUHELPER_DLLPUBLIC
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.