LibreOfficeDev
LibreOfficeDev 25.8 SDK C/C++ API Reference
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 
33 namespace salhelper {
34 
62 {
63  static const size_t nStaticFlag = 0x80000000;
64 
65 public:
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 
103 protected:
105 
110  void staticize()
111  {
112  m_nCount |= nStaticFlag;
113  }
114 
116 
117 private:
121 
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: */
void release()
Definition: simplereferenceobject.hxx:79
SimpleReferenceObject()
Definition: simplereferenceobject.hxx:66
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:367
oslInterlockedCount m_nCount
Definition: simplereferenceobject.hxx:115
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:396
void acquire()
Definition: simplereferenceobject.hxx:73
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:32
sal_Int32 oslInterlockedCount
Definition: interlck.h:44
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:61
Definition: condition.hxx:33