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-27 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      240765 : TYPEINIT0(SfxListener);
      32             : 
      33             : //====================================================================
      34             : // simple ctor of class SfxListener
      35             : 
      36       70565 : SfxListener::SfxListener()
      37             : {
      38             :     DBG_CTOR(SfxListener, 0);
      39       70565 : }
      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      129692 : SfxListener::~SfxListener()
      56             : {
      57             :     DBG_DTOR(SfxListener, 0);
      58             : 
      59             :     // unregister at all remaining broadcasters
      60       66460 :     for ( sal_uInt16 nPos = 0; nPos < aBCs.size(); ++nPos )
      61             :     {
      62        1614 :         SfxBroadcaster *pBC = aBCs[nPos];
      63        1614 :         pBC->RemoveListener(*this);
      64             :     }
      65       64846 : }
      66             : 
      67             : //--------------------------------------------------------------------
      68             : 
      69             : // unregisters a specific SfxBroadcaster
      70             : 
      71        2297 : void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster )
      72             : {
      73             :     DBG_CHKTHIS(SfxListener, 0);
      74             : 
      75        2297 :     aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
      76        2297 : }
      77             : 
      78             : //--------------------------------------------------------------------
      79             : 
      80             : // registers a specific SfxBroadcaster
      81             : 
      82       54815 : sal_Bool SfxListener::StartListening( SfxBroadcaster& rBroadcaster, sal_Bool bPreventDups )
      83             : {
      84             :     DBG_CHKTHIS(SfxListener, 0);
      85             : 
      86       54815 :     if ( !bPreventDups || !IsListening( rBroadcaster ) )
      87             :     {
      88       54579 :         rBroadcaster.AddListener(*this);
      89       54579 :         aBCs.push_back( &rBroadcaster );
      90             : 
      91             :         DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" );
      92       54579 :         return sal_True;
      93             :     }
      94             : 
      95         236 :     return sal_False;
      96             : }
      97             : 
      98             : //--------------------------------------------------------------------
      99             : 
     100             : // unregisters a specific SfxBroadcaster
     101             : 
     102       45380 : sal_Bool SfxListener::EndListening( SfxBroadcaster& rBroadcaster, sal_Bool bAllDups )
     103             : {
     104             :     DBG_CHKTHIS(SfxListener, 0);
     105             : 
     106       45380 :     if ( !IsListening( rBroadcaster ) )
     107         789 :         return sal_False;
     108             : 
     109       50065 :     do
     110             :     {
     111       44591 :         rBroadcaster.RemoveListener(*this);
     112       44591 :         aBCs.erase( std::find( aBCs.begin(), aBCs.end(), &rBroadcaster ) );
     113             :     }
     114        5474 :     while ( bAllDups && IsListening( rBroadcaster ) );
     115       44591 :     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       59323 : sal_Bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const
     138             : {
     139       59323 :     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