LibreOffice
LibreOffice 6.0 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 #ifndef INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
21 #define INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
22 
23 #include <osl/interlck.h>
25 
26 #include <cstddef>
27 #include <new>
28 
29 namespace salhelper {
30 
58 {
59 public:
60  SimpleReferenceObject(): m_nCount(0) {}
61 
68  void acquire()
69  { osl_atomic_increment(&m_nCount); }
70 
71  void release()
72  { if (osl_atomic_decrement(&m_nCount) == 0) delete this; }
73 
76  static void * operator new(std::size_t nSize);
77 
80  static void * operator new(std::size_t nSize,
81  std::nothrow_t const & rNothrow);
82 
85  static void operator delete(void * pPtr);
86 
89  static void operator delete(void * pPtr, std::nothrow_t const & rNothrow);
90 
91 protected:
93 
94 private:
95  oslInterlockedCount m_nCount;
96 
100 
104 
106 
107 #ifdef _MSC_VER
108 /* We can't now have these private with MSVC2008 at least, it leads to
109  compilation errors in xmloff and other places.
110 */
111 protected:
112 #endif
113 
115  static void * operator new[](std::size_t);
116 
119  static void operator delete[](void * pPtr);
120 
122 };
123 
124 }
125 
126 #endif // INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: condition.hxx:29
#define SAL_DELETED_FUNCTION
short-circuit extra-verbose API namespaces
Definition: types.h:402
#define COVERITY_NOEXCEPT_FALSE
To markup destructors that coverity warns might throw exceptions which won&#39;t throw in practice...
Definition: types.h:361
void release()
Definition: simplereferenceobject.hxx:71
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:57
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28
sal_Int32 oslInterlockedCount
Definition: interlck.h:36
SimpleReferenceObject()
Definition: simplereferenceobject.hxx:60
void acquire()
Definition: simplereferenceobject.hxx:68