LCOV - code coverage report
Current view: top level - svl/source/notify - listener.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 25 30 83.3 %
Date: 2014-04-11 Functions: 6 10 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             : #include <svl/listener.hxx>
      21             : #include <svl/broadcast.hxx>
      22             : #include <tools/debug.hxx>
      23             : 
      24        9542 : SvtListener::SvtListener() {}
      25             : 
      26           0 : SvtListener::SvtListener( const SvtListener &r ) :
      27           0 :     maBroadcasters(r.maBroadcasters) {}
      28             : 
      29       17754 : SvtListener::~SvtListener()
      30             : {
      31             :     // Unregister itself from all broadcasters it's listening to.
      32        8877 :     EndListeningAll();
      33        8877 : }
      34             : 
      35             : // registeres at a specific SvtBroadcaster
      36             : 
      37       20349 : bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
      38             : {
      39             :     std::pair<BroadcastersType::iterator, bool> r =
      40       20349 :         maBroadcasters.insert(&rBroadcaster);
      41       20349 :     if (r.second)
      42             :     {
      43             :         // This is a new broadcaster.
      44       12829 :         rBroadcaster.Add(this);
      45             :     }
      46       20349 :     return r.second;
      47             : }
      48             : 
      49        4653 : bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
      50             : {
      51        4653 :     BroadcastersType::iterator it = maBroadcasters.find(&rBroadcaster);
      52        4653 :     if (it == maBroadcasters.end())
      53             :         // Not listening to this broadcaster.
      54         388 :         return false;
      55             : 
      56        4265 :     rBroadcaster.Remove(this);
      57        4265 :     maBroadcasters.erase(it);
      58        4265 :     return true;
      59             : }
      60             : 
      61       11918 : void SvtListener::EndListeningAll()
      62             : {
      63       11918 :     BroadcastersType::iterator it = maBroadcasters.begin(), itEnd = maBroadcasters.end();
      64       20062 :     for (; it != itEnd; ++it)
      65             :     {
      66        8144 :         SvtBroadcaster& rBC = **it;
      67        8144 :         rBC.Remove(this);
      68             :     }
      69       11918 :     maBroadcasters.clear();
      70       11918 : }
      71             : 
      72             : 
      73           0 : bool SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const
      74             : {
      75           0 :     return maBroadcasters.count(&rBroadcaster) > 0;
      76             : }
      77             : 
      78          81 : bool SvtListener::HasBroadcaster() const
      79             : {
      80          81 :     return !maBroadcasters.empty();
      81             : }
      82             : 
      83           0 : void SvtListener::Notify( const SfxHint& ) {}
      84             : 
      85             : 
      86             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10