LCOV - code coverage report
Current view: top level - svx/source/sdr/event - eventhandler.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 49 0.0 %
Date: 2012-08-25 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 38 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <svx/sdr/event/eventhandler.hxx>
      30                 :            : 
      31                 :            : // for SOLARIS compiler include of algorithm part of _STL is necesary to
      32                 :            : // get access to basic algos like ::std::find
      33                 :            : #include <algorithm>
      34                 :            : #include <tools/debug.hxx>
      35                 :            : 
      36                 :            : //////////////////////////////////////////////////////////////////////////////
      37                 :            : 
      38                 :            : namespace sdr
      39                 :            : {
      40                 :            :     namespace event
      41                 :            :     {
      42                 :          0 :         BaseEvent::BaseEvent(EventHandler& rEventHandler)
      43                 :          0 :         :   mrEventHandler(rEventHandler)
      44                 :            :         {
      45                 :          0 :             mrEventHandler.AddEvent(*this);
      46                 :          0 :         }
      47                 :            : 
      48                 :          0 :         BaseEvent::~BaseEvent()
      49                 :            :         {
      50                 :          0 :             mrEventHandler.RemoveEvent(*this);
      51         [ #  # ]:          0 :         }
      52                 :            :     } // end of namespace mixer
      53                 :            : } // end of namespace sdr
      54                 :            : 
      55                 :            : //////////////////////////////////////////////////////////////////////////////
      56                 :            : 
      57                 :            : namespace sdr
      58                 :            : {
      59                 :            :     namespace event
      60                 :            :     {
      61                 :          0 :         void EventHandler::AddEvent(BaseEvent& rBaseEvent)
      62                 :            :         {
      63         [ #  # ]:          0 :             maVector.push_back(&rBaseEvent);
      64                 :          0 :         }
      65                 :            : 
      66                 :          0 :         void EventHandler::RemoveEvent(BaseEvent& rBaseEvent)
      67                 :            :         {
      68         [ #  # ]:          0 :             if(maVector.back() == &rBaseEvent)
      69                 :            :             {
      70                 :            :                 // the one to remove is the last, pop
      71                 :          0 :                 maVector.pop_back();
      72                 :            :             }
      73                 :            :             else
      74                 :            :             {
      75                 :            :                 const BaseEventVector::iterator aFindResult = ::std::find(
      76         [ #  # ]:          0 :                     maVector.begin(), maVector.end(), &rBaseEvent);
      77                 :            :                 DBG_ASSERT(aFindResult != maVector.end(),
      78                 :            :                     "EventHandler::RemoveEvent: Event to be removed not found (!)");
      79         [ #  # ]:          0 :                 maVector.erase(aFindResult);
      80                 :            :             }
      81                 :          0 :         }
      82                 :            : 
      83                 :          0 :         BaseEvent* EventHandler::GetEvent()
      84                 :            :         {
      85         [ #  # ]:          0 :             if(!maVector.empty())
      86                 :            :             {
      87                 :            :                 // get the last event, that one is fastest to be removed
      88                 :          0 :                 return maVector.back();
      89                 :            :             }
      90                 :            :             else
      91                 :            :             {
      92                 :          0 :                 return 0L;
      93                 :            :             }
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         EventHandler::EventHandler()
      97                 :            :         {
      98                 :          0 :         }
      99                 :            : 
     100                 :          0 :         EventHandler::~EventHandler()
     101                 :            :         {
     102         [ #  # ]:          0 :             while(!maVector.empty())
     103                 :            :             {
     104 [ #  # ][ #  # ]:          0 :                 delete GetEvent();
                 [ #  # ]
     105                 :            :             }
     106         [ #  # ]:          0 :         }
     107                 :            : 
     108                 :            :         // Trigger and consume the events
     109                 :          0 :         void EventHandler::ExecuteEvents()
     110                 :            :         {
     111                 :          0 :             for(;;)
     112                 :            :             {
     113                 :          0 :                 BaseEvent* pEvent = GetEvent();
     114         [ #  # ]:          0 :                 if(pEvent == NULL)
     115                 :          0 :                     break;
     116                 :          0 :                 pEvent->ExecuteEvent();
     117         [ #  # ]:          0 :                 delete pEvent;
     118                 :            :             }
     119                 :          0 :         }
     120                 :            : 
     121                 :            :         // for control
     122                 :          0 :         sal_Bool EventHandler::IsEmpty() const
     123                 :            :         {
     124                 :          0 :             return (0L == maVector.size());
     125                 :            :         }
     126                 :            :     } // end of namespace mixer
     127                 :            : } // end of namespace sdr
     128                 :            : 
     129                 :            : //////////////////////////////////////////////////////////////////////////////
     130                 :            : 
     131                 :            : namespace sdr
     132                 :            : {
     133                 :            :     namespace event
     134                 :            :     {
     135         [ #  # ]:          0 :         TimerEventHandler::TimerEventHandler(sal_uInt32 nTimeout)
     136                 :            :         {
     137         [ #  # ]:          0 :             SetTimeout(nTimeout);
     138         [ #  # ]:          0 :             Stop();
     139                 :          0 :         }
     140                 :            : 
     141         [ #  # ]:          0 :         TimerEventHandler::~TimerEventHandler()
     142                 :            :         {
     143         [ #  # ]:          0 :             Stop();
     144         [ #  # ]:          0 :         }
     145                 :            : 
     146                 :            :         // The timer when it is triggered; from class Timer
     147                 :          0 :         void TimerEventHandler::Timeout()
     148                 :            :         {
     149                 :          0 :             ExecuteEvents();
     150                 :          0 :         }
     151                 :            : 
     152                 :            :         // reset the timer
     153                 :          0 :         void TimerEventHandler::Restart()
     154                 :            :         {
     155                 :          0 :             Start();
     156                 :          0 :         }
     157                 :            :     } // end of namespace mixer
     158                 :            : } // end of namespace sdr
     159                 :            : 
     160                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10