1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: smartpointer.hxx,v $
9 * last change: $Author: mav $ $Date: 2008/10/30 11:59:06 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
34 ************************************************************************/
36 #ifndef _INPROCSERV_SMARTPOINTER_HXX_
37 #define _INPROCSERV_SMARTPOINTER_HXX_
42 #define WRITEDEBUGINFOINTERN( x ) WriteDebugInfo( (DWORD)this, x, sizeof( x ) )
43 #define WRITEDEBUGINFO( x ) WRITEDEBUGINFOINTERN( x ":" MY_STRING_LINE "\n" )
44 #define TO_STRING( x ) #x
45 #define MACRO_VALUE_TO_STRING( x ) TO_STRING( x )
46 #define MY_STRING_LINE MACRO_VALUE_TO_STRING( __LINE__ )
48 #define WRITEDEBUGINFO( x ) void()
49 #define MY_STRING_LINE
55 void WriteDebugInfo( DWORD pThis
, char* pString
, DWORD nToWrite
);
57 template< class T
> class ComSmart
65 T
* pInterface
= m_pInterface
;
67 pInterface
->Release();
73 : m_pInterface( NULL
)
76 ComSmart( const ComSmart
<T
>& rObj
)
77 : m_pInterface( rObj
.m_pInterface
)
79 if ( m_pInterface
!= NULL
)
80 m_pInterface
->AddRef();
83 ComSmart( T
* pInterface
)
84 : m_pInterface( pInterface
)
86 if ( m_pInterface
!= NULL
)
87 m_pInterface
->AddRef();
95 ComSmart
& operator=( const ComSmart
<T
>& rObj
)
99 m_pInterface
= rObj
.m_pInterface
;
101 if ( m_pInterface
!= NULL
)
102 m_pInterface
->AddRef();
107 ComSmart
<T
>& operator=( T
* pInterface
)
111 m_pInterface
= pInterface
;
113 if ( m_pInterface
!= NULL
)
114 m_pInterface
->AddRef();
126 return *m_pInterface
;
135 return &m_pInterface
;
138 T
* operator->() const
143 BOOL
operator==( const ComSmart
<T
>& rObj
) const
145 return ( m_pInterface
== rObj
.m_pInterface
);
148 BOOL
operator!=( const ComSmart
<T
>& rObj
) const
150 return ( m_pInterface
!= rObj
.m_pInterface
);
153 BOOL
operator==( const T
* pInterface
) const
155 return ( m_pInterface
== pInterface
);
158 BOOL
operator!=( const T
* pInterface
) const
160 return ( m_pInterface
!= pInterface
);
166 CRITICAL_SECTION
* m_pCriticalSection
;
169 CSGuard( CRITICAL_SECTION
* pCS
)
170 : m_pCriticalSection( pCS
)
172 if ( m_pCriticalSection
)
173 EnterCriticalSection( m_pCriticalSection
);
178 if ( m_pCriticalSection
)
179 LeaveCriticalSection( m_pCriticalSection
);
188 ULONGGuard( ULONG
* pValue
)
202 } // namespace inprocserv