UDK 3.2.7 C/C++ API Reference
salhelper/simplereferenceobject.hxx
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /*************************************************************************
00003  *
00004  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
00005  *
00006  * Copyright 2000, 2010 Oracle and/or its affiliates.
00007  *
00008  * OpenOffice.org - a multi-platform office productivity suite
00009  *
00010  * This file is part of OpenOffice.org.
00011  *
00012  * OpenOffice.org is free software: you can redistribute it and/or modify
00013  * it under the terms of the GNU Lesser General Public License version 3
00014  * only, as published by the Free Software Foundation.
00015  *
00016  * OpenOffice.org is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Lesser General Public License version 3 for more details
00020  * (a copy is included in the LICENSE file that accompanied this code).
00021  *
00022  * You should have received a copy of the GNU Lesser General Public License
00023  * version 3 along with OpenOffice.org.  If not, see
00024  * <http://www.openoffice.org/license.html>
00025  * for a copy of the LGPLv3 License.
00026  *
00027  ************************************************************************/
00028 
00029 #ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00030 #define _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00031 
00032 #include "osl/interlck.h"
00033 #include "sal/types.h"
00034 #include "salhelperdllapi.h"
00035 
00036 #ifndef INCLUDED_CSTDDEF
00037 #include <cstddef>
00038 #define INCLUDED_CSTDDEF
00039 #endif
00040 #ifndef INCLUDED_NEW
00041 #include <new>
00042 #define INCLUDED_NEW
00043 #endif
00044 
00045 namespace salhelper {
00046 
00073 class SALHELPER_DLLPUBLIC SimpleReferenceObject
00074 {
00075 public:
00076     inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {}
00077 
00084     inline void acquire() SAL_THROW(())
00085     { osl_incrementInterlockedCount(&m_nCount); }
00086 
00087     inline void release() SAL_THROW(())
00088     { if (osl_decrementInterlockedCount(&m_nCount) == 0) delete this; }
00089 
00092     static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
00093 
00096     static void * operator new(std::size_t nSize,
00097                                std::nothrow_t const & rNothrow)
00098         SAL_THROW(());
00099 
00102     static void operator delete(void * pPtr) SAL_THROW(());
00103 
00106     static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
00107         SAL_THROW(());
00108 
00109 protected:
00110     virtual ~SimpleReferenceObject() SAL_THROW(());
00111 
00112 private:
00113     oslInterlockedCount m_nCount;
00114 
00117     SALHELPER_DLLPRIVATE SimpleReferenceObject(SimpleReferenceObject &);
00118 
00121     SALHELPER_DLLPRIVATE void operator =(SimpleReferenceObject);
00122 
00124 
00125 #ifdef _MSC_VER
00126 /* We can't now have these private with MSVC2008 at least, it leads to
00127    compilation errors in xmloff and other places.
00128 */
00129 protected:
00130 #endif
00131 
00133     static void * operator new[](std::size_t);
00134 
00137     static void operator delete[](void * pPtr);
00138 
00140 };
00141 
00142 }
00143 
00144 #endif // _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00145 
00146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines