UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #ifndef _RTL_REF_HXX_ 00030 #define _RTL_REF_HXX_ 00031 00032 #include <sal/types.h> 00033 #include <osl/diagnose.h> 00034 #include <osl/interlck.h> 00035 00036 namespace rtl 00037 { 00038 00041 class IReference 00042 { 00043 public: 00046 virtual oslInterlockedCount SAL_CALL acquire() = 0; 00047 00050 virtual oslInterlockedCount SAL_CALL release() = 0; 00051 00052 #if !defined _MSC_VER // public -> protected changes mangled names there 00053 protected: 00054 #endif 00055 ~IReference() {} 00056 // avoid warnings about virtual members and non-virtual dtor 00057 }; 00058 00059 00062 template <class reference_type> 00063 class Reference 00064 { 00067 reference_type * m_pBody; 00068 00069 00070 public: 00073 inline Reference() 00074 : m_pBody (0) 00075 {} 00076 00077 00080 inline Reference (reference_type * pBody) 00081 : m_pBody (pBody) 00082 { 00083 if (m_pBody) 00084 m_pBody->acquire(); 00085 } 00086 00087 00090 inline Reference (const Reference<reference_type> & handle) 00091 : m_pBody (handle.m_pBody) 00092 { 00093 if (m_pBody) 00094 m_pBody->acquire(); 00095 } 00096 00097 00100 inline ~Reference() 00101 { 00102 if (m_pBody) 00103 m_pBody->release(); 00104 } 00105 00109 inline Reference<reference_type> & 00110 SAL_CALL set (reference_type * pBody) 00111 { 00112 if (pBody) 00113 pBody->acquire(); 00114 reference_type * const pOld = m_pBody; 00115 m_pBody = pBody; 00116 if (pOld) 00117 pOld->release(); 00118 return *this; 00119 } 00120 00125 inline Reference<reference_type> & 00126 SAL_CALL operator= (const Reference<reference_type> & handle) 00127 { 00128 return set( handle.m_pBody ); 00129 } 00130 00133 inline Reference<reference_type> & 00134 SAL_CALL operator= (reference_type * pBody) 00135 { 00136 return set( pBody ); 00137 } 00138 00146 inline Reference<reference_type> & SAL_CALL clear() 00147 { 00148 if (m_pBody) 00149 { 00150 reference_type * const pOld = m_pBody; 00151 m_pBody = 0; 00152 pOld->release(); 00153 } 00154 return *this; 00155 } 00156 00157 00162 inline reference_type * SAL_CALL get() const 00163 { 00164 return m_pBody; 00165 } 00166 00167 00170 inline reference_type * SAL_CALL operator->() const 00171 { 00172 OSL_PRECOND(m_pBody, "Reference::operator->() : null body"); 00173 return m_pBody; 00174 } 00175 00176 00179 inline reference_type & SAL_CALL operator*() const 00180 { 00181 OSL_PRECOND(m_pBody, "Reference::operator*() : null body"); 00182 return *m_pBody; 00183 } 00184 00185 00188 inline sal_Bool SAL_CALL is() const 00189 { 00190 return (m_pBody != 0); 00191 } 00192 00193 00196 inline sal_Bool SAL_CALL operator== (const reference_type * pBody) const 00197 { 00198 return (m_pBody == pBody); 00199 } 00200 00201 00204 inline sal_Bool 00205 SAL_CALL operator== (const Reference<reference_type> & handle) const 00206 { 00207 return (m_pBody == handle.m_pBody); 00208 } 00209 00210 00213 inline sal_Bool 00214 SAL_CALL operator!= (const Reference<reference_type> & handle) const 00215 { 00216 return (m_pBody != handle.m_pBody); 00217 } 00218 00219 00222 inline sal_Bool 00223 SAL_CALL operator< (const Reference<reference_type> & handle) const 00224 { 00225 return (m_pBody < handle.m_pBody); 00226 } 00227 00228 00231 inline sal_Bool 00232 SAL_CALL operator> (const Reference<reference_type> & handle) const 00233 { 00234 return (m_pBody > handle.m_pBody); 00235 } 00236 }; 00237 00239 00241 template <typename T> 00242 inline T * get_pointer( Reference<T> const& r ) 00243 { 00244 return r.get(); 00245 } 00247 00248 } // namespace rtl 00249 00250 #endif /* !_RTL_REF_HXX_ */ 00251 00252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */