1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 27 #ifndef _SALHELPER_SIMPLEREFERENCECOMPONENT_HXX_ 28 #include "helper/simplereferencecomponent.hxx" 29 #endif 30 31 #include "com/sun/star/uno/RuntimeException.hpp" 32 #include "osl/diagnose.h" 33 34 #ifndef INCLUDED_NEW 35 #include <new> 36 #define INCLUDED_NEW 37 #endif 38 39 using com::sun::star::uno::RuntimeException; 40 using sd::SimpleReferenceComponent; 41 42 SimpleReferenceComponent::SimpleReferenceComponent() 43 : m_nCount(0) 44 , mbDisposed(false) 45 { 46 } 47 48 SimpleReferenceComponent::~SimpleReferenceComponent() 49 { 50 OSL_ASSERT(m_nCount == 0); 51 OSL_ASSERT(mbDisposed); 52 } 53 54 void SimpleReferenceComponent::acquire() 55 { 56 osl_incrementInterlockedCount(&m_nCount); 57 } 58 59 void SimpleReferenceComponent::release() 60 { 61 if((1 == m_nCount) && !mbDisposed) 62 { 63 try 64 { 65 Dispose(); 66 } 67 catch (RuntimeException & 68 #if OSL_DEBUG_LEVEL > 0 69 exc 70 #endif 71 ) // don't break throw () 72 { 73 #if OSL_DEBUG_LEVEL > 0 74 rtl::OString msg( rtl::OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) ); 75 OSL_ENSURE( 0, msg.getStr() ); 76 #endif 77 } 78 } 79 80 if(osl_decrementInterlockedCount(&m_nCount) == 0) delete this; 81 } 82 83 void SimpleReferenceComponent::Dispose() 84 { 85 if( !mbDisposed ) 86 { 87 mbDisposed = true; 88 disposing(); 89 } 90 } 91 92 void SimpleReferenceComponent::disposing() 93 { 94 } 95 96 void * SimpleReferenceComponent::operator new(std::size_t nSize) 97 SAL_THROW((std::bad_alloc)) 98 { 99 return ::operator new(nSize); 100 } 101 102 void * SimpleReferenceComponent::operator new(std::size_t nSize, 103 std::nothrow_t const & 104 #ifndef WNT 105 rNothrow 106 #endif 107 ) 108 SAL_THROW(()) 109 { 110 #if defined WNT 111 return ::operator new(nSize); 112 // WNT lacks a global nothrow operator new... 113 #else // WNT 114 return ::operator new(nSize, rNothrow); 115 #endif // WNT 116 } 117 118 void SimpleReferenceComponent::operator delete(void * pPtr) SAL_THROW(()) 119 { 120 ::operator delete(pPtr); 121 } 122 123 void SimpleReferenceComponent::operator delete(void * pPtr, 124 std::nothrow_t const & 125 #ifndef WNT 126 rNothrow 127 #endif 128 ) 129 SAL_THROW(()) 130 { 131 #if defined WNT 132 ::operator delete(pPtr); // WNT lacks a global nothrow operator delete... 133 #else // WNT 134 ::operator delete(pPtr, rNothrow); 135 #endif // WNT 136 } 137