1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef _SD_SIMPLEREFERENCECOMPONENT_HXX_ 29 #define _SD_SIMPLEREFERENCECOMPONENT_HXX_ 30 31 #include "osl/interlck.h" 32 #include "sal/types.h" 33 34 #include <cstddef> 35 #include <new> 36 37 #include <sddllapi.h> 38 39 namespace sd { 40 41 /** A simple base implementation for reference-counted components. 42 acts like sal::SimpleReferenceObject but calls the virtual disposing() 43 methods before the ref count switches from 1 to zero. 44 */ 45 class SimpleReferenceComponent 46 { 47 public: 48 SimpleReferenceComponent(); 49 50 /** @ATTENTION 51 The results are undefined if, for any individual instance of 52 SimpleReferenceComponent, the total number of calls to acquire() exceeds 53 the total number of calls to release() by a plattform dependent amount 54 (which, hopefully, is quite large). 55 */ 56 SD_DLLPUBLIC void acquire(); 57 SD_DLLPUBLIC void release(); 58 59 void Dispose(); 60 61 bool isDisposed() const { return mbDisposed; } 62 63 /** see general class documentation 64 */ 65 static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc)); 66 67 /** see general class documentation 68 */ 69 static void * operator new(std::size_t nSize, 70 std::nothrow_t const & rNothrow) 71 ; 72 73 /** see general class documentation 74 */ 75 static void operator delete(void * pPtr); 76 77 /** see general class documentation 78 */ 79 static void operator delete(void * pPtr, std::nothrow_t const & rNothrow) 80 ; 81 82 protected: 83 virtual void disposing(); 84 85 virtual ~SimpleReferenceComponent(); 86 87 private: 88 oslInterlockedCount m_nCount; 89 90 /** not implemented 91 @internal 92 */ 93 SimpleReferenceComponent(SimpleReferenceComponent &); 94 95 /** not implemented 96 @internal 97 */ 98 void operator =(SimpleReferenceComponent); 99 100 /** not implemented (see general class documentation) 101 @internal 102 */ 103 static void * operator new[](std::size_t); 104 105 /** not implemented (see general class documentation) 106 @internal 107 */ 108 static void operator delete[](void * pPtr); 109 110 bool mbDisposed; 111 }; 112 113 } 114 115 #endif // _SALHELPER_SimpleReferenceComponent_HXX_ 116