LibreOffice
LibreOffice 24.2 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 public:
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 
95 protected:
97 
99 
100 private:
104 
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: */
void release()
Definition: simplereferenceobject.hxx:75
SimpleReferenceObject()
Definition: simplereferenceobject.hxx:64
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:349
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:378
void acquire()
Definition: simplereferenceobject.hxx:72
#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