LCOV - code coverage report
Current view: top level - libreoffice/framework/source/helper - ocomponentenumeration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 26 0.0 %
Date: 2012-12-27 Functions: 0 7 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 <helper/ocomponentenumeration.hxx>
      21             : 
      22             : #include <threadhelp/resetableguard.hxx>
      23             : 
      24             : #include <vcl/svapp.hxx>
      25             : 
      26             : namespace framework{
      27             : 
      28             : using namespace ::com::sun::star::container     ;
      29             : using namespace ::com::sun::star::lang          ;
      30             : using namespace ::com::sun::star::uno           ;
      31             : using namespace ::cppu                          ;
      32             : using namespace ::osl                           ;
      33             : using namespace ::rtl                           ;
      34             : 
      35             : //*****************************************************************************************************************
      36             : //  constructor
      37             : //*****************************************************************************************************************
      38           0 : OComponentEnumeration::OComponentEnumeration( const Sequence< css::uno::Reference< XComponent > >& seqComponents )
      39             :         //  Init baseclasses first
      40             :         //  Attention:
      41             :         //      Don't change order of initialization!
      42             :         //      ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
      43             :         //      we must garant right initialization and a valid value of this! First initialize
      44             :         //      baseclasses and then members. And we need the mutex for other baseclasses !!!
      45           0 :         :   ThreadHelpBase  ( &Application::GetSolarMutex() )
      46             :         // Init member
      47             :         ,   m_nPosition     ( 0                             )   // 0 is the first position for a valid list and the right value for an invalid list to!
      48           0 :         ,   m_seqComponents ( seqComponents                 )
      49             : {
      50             :     // Safe impossible states
      51             :     // "Method" not defined for ALL parameters!
      52             :     LOG_ASSERT( impldbg_checkParameter_OComponentEnumerationCtor( seqComponents ), "OComponentEnumeration::OComponentEnumeration()\nInvalid parameter detected!\n" )
      53           0 : }
      54             : 
      55             : //*****************************************************************************************************************
      56             : //  destructor
      57             : //*****************************************************************************************************************
      58           0 : OComponentEnumeration::~OComponentEnumeration()
      59             : {
      60             :     // Reset instance, free memory ....
      61           0 :     impl_resetObject();
      62           0 : }
      63             : 
      64             : //*****************************************************************************************************************
      65             : //  XEventListener
      66             : //*****************************************************************************************************************
      67           0 : void SAL_CALL OComponentEnumeration::disposing( const EventObject&
      68             : #if OSL_DEBUG_LEVEL > 0
      69             : aEvent
      70             : #endif
      71             : ) throw( RuntimeException )
      72             : {
      73             :     // Ready for multithreading
      74           0 :     ResetableGuard aGuard( m_aLock );
      75             : 
      76             :     // Safe impossible cases
      77             :     // This method is not specified for all incoming parameters.
      78             :     LOG_ASSERT( impldbg_checkParameter_disposing( aEvent ), "OComponentEnumeration::disposing()\nInvalid parameter detected!\n" )
      79             : 
      80             :     // Reset instance to defaults, release references and free memory.
      81           0 :     impl_resetObject();
      82           0 : }
      83             : 
      84             : //*****************************************************************************************************************
      85             : //  XEnumeration
      86             : //*****************************************************************************************************************
      87           0 : sal_Bool SAL_CALL OComponentEnumeration::hasMoreElements() throw( RuntimeException )
      88             : {
      89             :     // Ready for multithreading
      90           0 :     ResetableGuard aGuard( m_aLock );
      91             : 
      92             :     // First position in a valid list is 0.
      93             :     // => The last one is getLength() - 1!
      94             :     // m_nPosition's current value is the position for the next element, which will be return, if user call "nextElement()"
      95             :     // => We have more elements if current position less then the length of the list!
      96           0 :     return ( m_nPosition < (sal_uInt32)(m_seqComponents.getLength()) );
      97             : }
      98             : 
      99             : //*****************************************************************************************************************
     100             : //  XEnumeration
     101             : //*****************************************************************************************************************
     102           0 : Any SAL_CALL OComponentEnumeration::nextElement() throw(    NoSuchElementException  ,
     103             :                                                              WrappedTargetException ,
     104             :                                                             RuntimeException        )
     105             : {
     106             :     // Ready for multithreading
     107           0 :     ResetableGuard aGuard( m_aLock );
     108             : 
     109             :     // If we have no elements or end of enumeration is arrived ...
     110           0 :     if ( hasMoreElements() == sal_False )
     111             :     {
     112             :         // .. throw an exception!
     113           0 :         throw NoSuchElementException();
     114             :     }
     115             : 
     116             :     // Else; Get next element from list ...
     117           0 :     Any aComponent;
     118           0 :     aComponent <<= m_seqComponents[m_nPosition];
     119             :     // ... and step to next element!
     120           0 :     ++m_nPosition;
     121             : 
     122             :     // Return listitem.
     123           0 :     return aComponent;
     124             : }
     125             : 
     126             : //*****************************************************************************************************************
     127             : //  proteced method
     128             : //*****************************************************************************************************************
     129           0 : void OComponentEnumeration::impl_resetObject()
     130             : {
     131             :     // Attention:
     132             :     // Write this for multiple calls - NOT AT THE SAME TIME - but for more then one call again)!
     133             :     // It exist two ways to call this method. From destructor and from disposing().
     134             :     // I can't say, which one is the first. Normaly the disposing-call - but other way ....
     135             : 
     136             :     // Delete list of components.
     137           0 :     m_seqComponents.realloc( 0 );
     138             :     // Reset position in list.
     139             :     // The list has no elements anymore. m_nPosition is normaly the current position in list for nextElement!
     140             :     // But a position of 0 in a list of 0 items is an invalid state. This constellation can't work in future.
     141             :     // End of enumeration is arrived!
     142             :     // (see hasMoreElements() for more details...)
     143           0 :     m_nPosition = 0 ;
     144           0 : }
     145             : 
     146             : //_________________________________________________________________________________________________________________
     147             : //  debug methods
     148             : //_________________________________________________________________________________________________________________
     149             : 
     150             : /*-----------------------------------------------------------------------------------------------------------------
     151             :     The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
     152             :     we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!
     153             : 
     154             :     ATTENTION
     155             : 
     156             :         If you miss a test for one of this parameters, contact the autor or add it himself !(?)
     157             :         But ... look for right testing! See using of this methods!
     158             : -----------------------------------------------------------------------------------------------------------------*/
     159             : 
     160             : #ifdef ENABLE_ASSERTIONS
     161             : 
     162             : //*****************************************************************************************************************
     163             : // An empty list is allowed ... hasMoreElements() will return false then!
     164             : sal_Bool OComponentEnumeration::impldbg_checkParameter_OComponentEnumerationCtor( const Sequence< css::uno::Reference< XComponent > >& seqComponents )
     165             : {
     166             :     // Set default return value.
     167             :     sal_Bool bOK = sal_True;
     168             :     // Check parameter.
     169             :     if  (
     170             :             ( &seqComponents == NULL )
     171             :         )
     172             :     {
     173             :         bOK = sal_False ;
     174             :     }
     175             :     // Return result of check.
     176             :     return bOK ;
     177             : }
     178             : 
     179             : //*****************************************************************************************************************
     180             : sal_Bool OComponentEnumeration::impldbg_checkParameter_disposing( const EventObject& aEvent )
     181             : {
     182             :     // Set default return value.
     183             :     sal_Bool bOK = sal_True;
     184             :     // Check parameter.
     185             :     if  (
     186             :             ( &aEvent               ==  NULL        )   ||
     187             :             ( aEvent.Source.is()    ==  sal_False   )
     188             :         )
     189             :     {
     190             :         bOK = sal_False ;
     191             :     }
     192             :     // Return result of check.
     193             :     return bOK ;
     194             : }
     195             : 
     196             : #endif  //  #ifdef ENABLE_ASSERTIONS
     197             : 
     198             : }       //  namespace framework
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10