LibreOffice: salhelper/simplereferenceobject.hxx Source File

LibreOffice LibreOffice 7.5 SDK C/C++ API Reference

Loading...
Searching...
No Matches
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"
28#include "salhelper/salhelperdllapi.h"
29
30#include <cstddef>
31#include <new>
32
33namespace salhelper {
34
61 class SALHELPER_DLLPUBLIC SimpleReferenceObject
62{
63public:
64 SimpleReferenceObject(): m_nCount(0) {}
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:
103 SimpleReferenceObject(SimpleReferenceObject &) SAL_DELETED_FUNCTION;
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: */
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:378
COVERITY_NOEXCEPT_FALSE
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won't throw in practice,...
Definition: types.h:349
salhelperdllapi.h
SALHELPER_DLLPUBLIC
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:32
interlck.h
oslInterlockedCount
sal_Int32 oslInterlockedCount
Definition: interlck.h:44
salhelper
Definition: condition.hxx:34
salhelper::SimpleReferenceObject
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:62
salhelper::SimpleReferenceObject::~SimpleReferenceObject
virtual ~SimpleReferenceObject() COVERITY_NOEXCEPT_FALSE
salhelper::SimpleReferenceObject::release
void release()
Definition: simplereferenceobject.hxx:75
salhelper::SimpleReferenceObject::SimpleReferenceObject
SimpleReferenceObject()
Definition: simplereferenceobject.hxx:64
salhelper::SimpleReferenceObject::acquire
void acquire()
Definition: simplereferenceobject.hxx:72