LCOV - code coverage report
Current view: top level - svx/source/sdr/event - eventhandler.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 49 0.0 %
Date: 2014-11-03 Functions: 0 16 0.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 "eventhandler.hxx"
      21             : 
      22             : // for SOLARIS compiler include of algorithm part of _STL is necessary to
      23             : // get access to basic algos like ::std::find
      24             : #include <algorithm>
      25             : #include <tools/debug.hxx>
      26             : 
      27             : namespace sdr
      28             : {
      29             :     namespace event
      30             :     {
      31           0 :         BaseEvent::BaseEvent(EventHandler& rEventHandler)
      32           0 :         :   mrEventHandler(rEventHandler)
      33             :         {
      34           0 :             mrEventHandler.AddEvent(*this);
      35           0 :         }
      36             : 
      37           0 :         BaseEvent::~BaseEvent()
      38             :         {
      39           0 :             mrEventHandler.RemoveEvent(*this);
      40           0 :         }
      41             :     } // end of namespace mixer
      42             : } // end of namespace sdr
      43             : 
      44             : 
      45             : 
      46             : namespace sdr
      47             : {
      48             :     namespace event
      49             :     {
      50           0 :         void EventHandler::AddEvent(BaseEvent& rBaseEvent)
      51             :         {
      52           0 :             maVector.push_back(&rBaseEvent);
      53           0 :         }
      54             : 
      55           0 :         void EventHandler::RemoveEvent(BaseEvent& rBaseEvent)
      56             :         {
      57           0 :             if(maVector.back() == &rBaseEvent)
      58             :             {
      59             :                 // the one to remove is the last, pop
      60           0 :                 maVector.pop_back();
      61             :             }
      62             :             else
      63             :             {
      64             :                 const BaseEventVector::iterator aFindResult = ::std::find(
      65           0 :                     maVector.begin(), maVector.end(), &rBaseEvent);
      66             :                 DBG_ASSERT(aFindResult != maVector.end(),
      67             :                     "EventHandler::RemoveEvent: Event to be removed not found (!)");
      68           0 :                 maVector.erase(aFindResult);
      69             :             }
      70           0 :         }
      71             : 
      72           0 :         BaseEvent* EventHandler::GetEvent()
      73             :         {
      74           0 :             if(!maVector.empty())
      75             :             {
      76             :                 // get the last event, that one is fastest to be removed
      77           0 :                 return maVector.back();
      78             :             }
      79             :             else
      80             :             {
      81           0 :                 return 0L;
      82             :             }
      83             :         }
      84             : 
      85           0 :         EventHandler::EventHandler()
      86             :         {
      87           0 :         }
      88             : 
      89           0 :         EventHandler::~EventHandler()
      90             :         {
      91           0 :             while(!maVector.empty())
      92             :             {
      93           0 :                 delete GetEvent();
      94             :             }
      95           0 :         }
      96             : 
      97             :         // Trigger and consume the events
      98           0 :         void EventHandler::ExecuteEvents()
      99             :         {
     100             :             for(;;)
     101             :             {
     102           0 :                 BaseEvent* pEvent = GetEvent();
     103           0 :                 if(pEvent == NULL)
     104           0 :                     break;
     105           0 :                 pEvent->ExecuteEvent();
     106           0 :                 delete pEvent;
     107           0 :             }
     108           0 :         }
     109             : 
     110             :         // for control
     111           0 :         bool EventHandler::IsEmpty() const
     112             :         {
     113           0 :             return (0L == maVector.size());
     114             :         }
     115             :     } // end of namespace mixer
     116             : } // end of namespace sdr
     117             : 
     118             : 
     119             : 
     120             : namespace sdr
     121             : {
     122             :     namespace event
     123             :     {
     124           0 :         TimerEventHandler::TimerEventHandler(sal_uInt32 nTimeout)
     125             :         {
     126           0 :             SetTimeout(nTimeout);
     127           0 :             Stop();
     128           0 :         }
     129             : 
     130           0 :         TimerEventHandler::~TimerEventHandler()
     131             :         {
     132           0 :             Stop();
     133           0 :         }
     134             : 
     135             :         // The timer when it is triggered; from class Timer
     136           0 :         void TimerEventHandler::Timeout()
     137             :         {
     138           0 :             ExecuteEvents();
     139           0 :         }
     140             : 
     141             :         // reset the timer
     142           0 :         void TimerEventHandler::Restart()
     143             :         {
     144           0 :             Start();
     145           0 :         }
     146             :     } // end of namespace mixer
     147             : } // end of namespace sdr
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10