Branch libreoffice-5-0-4
[LibreOffice.git] / include / canvas / base / disambiguationhelper.hxx
blob9b07498cb754a0020dee8388f460dbc85dcb5541
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_CANVAS_BASE_DISAMBIGUATIONHELPER_HXX
21 #define INCLUDED_CANVAS_BASE_DISAMBIGUATIONHELPER_HXX
23 #include <osl/mutex.hxx>
26 /* Definition of the DisambiguationHelper class */
28 namespace canvas
30 /** Base class, initializing its own baseclass with m_aMutex.
32 This is necessary to make the CanvasBase, GraphicDeviceBase,
33 etc. classes freely combinable - letting them perform this
34 initialization would prohibit deriving e.g. CanvasBase from
35 GraphicDeviceBase.
37 On top of that, disambiguates XEventListener::disposing and
38 WeakComponentImplHelper::disposing.
40 Having two virtual methods with the same name, and not
41 overriding them in every derived class, will hide one of
42 them. Later trying to override the same method, will generate
43 a new vtable slot, and lead to very hard to spot errors.
45 template< class Base > class DisambiguationHelper : public Base
47 protected:
48 /** Construct DisambiguationHelper
50 This method is the whole purpose of this template:
51 initializing a base class with the provided m_aMutex
52 member (the WeakComponentImplHelper templates need that,
53 as they require the lifetime of the mutex to extend
54 theirs).
56 DisambiguationHelper() :
57 Base( m_aMutex )
61 virtual void disposeThis()
63 virtual void disposeEventSource( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
66 mutable ::osl::Mutex m_aMutex;
68 private:
69 virtual void SAL_CALL disposing() SAL_OVERRIDE
70 { disposeThis(); }
72 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE
73 { disposeEventSource(Source); }
78 #endif // INCLUDED_CANVAS_BASE_DISAMBIGUATIONHELPER_HXX
80 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */