LibreOffice
LibreOffice 4.2 SDK C/C++ API Reference
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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>
24 #include <sal/types.h>
26 
27 #include <cstddef>
28 #include <new>
29 
30 namespace salhelper {
31 
59 {
60 public:
61  inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {}
62 
69  inline void acquire() SAL_THROW(())
70  { osl_atomic_increment(&m_nCount); }
71 
72  inline void release() SAL_THROW(())
73  { if (osl_atomic_decrement(&m_nCount) == 0) delete this; }
74 
77  static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
78 
81  static void * operator new(std::size_t nSize,
82  std::nothrow_t const & rNothrow)
83  SAL_THROW(());
84 
87  static void operator delete(void * pPtr) SAL_THROW(());
88 
91  static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
92  SAL_THROW(());
93 
94 protected:
95  virtual ~SimpleReferenceObject() SAL_THROW(());
96 
97 private:
98  oslInterlockedCount m_nCount;
99 
103 
106  SALHELPER_DLLPRIVATE void operator =(SimpleReferenceObject);
107 
109 
110 #ifdef _MSC_VER
111 /* We can't now have these private with MSVC2008 at least, it leads to
112  compilation errors in xmloff and other places.
113 */
114 protected:
115 #endif
116 
118  static void * operator new[](std::size_t);
119 
122  static void operator delete[](void * pPtr);
123 
125 };
126 
127 }
128 
129 #endif // INCLUDED_SALHELPER_SIMPLEREFERENCEOBJECT_HXX
130 
131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 oslInterlockedCount
Definition: interlck.h:32
SimpleReferenceObject()
Definition: simplereferenceobject.hxx:61
void acquire()
Definition: simplereferenceobject.hxx:69
#define SALHELPER_DLLPUBLIC
Definition: salhelperdllapi.h:28
#define SALHELPER_DLLPRIVATE
Definition: salhelperdllapi.h:30
A simple base implementation for reference-counted objects.
Definition: simplereferenceobject.hxx:58
void release()
Definition: simplereferenceobject.hxx:72
#define SAL_THROW(exc)
Definition of function throw clause macros.
Definition: types.h:358