LCOV - code coverage report
Current view: top level - include/cppuhelper - weakref.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 18 18 100.0 %
Date: 2014-11-03 Functions: 327 438 74.7 %
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/XInterface.hpp>
      23             : #include <cppuhelper/cppuhelperdllapi.h>
      24             : 
      25             : 
      26             : namespace com
      27             : {
      28             : namespace sun
      29             : {
      30             : namespace star
      31             : {
      32             : namespace uno
      33             : {
      34             : 
      35             : class OWeakRefListener;
      36             : 
      37             : /** The WeakReferenceHelper holds a weak reference to an object. This object must implement
      38             :     the com::sun::star::uno::XWeak interface.  The implementation is thread safe.
      39             : */
      40             : class CPPUHELPER_DLLPUBLIC WeakReferenceHelper
      41             : {
      42             : public:
      43             :     /** Default ctor.  Creates an empty weak reference.
      44             :     */
      45     2649800 :     inline WeakReferenceHelper()
      46     2649800 :         : m_pImpl( 0 )
      47     2649800 :         {}
      48             : 
      49             :     /** Copy ctor.  Initialize this reference with the same interface as in rWeakRef.
      50             : 
      51             :         @param rWeakRef another weak ref
      52             :     */
      53             :     WeakReferenceHelper( const WeakReferenceHelper & rWeakRef );
      54             :     /** Initialize this reference with the hard interface reference xInt. If the implementation
      55             :         behind xInt does not support XWeak or XInt is null then this reference will be null.
      56             : 
      57             :         @param xInt another hard interface reference
      58             :     */
      59             :     WeakReferenceHelper( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & xInt );
      60             :     /** Releases this reference.
      61             :     */
      62             :     ~WeakReferenceHelper();
      63             : 
      64             :     /** Releases this reference and takes over rWeakRef.
      65             : 
      66             :         @param rWeakRef another weak ref
      67             :     */
      68             :     WeakReferenceHelper & SAL_CALL operator = ( const WeakReferenceHelper & rWeakRef );
      69             : 
      70             :     /** Releases this reference and takes over hard reference xInt.
      71             :         If the implementation behind xInt does not support XWeak
      72             :         or XInt is null, then this reference is null.
      73             : 
      74             :         @param xInt another hard reference
      75             :     */
      76             :     WeakReferenceHelper & SAL_CALL operator = (
      77             :             const ::com::sun::star::uno::Reference<
      78             :                 ::com::sun::star::uno::XInterface > & xInt );
      79             : 
      80             :     /** Returns true if both weak refs reference to the same object.
      81             : 
      82             :         @param rObj another weak ref
      83             :         @return true, if both weak refs reference to the same object.
      84             :     */
      85      346508 :     inline bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const
      86      346508 :         { return (get() == rObj.get()); }
      87             : 
      88             :     /**  Gets a hard reference to the object.
      89             : 
      90             :          @return hard reference or null, if the weakly referenced interface has gone
      91             :     */
      92             :     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL get() const;
      93             :     /**  Gets a hard reference to the object.
      94             : 
      95             :          @return hard reference or null, if the weakly referenced interface has gone
      96             :     */
      97    59629821 :     inline SAL_CALL operator Reference< XInterface > () const
      98    59629821 :         { return get(); }
      99             : 
     100             :     /** Releases this reference.
     101             : 
     102             :         @since UDK 3.2.12
     103             :     */
     104             :     void SAL_CALL clear();
     105             : 
     106             : protected:
     107             :     /// @cond INTERNAL
     108             :     OWeakRefListener * m_pImpl;
     109             :     /// @endcond
     110             : };
     111             : 
     112             : /** The WeakReference<> holds a weak reference to an object. This object must implement
     113             :     the com::sun::star::uno::XWeak interface.  The implementation is thread safe.
     114             : 
     115             :     @tparam interface_type type of interface
     116             : */
     117             : template< class interface_type >
     118    20184235 : class WeakReference : public WeakReferenceHelper
     119             : {
     120             : public:
     121             :     /** Default ctor.  Creates an empty weak reference.
     122             :     */
     123     2041502 :     inline WeakReference()
     124     2041502 :         : WeakReferenceHelper()
     125     2041502 :         {}
     126             : 
     127             :     /** Copy ctor.  Initialize this reference with a hard reference.
     128             : 
     129             :         @param rRef another hard ref
     130             :     */
     131     2675301 :     inline WeakReference( const Reference< interface_type > & rRef )
     132     2675301 :         : WeakReferenceHelper( rRef )
     133     2675301 :         {}
     134             : 
     135             :     /** Releases this reference and takes over hard reference xInt.
     136             :         If the implementation behind xInt does not support XWeak
     137             :         or XInt is null, then this reference is null.
     138             : 
     139             :         @param xInt another hard reference
     140             : 
     141             :         @since UDK 3.2.12
     142             :     */
     143      878707 :     WeakReference & SAL_CALL operator = (
     144             :             const ::com::sun::star::uno::Reference< interface_type > & xInt )
     145      878707 :         { WeakReferenceHelper::operator=(xInt); return *this; }
     146             : 
     147             :     /**  Gets a hard reference to the object.
     148             : 
     149             :          @return hard reference or null, if the weakly referenced interface has gone
     150             :     */
     151     4486944 :     inline SAL_CALL operator Reference< interface_type > () const
     152     4486944 :         { return Reference< interface_type >::query( get() ); }
     153             : };
     154             : 
     155             : }
     156             : }
     157             : }
     158             : }
     159             : 
     160             : #endif
     161             : 
     162             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10