LCOV - code coverage report
Current view: top level - libreoffice/svl/source/notify - lstner.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 39 69.2 %
Date: 2012-12-17 Functions: 9 15 60.0 %
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             : //====================================================================
      30             : DBG_NAME(SfxListener)
      31      491102 : TYPEINIT0(SfxListener);
      32             : 
      33             : //====================================================================
      34             : // simple ctor of class SfxListener
      35             : 
      36      149224 : SfxListener::SfxListener()
      37             : {
      38             :     DBG_CTOR(SfxListener, 0);
      39      149224 : }
      40             : //--------------------------------------------------------------------
      41             : 
      42             : // copy ctor of class SfxListener
      43             : 
      44           0 : SfxListener::SfxListener( const SfxListener &rListener )
      45             : {
      46             :     DBG_CTOR(SfxListener, 0);
      47             : 
      48           0 :     for ( sal_uInt16 n = 0; n < rListener.aBCs.size(); ++n )
      49           0 :         StartListening( *rListener.aBCs[n] );
      50           0 : }
      51             : //--------------------------------------------------------------------
      52             : 
      53             : // unregisters the SfxListener from its SfxBroadcasters
      54             : 
      55      271976 : SfxListener::~SfxListener()
      56             : {
      57             :     DBG_DTOR(SfxListener, 0);
      58             : 
      59             :     // unregister at all remaining broadcasters
      60      139132 :     for ( sal_uInt16 nPos = 0; nPos < aBCs.size(); ++nPos )
      61             :     {
      62        3144 :         SfxBroadcaster *pBC = aBCs[nPos];
      63        3144 :         pBC->RemoveListener(*this);
      64             :     }
      65      135988 : }
      66             : 
      67             : //--------------------------------------------------------------------
      68             : 
      69             : // unregisters a specific SfxBroadcaster
      70             : 
      71        5126 : void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster )
      72             : {
      73             :     DBG_CHKTHIS(SfxListener, 0);
      74             : 
      75        5126 :     aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
      76        5126 : }
      77             : 
      78             : //--------------------------------------------------------------------
      79             : 
      80             : // registers a specific SfxBroadcaster
      81             : 
      82      116637 : sal_Bool SfxListener::StartListening( SfxBroadcaster& rBroadcaster, sal_Bool bPreventDups )
      83             : {
      84             :     DBG_CHKTHIS(SfxListener, 0);
      85             : 
      86      116637 :     if ( !bPreventDups || !IsListening( rBroadcaster ) )
      87             :     {
      88      116129 :         rBroadcaster.AddListener(*this);
      89      116129 :         aBCs.push_back( &rBroadcaster );
      90             : 
      91             :         DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" );
      92      116129 :         return sal_True;
      93             :     }
      94             : 
      95         508 :     return sal_False;
      96             : }
      97             : 
      98             : //--------------------------------------------------------------------
      99             : 
     100             : // unregisters a specific SfxBroadcaster
     101             : 
     102       95587 : sal_Bool SfxListener::EndListening( SfxBroadcaster& rBroadcaster, sal_Bool bAllDups )
     103             : {
     104             :     DBG_CHKTHIS(SfxListener, 0);
     105             : 
     106       95587 :     if ( !IsListening( rBroadcaster ) )
     107        1578 :         return sal_False;
     108             : 
     109      106447 :     do
     110             :     {
     111       94009 :         rBroadcaster.RemoveListener(*this);
     112       94009 :         aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
     113             :     }
     114       12438 :     while ( bAllDups && IsListening( rBroadcaster ) );
     115       94009 :     return sal_True;
     116             : }
     117             : 
     118             : //--------------------------------------------------------------------
     119             : 
     120             : // unregisters all Broadcasters
     121             : 
     122           0 : void SfxListener::EndListeningAll()
     123             : {
     124             :     DBG_CHKTHIS(SfxListener, 0);
     125             : 
     126             :     // MI: bei Optimierung beachten: Seiteneffekte von RemoveListener beachten!
     127           0 :     while ( !aBCs.empty() )
     128             :     {
     129           0 :         SfxBroadcaster *pBC = aBCs.front();
     130           0 :         pBC->RemoveListener(*this);
     131           0 :         aBCs.pop_front();
     132             :     }
     133           0 : }
     134             : 
     135             : //--------------------------------------------------------------------
     136             : 
     137      127289 : sal_Bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const
     138             : {
     139      127289 :     return aBCs.end() != std::find( aBCs.begin(), aBCs.end(), &rBroadcaster );
     140             : }
     141             : 
     142             : //--------------------------------------------------------------------
     143             : 
     144             : // base implementation of notification handler
     145             : 
     146             : #ifdef DBG_UTIL
     147             : void SfxListener::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& )
     148             : #else
     149           0 : void SfxListener::Notify( SfxBroadcaster&, const SfxHint& )
     150             : #endif
     151             : {
     152             :     #ifdef DBG_UTIL
     153             :     DBG_ASSERT(aBCs.end() != std::find(aBCs.begin(), aBCs.end(), &rBroadcaster),
     154             :                 "notification from unregistered broadcaster" );
     155             :     #endif
     156           0 : }
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10