Prepare for removal of non-const operator[] from Sequence in lotuswordpro
[LibreOffice.git] / shell / inc / spsupp / COMRefCounted.hpp
blob4a3ce80bfb5a7eeb1908bbc6422a014c1fde99f0
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/.
8 */
10 #ifndef INCLUDED_SHELL_INC_SPSUPP_COMREFCOUNTED_HPP
11 #define INCLUDED_SHELL_INC_SPSUPP_COMREFCOUNTED_HPP
13 #include <objbase.h>
14 #include <assert.h>
16 template <class... Interfaces>
17 class COMRefCounted : public Interfaces...
19 public:
20 COMRefCounted() {}
21 virtual ~COMRefCounted() {}
23 // IUnknown methods
25 ULONG STDMETHODCALLTYPE AddRef() override
27 return static_cast<ULONG>(::InterlockedIncrement(&m_nRef));
30 ULONG STDMETHODCALLTYPE Release() override
32 assert(m_nRef > 0);
33 if (::InterlockedDecrement(&m_nRef) == 0)
35 delete this;
36 return 0;
38 return static_cast<ULONG>(m_nRef);
41 private:
42 LONG m_nRef = 1; // Created referenced
45 #endif
47 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */