LibreOffice: salhelper/simplereferenceobject.hxx Source File

LibreOffice LibreOffice 26.2 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{
63 static const size_t nStaticFlag = 0x80000000;
64
65public:
66 SimpleReferenceObject(): m_nCount(0) {}
67
73 void acquire()
74 {
75 if (!(m_nCount & nStaticFlag))
76 osl_atomic_increment(&m_nCount);
77 }
78
79 void release()
80 {
81 if (!(m_nCount & nStaticFlag) &&
82 osl_atomic_decrement(&m_nCount) == 0)
83 delete this;
84 }
85
88 static void * operator new(std::size_t nSize);
89
92 static void * operator new(std::size_t nSize,
93 std::nothrow_t const & rNothrow);
94
97 static void operator delete(void * pPtr);
98
101 static void operator delete(void * pPtr, std::nothrow_t const & rNothrow);
102
103protected:
104 virtual ~SimpleReferenceObject() COVERITY_NOEXCEPT_FALSE;
105
110 void staticize()
111 {
112 m_nCount |= nStaticFlag;
113 }
114
115 oslInterlockedCount m_nCount;
116
117private:
120 SimpleReferenceObject(SimpleReferenceObject &) SAL_DELETED_FUNCTION;
121
124 void operator =(SimpleReferenceObject) SAL_DELETED_FUNCTION;
125
128 static void * operator new[](std::size_t) SAL_DELETED_FUNCTION;
129
132 static void operator delete[](void * pPtr) SAL_DELETED_FUNCTION;
133};
134
135}
136
137#endif // INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
138
139/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DELETED_FUNCTION
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition types.h:396
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:367
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::~SimpleReferenceObject
virtual ~SimpleReferenceObject() COVERITY_NOEXCEPT_FALSE
salhelper::SimpleReferenceObject::staticize
void staticize()
mark reference count as not to be touched, and the related object as having an indefinite lifespan.
Definition simplereferenceobject.hxx:110
salhelper::SimpleReferenceObject::release
void release()
Definition simplereferenceobject.hxx:79
salhelper::SimpleReferenceObject::SimpleReferenceObject
SimpleReferenceObject()
Definition simplereferenceobject.hxx:66
salhelper::SimpleReferenceObject::m_nCount
oslInterlockedCount m_nCount
Definition simplereferenceobject.hxx:115
salhelper::SimpleReferenceObject::acquire
void acquire()
Definition simplereferenceobject.hxx:73