LibreOffice Module salhelper (master) 1
simplereferenceobject.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
24#ifndef INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
25#define INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
26
27#include "osl/interlck.h"
29
30#include <cstddef>
31#include <new>
32
33namespace salhelper {
34
62{
63public:
65
72 void acquire()
73 { osl_atomic_increment(&m_nCount); }
74
75 void release()
76 { if (osl_atomic_decrement(&m_nCount) == 0) delete this; }
77
80 static void * operator new(std::size_t nSize);
81
84 static void * operator new(std::size_t nSize,
85 std::nothrow_t const & rNothrow);
86
89 static void operator delete(void * pPtr);
90
93 static void operator delete(void * pPtr, std::nothrow_t const & rNothrow);
94
95protected:
96 virtual ~SimpleReferenceObject() COVERITY_NOEXCEPT_FALSE;
97
98 oslInterlockedCount m_nCount;
99
100private:
104
107 void operator =(SimpleReferenceObject) SAL_DELETED_FUNCTION;
108
111 static void * operator new[](std::size_t) SAL_DELETED_FUNCTION;
112
115 static void operator delete[](void * pPtr) SAL_DELETED_FUNCTION;
116};
117
118}
119
120#endif // INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
A simple base implementation for reference-counted objects.
sal_Int16 m_nCount
#define SALHELPER_DLLPUBLIC