LCOV - code coverage report
Current view: top level - svl/source/notify - lstner.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 29 39 74.4 %
Date: 2014-04-11 Functions: 10 15 66.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             : 
      20             : 
      21             : #include <tools/debug.hxx>
      22             : 
      23             : #include <svl/hint.hxx>
      24             : #include <svl/brdcst.hxx>
      25             : 
      26             : #include <svl/lstner.hxx>
      27             : #include <algorithm>
      28             : 
      29     4413795 : TYPEINIT0(SfxListener);
      30             : 
      31             : // simple ctor of class SfxListener
      32             : 
      33      935974 : SfxListener::SfxListener()
      34             : {
      35      935974 : }
      36             : 
      37             : // copy ctor of class SfxListener
      38             : 
      39           0 : SfxListener::SfxListener( const SfxListener &rListener )
      40             : {
      41           0 :     for ( sal_uInt16 n = 0; n < rListener.aBCs.size(); ++n )
      42           0 :         StartListening( *rListener.aBCs[n] );
      43           0 : }
      44             : 
      45             : // unregisters the SfxListener from its SfxBroadcasters
      46             : 
      47     1800150 : SfxListener::~SfxListener()
      48             : {
      49             :     // unregister at all remaining broadcasters
      50      927888 :     for ( sal_uInt16 nPos = 0; nPos < aBCs.size(); ++nPos )
      51             :     {
      52       27813 :         SfxBroadcaster *pBC = aBCs[nPos];
      53       27813 :         pBC->RemoveListener(*this);
      54             :     }
      55      900075 : }
      56             : 
      57             : 
      58             : // unregisters a specific SfxBroadcaster
      59             : 
      60       18349 : void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster )
      61             : {
      62       18349 :     aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
      63       18349 : }
      64             : 
      65             : 
      66             : // registers a specific SfxBroadcaster
      67             : 
      68      451230 : bool SfxListener::StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDups )
      69             : {
      70      451230 :     if ( !bPreventDups || !IsListening( rBroadcaster ) )
      71             :     {
      72      449195 :         rBroadcaster.AddListener(*this);
      73      449195 :         aBCs.push_back( &rBroadcaster );
      74             : 
      75             :         DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" );
      76      449195 :         return true;
      77             :     }
      78             : 
      79        2035 :     return false;
      80             : }
      81             : 
      82             : 
      83             : // unregisters a specific SfxBroadcaster
      84             : 
      85      370328 : bool SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bAllDups )
      86             : {
      87      370328 :     if ( !IsListening( rBroadcaster ) )
      88        2784 :         return false;
      89             : 
      90      367544 :     do
      91             :     {
      92      367544 :         rBroadcaster.RemoveListener(*this);
      93      367544 :         aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
      94             :     }
      95      367544 :     while ( bAllDups && IsListening( rBroadcaster ) );
      96      367544 :     return true;
      97             : }
      98             : 
      99             : 
     100             : // unregisters all Broadcasters
     101             : 
     102           0 : void SfxListener::EndListeningAll()
     103             : {
     104             :     // MI: bei Optimierung beachten: Seiteneffekte von RemoveListener beachten!
     105           0 :     while ( !aBCs.empty() )
     106             :     {
     107           0 :         SfxBroadcaster *pBC = aBCs.front();
     108           0 :         pBC->RemoveListener(*this);
     109           0 :         aBCs.pop_front();
     110             :     }
     111           0 : }
     112             : 
     113             : 
     114      482366 : bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const
     115             : {
     116      482366 :     return aBCs.end() != std::find( aBCs.begin(), aBCs.end(), &rBroadcaster );
     117             : }
     118             : 
     119             : 
     120             : // base implementation of notification handler
     121             : 
     122             : #ifdef DBG_UTIL
     123             : void SfxListener::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& )
     124             : #else
     125         503 : void SfxListener::Notify( SfxBroadcaster&, const SfxHint& )
     126             : #endif
     127             : {
     128             :     #ifdef DBG_UTIL
     129             :     DBG_ASSERT(aBCs.end() != std::find(aBCs.begin(), aBCs.end(), &rBroadcaster),
     130             :                 "notification from unregistered broadcaster" );
     131             :     #endif
     132         503 : }
     133             : 
     134             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10