LCOV - code coverage report
Current view: top level - include/cppuhelper - weakref.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 18 18 100.0 %
Date: 2015-06-13 12:38:46 Functions: 331 434 76.3 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_CPPUHELPER_WEAKREF_HXX
      20             : #define INCLUDED_CPPUHELPER_WEAKREF_HXX
      21             : 
      22             : #include <com/sun/star/uno/Reference.hxx>
      23             : #include <com/sun/star/uno/XInterface.hpp>
      24             : #include <cppuhelper/cppuhelperdllapi.h>
      25             : 
      26             : 
      27             : namespace com
      28             : {
      29             : namespace sun
      30             : {
      31             : namespace star
      32             : {
      33             : namespace uno
      34             : {
      35             : 
      36             : class OWeakRefListener;
      37             : 
      38             : /** The WeakReferenceHelper holds a weak reference to an object. This object must implement
      39             :     the com::sun::star::uno::XWeak interface.  The implementation is thread safe.
      40             : */
      41             : class CPPUHELPER_DLLPUBLIC WeakReferenceHelper
      42             : {
      43             : public:
      44             :     /** Default ctor.  Creates an empty weak reference.
      45             :     */
      46     2088036 :     inline WeakReferenceHelper()
      47     2088036 :         : m_pImpl( 0 )
      48     2088036 :         {}
      49             : 
      50             :     /** Copy ctor.  Initialize this reference with the same interface as in rWeakRef.
      51             : 
      52             :         @param rWeakRef another weak ref
      53             :     */
      54             :     WeakReferenceHelper( const WeakReferenceHelper & rWeakRef );
      55             :     /** Initialize this reference with the hard interface reference xInt. If the implementation
      56             :         behind xInt does not support XWeak or XInt is null then this reference will be null.
      57             : 
      58             :         @param xInt another hard interface reference
      59             :     */
      60             :     WeakReferenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & xInt );
      61             :     /** Releases this reference.
      62             :     */
      63             :     ~WeakReferenceHelper();
      64             : 
      65             :     /** Releases this reference and takes over rWeakRef.
      66             : 
      67             :         @param rWeakRef another weak ref
      68             :     */
      69             :     WeakReferenceHelper & SAL_CALL operator = ( const WeakReferenceHelper & rWeakRef );
      70             : 
      71             :     /** Releases this reference and takes over hard reference xInt.
      72             :         If the implementation behind xInt does not support XWeak
      73             :         or XInt is null, then this reference is null.
      74             : 
      75             :         @param xInt another hard reference
      76             :     */
      77             :     WeakReferenceHelper & SAL_CALL operator = (
      78             :             const ::com::sun::star::uno::Reference<
      79             :                 ::com::sun::star::uno::XInterface > & xInt );
      80             : 
      81             :     /** Returns true if both weak refs reference to the same object.
      82             : 
      83             :         @param rObj another weak ref
      84             :         @return true, if both weak refs reference to the same object.
      85             :     */
      86      191062 :     inline bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const
      87      191062 :         { return (get() == rObj.get()); }
      88             : 
      89             :     /**  Gets a hard reference to the object.
      90             : 
      91             :          @return hard reference or null, if the weakly referenced interface has gone
      92             :     */
      93             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL get() const;
      94             :     /**  Gets a hard reference to the object.
      95             : 
      96             :          @return hard reference or null, if the weakly referenced interface has gone
      97             :     */
      98    43491622 :     inline SAL_CALL operator Reference< XInterface > () const
      99    43491622 :         { return get(); }
     100             : 
     101             :     /** Releases this reference.
     102             : 
     103             :         @since UDK 3.2.12
     104             :     */
     105             :     void SAL_CALL clear();
     106             : 
     107             : protected:
     108             :     /// @cond INTERNAL
     109             :     OWeakRefListener * m_pImpl;
     110             :     /// @endcond
     111             : };
     112             : 
     113             : /** The WeakReference<> holds a weak reference to an object. This object must implement
     114             :     the com::sun::star::uno::XWeak interface.  The implementation is thread safe.
     115             : 
     116             :     @tparam interface_type type of interface
     117             : */
     118             : template< class interface_type >
     119    11918744 : class WeakReference : public WeakReferenceHelper
     120             : {
     121             : public:
     122             :     /** Default ctor.  Creates an empty weak reference.
     123             :     */
     124     1631358 :     inline WeakReference()
     125     1631358 :         : WeakReferenceHelper()
     126     1631358 :         {}
     127             : 
     128             :     /** Copy ctor.  Initialize this reference with a hard reference.
     129             : 
     130             :         @param rRef another hard ref
     131             :     */
     132     1503307 :     inline WeakReference( const Reference< interface_type > & rRef )
     133     1503307 :         : WeakReferenceHelper( rRef )
     134     1503307 :         {}
     135             : 
     136             :     /** Releases this reference and takes over hard reference xInt.
     137             :         If the implementation behind xInt does not support XWeak
     138             :         or XInt is null, then this reference is null.
     139             : 
     140             :         @param xInt another hard reference
     141             : 
     142             :         @since UDK 3.2.12
     143             :     */
     144      623362 :     WeakReference & SAL_CALL operator = (
     145             :             const ::com::sun::star::uno::Reference< interface_type > & xInt )
     146      623362 :         { WeakReferenceHelper::operator=(xInt); return *this; }
     147             : 
     148             :     /**  Gets a hard reference to the object.
     149             : 
     150             :          @return hard reference or null, if the weakly referenced interface has gone
     151             :     */
     152     3665989 :     inline SAL_CALL operator Reference< interface_type > () const
     153     3665989 :         { return Reference< interface_type >::query( get() ); }
     154             : };
     155             : 
     156             : }
     157             : }
     158             : }
     159             : }
     160             : 
     161             : #endif
     162             : 
     163             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11