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
SimpleReferenceComponent()42 SimpleReferenceComponent::SimpleReferenceComponent()
43 : m_nCount(0)
44 , mbDisposed(false)
45 {
46 }
47
~SimpleReferenceComponent()48 SimpleReferenceComponent::~SimpleReferenceComponent()
49 {
50 OSL_ASSERT(m_nCount == 0);
51 OSL_ASSERT(mbDisposed);
52 }
53
acquire()54 void SimpleReferenceComponent::acquire()
55 {
56 osl_incrementInterlockedCount(&m_nCount);
57 }
58
release()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
Dispose()83 void SimpleReferenceComponent::Dispose()
84 {
85 if( !mbDisposed )
86 {
87 mbDisposed = true;
88 disposing();
89 }
90 }
91
disposing()92 void SimpleReferenceComponent::disposing()
93 {
94 }
95
operator new(std::size_t nSize)96 void * SimpleReferenceComponent::operator new(std::size_t nSize)
97 {
98 return ::operator new(nSize);
99 }
100
operator new(std::size_t nSize,std::nothrow_t const & rNothrow)101 void * SimpleReferenceComponent::operator new(std::size_t nSize,
102 std::nothrow_t const &
103 #ifndef WNT
104 rNothrow
105 #endif
106 )
107 SAL_THROW(())
108 {
109 #if defined WNT
110 return ::operator new(nSize);
111 // WNT lacks a global nothrow operator new...
112 #else // WNT
113 return ::operator new(nSize, rNothrow);
114 #endif // WNT
115 }
116
operator delete(void * pPtr)117 void SimpleReferenceComponent::operator delete(void * pPtr) SAL_THROW(())
118 {
119 ::operator delete(pPtr);
120 }
121
operator delete(void * pPtr,std::nothrow_t const & rNothrow)122 void SimpleReferenceComponent::operator delete(void * pPtr,
123 std::nothrow_t const &
124 #ifndef WNT
125 rNothrow
126 #endif
127 )
128 SAL_THROW(())
129 {
130 #if defined WNT
131 ::operator delete(pPtr); // WNT lacks a global nothrow operator delete...
132 #else // WNT
133 ::operator delete(pPtr, rNothrow);
134 #endif // WNT
135 }
136