LCOV - code coverage report
Current view: top level - include/cppuhelper - weakref.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 5 18 27.8 %
Date: 2014-04-14 Functions: 2 431 0.5 %
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           5 :     inline WeakReferenceHelper() SAL_THROW(())
      46           5 :         : m_pImpl( 0 )
      47           5 :         {}
      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 ) SAL_THROW(());
      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             :         SAL_THROW(());
      61             :     /** Releases this reference.
      62             :     */
      63             :     ~WeakReferenceHelper() SAL_THROW(());
      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 ) SAL_THROW(());
      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 ) SAL_THROW(());
      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           0 :     inline bool SAL_CALL operator == ( const WeakReferenceHelper & rObj ) const SAL_THROW(())
      87           0 :         { 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 SAL_THROW(());
      94             :     /**  Gets a hard reference to the object.
      95             : 
      96             :          @return hard reference or null, if the weakly referenced interface has gone
      97             :     */
      98         186 :     inline SAL_CALL operator Reference< XInterface > () const SAL_THROW(())
      99         186 :         { return get(); }
     100             : 
     101             :     /** Releases this reference.
     102             : 
     103             :         @since UDK 3.2.12
     104             :     */
     105             :     void SAL_CALL clear() SAL_THROW(());
     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           0 : class WeakReference : public WeakReferenceHelper
     120             : {
     121             : public:
     122             :     /** Default ctor.  Creates an empty weak reference.
     123             :     */
     124           0 :     inline WeakReference() SAL_THROW(())
     125           0 :         : WeakReferenceHelper()
     126           0 :         {}
     127             : 
     128             :     /** Copy ctor.  Initialize this reference with a hard reference.
     129             : 
     130             :         @param rRef another hard ref
     131             :     */
     132           0 :     inline WeakReference( const Reference< interface_type > & rRef ) SAL_THROW(())
     133           0 :         : WeakReferenceHelper( rRef )
     134           0 :         {}
     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           0 :     WeakReference & SAL_CALL operator = (
     145             :             const ::com::sun::star::uno::Reference< interface_type > & xInt )
     146             :         SAL_THROW(())
     147           0 :         { WeakReferenceHelper::operator=(xInt); return *this; }
     148             : 
     149             :     /**  Gets a hard reference to the object.
     150             : 
     151             :          @return hard reference or null, if the weakly referenced interface has gone
     152             :     */
     153           0 :     inline SAL_CALL operator Reference< interface_type > () const SAL_THROW(())
     154           0 :         { return Reference< interface_type >::query( get() ); }
     155             : };
     156             : 
     157             : }
     158             : }
     159             : }
     160             : }
     161             : 
     162             : #endif
     163             : 
     164             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10