LCOV - code coverage report
Current view: top level - svl/source/notify - lstner.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 43 44 97.7 %
Date: 2015-06-13 12:38:46 Functions: 16 19 84.2 %
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             : #include <svl/lstner.hxx>
      21             : 
      22             : #include <svl/hint.hxx>
      23             : #include <svl/SfxBroadcaster.hxx>
      24             : 
      25             : #include <algorithm>
      26             : #include <cassert>
      27             : #include <deque>
      28             : 
      29    10341009 : TYPEINIT0(SfxListener);
      30             : 
      31             : typedef std::deque<SfxBroadcaster*> SfxBroadcasterArr_Impl;
      32             : 
      33     3376251 : struct SfxListener::Impl
      34             : {
      35             :     SfxBroadcasterArr_Impl maBCs;
      36             : };
      37             : 
      38             : // simple ctor of class SfxListener
      39             : 
      40     1693069 : SfxListener::SfxListener() : mpImpl(new Impl)
      41             : {
      42     1693069 : }
      43             : 
      44             : // copy ctor of class SfxListener
      45             : 
      46           2 : SfxListener::SfxListener( const SfxListener &rListener ) : mpImpl(new Impl)
      47             : {
      48           2 :     for ( size_t n = 0; n < rListener.mpImpl->maBCs.size(); ++n )
      49           0 :         StartListening( *rListener.mpImpl->maBCs[n] );
      50           2 : }
      51             : 
      52             : // unregisters the SfxListener from its SfxBroadcasters
      53             : 
      54     1683180 : SfxListener::~SfxListener()
      55             : {
      56             :     // unregister at all remaining broadcasters
      57     1738102 :     for ( size_t nPos = 0; nPos < mpImpl->maBCs.size(); ++nPos )
      58             :     {
      59       54922 :         SfxBroadcaster *pBC = mpImpl->maBCs[nPos];
      60       54922 :         pBC->RemoveListener(*this);
      61             :     }
      62             : 
      63     1683180 :     delete mpImpl;
      64     1683180 : }
      65             : 
      66             : 
      67             : // unregisters a specific SfxBroadcaster
      68             : 
      69       37858 : void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBroadcaster )
      70             : {
      71       37858 :     mpImpl->maBCs.erase( std::find( mpImpl->maBCs.begin(), mpImpl->maBCs.end(), &rBroadcaster ) );
      72       37858 : }
      73             : 
      74             : 
      75             : // registers a specific SfxBroadcaster
      76             : 
      77      807465 : void SfxListener::StartListening( SfxBroadcaster& rBroadcaster, bool bPreventDups )
      78             : {
      79      807465 :     if ( !bPreventDups || !IsListening( rBroadcaster ) )
      80             :     {
      81      804221 :         rBroadcaster.AddListener(*this);
      82      804221 :         mpImpl->maBCs.push_back( &rBroadcaster );
      83             : 
      84             :         assert(IsListening(rBroadcaster) && "StartListening failed");
      85             :     }
      86      807465 : }
      87             : 
      88             : 
      89             : // unregisters a specific SfxBroadcaster
      90             : 
      91      822151 : void SfxListener::EndListening( SfxBroadcaster& rBroadcaster, bool bAllDups )
      92             : {
      93      700826 :     do
      94             :     {
      95      822151 :         SfxBroadcasterArr_Impl::iterator it = std::find( mpImpl->maBCs.begin(), mpImpl->maBCs.end(), &rBroadcaster );
      96      822151 :         if ( it == mpImpl->maBCs.end() )
      97             :         {
      98      121325 :             break;
      99             :         }
     100      700826 :         rBroadcaster.RemoveListener(*this);
     101      700826 :         mpImpl->maBCs.erase( it );
     102             :     }
     103             :     while ( bAllDups );
     104      706910 : }
     105             : 
     106             : 
     107             : // unregisters all Broadcasters
     108             : 
     109      166706 : void SfxListener::EndListeningAll()
     110             : {
     111             :     // Attention: when optimizing this: Respect sideffects of RemoveListener!
     112      333673 :     while ( !mpImpl->maBCs.empty() )
     113             :     {
     114         261 :         SfxBroadcaster *pBC = mpImpl->maBCs.front();
     115         261 :         pBC->RemoveListener(*this);
     116         261 :         mpImpl->maBCs.pop_front();
     117             :     }
     118      166706 : }
     119             : 
     120             : 
     121      133742 : bool SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const
     122             : {
     123      133742 :     return mpImpl->maBCs.end() != std::find( mpImpl->maBCs.begin(), mpImpl->maBCs.end(), &rBroadcaster );
     124             : }
     125             : 
     126       20965 : sal_uInt16 SfxListener::GetBroadcasterCount() const
     127             : {
     128       20965 :     return mpImpl->maBCs.size();
     129             : }
     130             : 
     131         862 : SfxBroadcaster* SfxListener::GetBroadcasterJOE( sal_uInt16 nNo ) const
     132             : {
     133         862 :     return mpImpl->maBCs[nNo];
     134             : }
     135             : 
     136             : 
     137             : // base implementation of notification handler
     138             : 
     139         516 : void SfxListener::Notify( SfxBroadcaster& rBroadcaster, const SfxHint& )
     140             : {
     141             :     (void) rBroadcaster;
     142             :     assert(IsListening(rBroadcaster));
     143         516 : }
     144             : 
     145             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11