My Project
UDK 3.2.7 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  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org. If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 #ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
30 #define _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
31 
32 #include "osl/interlck.h"
33 #include "sal/types.h"
34 #include "salhelperdllapi.h"
35 
36 #ifndef INCLUDED_CSTDDEF
37 #include <cstddef>
38 #define INCLUDED_CSTDDEF
39 #endif
40 #ifndef INCLUDED_NEW
41 #include <new>
42 #define INCLUDED_NEW
43 #endif
44 
45 namespace salhelper {
46 
74 {
75 public:
76  inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {}
77 
84  inline void acquire() SAL_THROW(())
85  { osl_incrementInterlockedCount(&m_nCount); }
86 
87  inline void release() SAL_THROW(())
88  { if (osl_decrementInterlockedCount(&m_nCount) == 0) delete this; }
89 
92  static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
93 
96  static void * operator new(std::size_t nSize,
97  std::nothrow_t const & rNothrow)
98  SAL_THROW(());
99 
102  static void operator delete(void * pPtr) SAL_THROW(());
103 
106  static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
107  SAL_THROW(());
108 
109 protected:
110  virtual ~SimpleReferenceObject() SAL_THROW(());
111 
112 private:
113  oslInterlockedCount m_nCount;
114 
118 
121  SALHELPER_DLLPRIVATE void operator =(SimpleReferenceObject);
122 
124 
125 #ifdef _MSC_VER
126 /* We can't now have these private with MSVC2008 at least, it leads to
127  compilation errors in xmloff and other places.
128 */
129 protected:
130 #endif
131 
133  static void * operator new[](std::size_t);
134 
137  static void operator delete[](void * pPtr);
138 
140 };
141 
142 }
143 
144 #endif // _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
145 
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */