LCOV - code coverage report
Current view: top level - svl/source/notify - lstner.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 27 39 69.2 %
Date: 2012-08-25 Functions: 9 15 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 25 46 54.3 %

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