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  * This file is part of the LibreOffice project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  *
00009  * This file incorporates work covered by the following license notice:
00010  *
00011  *   Licensed to the Apache Software Foundation (ASF) under one or more
00012  *   contributor license agreements. See the NOTICE file distributed
00013  *   with this work for additional information regarding copyright
00014  *   ownership. The ASF licenses this file to you under the Apache
00015  *   License, Version 2.0 (the "License"); you may not use this file
00016  *   except in compliance with the License. You may obtain a copy of
00017  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
00018  */
00019 
00020 #ifndef _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00021 #define _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00022 
00023 #include "osl/interlck.h"
00024 #include "sal/types.h"
00025 #include "salhelperdllapi.h"
00026 
00027 #include <cstddef>
00028 #include <new>
00029 
00030 namespace salhelper {
00031 
00058 class SALHELPER_DLLPUBLIC SimpleReferenceObject
00059 {
00060 public:
00061     inline SimpleReferenceObject() SAL_THROW(()): m_nCount(0) {}
00062 
00069     inline void acquire() SAL_THROW(())
00070     { osl_atomic_increment(&m_nCount); }
00071 
00072     inline void release() SAL_THROW(())
00073     { if (osl_atomic_decrement(&m_nCount) == 0) delete this; }
00074 
00077     static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
00078 
00081     static void * operator new(std::size_t nSize,
00082                                std::nothrow_t const & rNothrow)
00083         SAL_THROW(());
00084 
00087     static void operator delete(void * pPtr) SAL_THROW(());
00088 
00091     static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
00092         SAL_THROW(());
00093 
00094 protected:
00095     virtual ~SimpleReferenceObject() SAL_THROW(());
00096 
00097 private:
00098     oslInterlockedCount m_nCount;
00099 
00102     SALHELPER_DLLPRIVATE SimpleReferenceObject(SimpleReferenceObject &);
00103 
00106     SALHELPER_DLLPRIVATE void operator =(SimpleReferenceObject);
00107 
00109 
00110 #ifdef _MSC_VER
00111 /* We can't now have these private with MSVC2008 at least, it leads to
00112    compilation errors in xmloff and other places.
00113 */
00114 protected:
00115 #endif
00116 
00118     static void * operator new[](std::size_t);
00119 
00122     static void operator delete[](void * pPtr);
00123 
00125 };
00126 
00127 }
00128 
00129 #endif // _SALHELPER_SIMPLEREFERENCEOBJECT_HXX_
00130 
00131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines