LCOV - code coverage report
Current view: top level - solver/unxlngi6.pro/inc/cppuhelper - interfacecontainer.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 53 55 96.4 %
Date: 2012-08-25 Functions: 116 257 45.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 70 259 27.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                 :            : #ifndef _CPPUHELPER_INTERFACECONTAINER_H_
      29                 :            : #define _CPPUHELPER_INTERFACECONTAINER_H_
      30                 :            : 
      31                 :            : #include <vector>
      32                 :            : #include <osl/mutex.hxx>
      33                 :            : #include <rtl/alloc.h>
      34                 :            : #include <com/sun/star/uno/Sequence.hxx>
      35                 :            : #include <com/sun/star/uno/XInterface.hpp>
      36                 :            : #ifndef _COM_SUN_STAR_LANG_EVENTOBJECT_HXX_
      37                 :            : #include <com/sun/star/lang/EventObject.hpp>
      38                 :            : #endif
      39                 :            : 
      40                 :            : #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HXX_
      41                 :            : #include "com/sun/star/lang/DisposedException.hpp"
      42                 :            : #endif
      43                 :            : #include "cppuhelperdllapi.h"
      44                 :            : 
      45                 :            : /** */ //for docpp
      46                 :            : namespace cppu
      47                 :            : {
      48                 :            : 
      49                 :            : namespace detail {
      50                 :            : 
      51                 :            :     union element_alias
      52                 :            :     {
      53                 :            :         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > *pAsSequence;
      54                 :            :         ::com::sun::star::uno::XInterface * pAsInterface;
      55                 :    3535962 :         element_alias() : pAsInterface(0) {}
      56                 :            :     };
      57                 :            : 
      58                 :            : }
      59                 :            : 
      60                 :            : //===================================================================
      61                 :            : class OInterfaceContainerHelper;
      62                 :            : /**
      63                 :            :   This is the iterator of a InterfaceContainerHelper. Typically
      64                 :            :   one constructs an instance on the stack for one firing session.
      65                 :            :   It is not allowed to assign or copy an instance of this class.
      66                 :            : 
      67                 :            :   @see OInterfaceContainerHelper
      68                 :            :  */
      69                 :            : class CPPUHELPER_DLLPUBLIC OInterfaceIteratorHelper
      70                 :            : {
      71                 :            : public:
      72                 :            :     /**
      73                 :            :        Create an iterator over the elements of the container. The iterator
      74                 :            :        copies the elements of the conatainer. A change to the container
      75                 :            :        during the lifetime of an iterator is allowed and does not
      76                 :            :        affect the iterator-instance. The iterator and the container take cares
      77                 :            :        themself for concurrent access, no additional guarding is necessary.
      78                 :            : 
      79                 :            :        Remark: The copy is on demand. The iterator copy the elements only if the container
      80                 :            :        change the contents. It is not allowed to destroy the container as long
      81                 :            :        as an iterator exist.
      82                 :            : 
      83                 :            :        @param rCont the container of the elements.
      84                 :            :      */
      85                 :            :     OInterfaceIteratorHelper( OInterfaceContainerHelper & rCont ) SAL_THROW(());
      86                 :            : 
      87                 :            :     /**
      88                 :            :       Releases the connection to the container.
      89                 :            :      */
      90                 :            :     ~OInterfaceIteratorHelper() SAL_THROW(());
      91                 :            : 
      92                 :            :     /** Return sal_True, if there are more elements in the iterator. */
      93                 :    3032003 :     sal_Bool SAL_CALL hasMoreElements() const SAL_THROW(())
      94                 :    3032003 :         { return nRemain != 0; }
      95                 :            :     /** Return the next element of the iterator. Calling this method if
      96                 :            :         hasMoreElements() has returned sal_False, is an error. Cast the
      97                 :            :         returned pointer to the
      98                 :            :      */
      99                 :            :     ::com::sun::star::uno::XInterface * SAL_CALL next() SAL_THROW(());
     100                 :            : 
     101                 :            :     /** Removes the current element (the last one returned by next())
     102                 :            :         from the underlying container. Calling this method before
     103                 :            :         next() has been called or calling it twice with no next()
     104                 :            :         inbetween is an error.
     105                 :            :     */
     106                 :            :     void SAL_CALL remove() SAL_THROW(());
     107                 :            : 
     108                 :            : private:
     109                 :            :     OInterfaceContainerHelper & rCont;
     110                 :            :     sal_Bool                    bIsList;
     111                 :            : 
     112                 :            :     detail::element_alias aData;
     113                 :            : 
     114                 :            :     sal_Int32                   nRemain;
     115                 :            : 
     116                 :            :     OInterfaceIteratorHelper( const OInterfaceIteratorHelper & ) SAL_THROW(());
     117                 :            :     OInterfaceIteratorHelper &  operator = ( const OInterfaceIteratorHelper & ) SAL_THROW(());
     118                 :            : };
     119                 :            : 
     120                 :            : //===================================================================
     121                 :            : /**
     122                 :            :   A container of interfaces. To access the elements use an iterator.
     123                 :            :   This implementation is thread save.
     124                 :            : 
     125                 :            :   @see OInterfaceIteratorHelper
     126                 :            :  */
     127                 :            : class CPPUHELPER_DLLPUBLIC OInterfaceContainerHelper
     128                 :            : {
     129                 :            : public:
     130                 :            :     // these are here to force memory de/allocation to sal lib.
     131                 :     321468 :     inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
     132                 :     321468 :         { return ::rtl_allocateMemory( nSize ); }
     133                 :     308019 :     inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
     134                 :     308019 :         { ::rtl_freeMemory( pMem ); }
     135                 :            :     inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
     136                 :            :         { return pMem; }
     137                 :            :     inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
     138                 :            :         {}
     139                 :            : 
     140                 :            :     /**
     141                 :            :        Create an interface container.
     142                 :            : 
     143                 :            :        @param rMutex    the mutex to protect multi thread access.
     144                 :            :        The lifetime must be longer than the lifetime
     145                 :            :        of this object.
     146                 :            :      */
     147                 :            :     OInterfaceContainerHelper( ::osl::Mutex & rMutex ) SAL_THROW(());
     148                 :            :     /**
     149                 :            :       Release all interfaces. All iterators must be destroyed before
     150                 :            :       the container is destructed.
     151                 :            :      */
     152                 :            :     ~OInterfaceContainerHelper() SAL_THROW(());
     153                 :            :     /**
     154                 :            :       Return the number of Elements in the container. Only useful if you have acquired
     155                 :            :       the mutex.
     156                 :            :      */
     157                 :            :     sal_Int32 SAL_CALL getLength() const SAL_THROW(());
     158                 :            : 
     159                 :            :     /**
     160                 :            :       Return all interfaces added to this container.
     161                 :            :      **/
     162                 :            :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const SAL_THROW(());
     163                 :            : 
     164                 :            :     /** Inserts an element into the container.  The position is not specified, thus it is not
     165                 :            :         specified in which order events are fired.
     166                 :            : 
     167                 :            :         @attention
     168                 :            :         If you add the same interface more than once, then it will be added to the elements list
     169                 :            :         more than once and thus if you want to remove that interface from the list, you have to call
     170                 :            :         removeInterface() the same number of times.
     171                 :            :         In the latter case, you will also get events fired more than once (if the interface is a
     172                 :            :         listener interface).
     173                 :            : 
     174                 :            :         @param rxIFace
     175                 :            :                interface to be added; it is allowed to insert null or
     176                 :            :                the same interface more than once
     177                 :            :         @return
     178                 :            :                 the new count of elements in the container
     179                 :            :     */
     180                 :            :     sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
     181                 :            :     /** Removes an element from the container.  It uses interface equality to remove the interface.
     182                 :            : 
     183                 :            :         @param rxIFace
     184                 :            :                interface to be removed
     185                 :            :         @return
     186                 :            :                 the new count of elements in the container
     187                 :            :     */
     188                 :            :     sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ) SAL_THROW(());
     189                 :            :     /**
     190                 :            :       Call disposing on all object in the container that
     191                 :            :       support XEventListener. Than clear the container.
     192                 :            :      */
     193                 :            :     void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
     194                 :            :     /**
     195                 :            :       Clears the container without calling disposing().
     196                 :            :      */
     197                 :            :     void SAL_CALL clear() SAL_THROW(());
     198                 :            : 
     199                 :            :     /** Executes a functor for each contained listener of specified type, e.g.
     200                 :            :         <code>forEach<awt::XPaintListener>(...</code>.
     201                 :            : 
     202                 :            :         If a com::sun::star::lang::DisposedException occurs which relates to
     203                 :            :         the called listener, then that listener is removed from the container.
     204                 :            : 
     205                 :            :         @tparam ListenerT listener type
     206                 :            :         @tparam FuncT unary functor type, let your compiler deduce this for you
     207                 :            :         @param func unary functor object expecting an argument of type
     208                 :            :                     ::com::sun::star::uno::Reference<ListenerT>
     209                 :            :     */
     210                 :            :     template <typename ListenerT, typename FuncT>
     211                 :            :     inline void forEach( FuncT const& func );
     212                 :            : 
     213                 :            :     /** Calls a UNO listener method for each contained listener.
     214                 :            : 
     215                 :            :         The listener method must take a single argument of type EventT,
     216                 :            :         and return <code>void</code>.
     217                 :            : 
     218                 :            :         If a com::sun::star::lang::DisposedException occurs which relates to
     219                 :            :         the called listener, then that listener is removed from the container.
     220                 :            : 
     221                 :            :         @tparam ListenerT UNO event listener type, let your compiler deduce this for you
     222                 :            :         @tparam EventT event type, let your compiler deduce this for you
     223                 :            :         @param NotificationMethod
     224                 :            :             Pointer to a method of a ListenerT interface.
     225                 :            :         @param Event
     226                 :            :             Event to notify to all contained listeners
     227                 :            : 
     228                 :            :         Example:
     229                 :            : @code
     230                 :            :     awt::PaintEvent aEvent( static_cast< cppu::OWeakObject* >( this ), ... );
     231                 :            :     listeners.notifyEach( &XPaintListener::windowPaint, aEvent );
     232                 :            : @endcode
     233                 :            :     */
     234                 :            :     template< typename ListenerT, typename EventT >
     235                 :            :     inline void notifyEach( void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event );
     236                 :            : 
     237                 :            : private:
     238                 :            : friend class OInterfaceIteratorHelper;
     239                 :            :     /**
     240                 :            :       bIsList == TRUE -> aData.pAsSequence of type Sequence< XInterfaceSequence >,
     241                 :            :       otherwise aData.pAsInterface == of type (XEventListener *)
     242                 :            :      */
     243                 :            :     detail::element_alias   aData;
     244                 :            :     ::osl::Mutex &          rMutex;
     245                 :            :     /** TRUE -> used by an iterator. */
     246                 :            :     sal_Bool                bInUse;
     247                 :            :     /** TRUE -> aData.pAsSequence is of type Sequence< XInterfaceSequence >. */
     248                 :            :     sal_Bool                bIsList;
     249                 :            : 
     250                 :            :     OInterfaceContainerHelper( const OInterfaceContainerHelper & ) SAL_THROW(());
     251                 :            :     OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & ) SAL_THROW(());
     252                 :            : 
     253                 :            :     /*
     254                 :            :       Dulicate content of the conaitner and release the old one without destroying.
     255                 :            :       The mutex must be locked and the memberbInUse must be true.
     256                 :            :      */
     257                 :            :     void copyAndResetInUse() SAL_THROW(());
     258                 :            : 
     259                 :            : private:
     260                 :            :     template< typename ListenerT, typename EventT >
     261                 :            :     class NotifySingleListener
     262                 :            :     {
     263                 :            :     private:
     264                 :            :         typedef void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& );
     265                 :            :         NotificationMethod  m_pMethod;
     266                 :            :         const EventT&       m_rEvent;
     267                 :            :     public:
     268                 :     160125 :         NotifySingleListener( NotificationMethod method, const EventT& event ) : m_pMethod( method ), m_rEvent( event ) { }
     269                 :            : 
     270                 :      71637 :         void operator()( const ::com::sun::star::uno::Reference<ListenerT>& listener ) const
     271                 :            :         {
     272 [ -  + ][ -  + ]:      71637 :             (listener.get()->*m_pMethod)( m_rEvent );
         [ -  + ][ #  # ]
         [ -  + ][ #  # ]
         [ #  # ][ #  # ]
     273                 :      71637 :         }
     274                 :            :     };
     275                 :            : };
     276                 :            : 
     277                 :            : template <typename ListenerT, typename FuncT>
     278                 :     234441 : inline void OInterfaceContainerHelper::forEach( FuncT const& func )
     279                 :            : {
     280 [ +  - ][ +  - ]:     234441 :     OInterfaceIteratorHelper iter( *this );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
     281 [ +  + ][ +  + ]:     379269 :     while (iter.hasMoreElements()) {
         [ +  + ][ +  + ]
         [ +  + ][ #  # ]
         [ #  # ][ #  # ]
     282                 :            :         ::com::sun::star::uno::Reference<ListenerT> const xListener(
     283 [ +  - ][ +  - ]:     144828 :             iter.next(), ::com::sun::star::uno::UNO_QUERY );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     284 [ +  - ][ +  - ]:     144828 :         if (xListener.is()) {
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
     285                 :            : #if defined(EXCEPTIONS_OFF)
     286                 :            :             func( xListener );
     287                 :            : #else
     288                 :            :             try {
     289 [ +  - ][ +  - ]:     144828 :                 func( xListener );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
     290                 :            :             }
     291   [ #  #  #  #  :          0 :             catch (::com::sun::star::lang::DisposedException const& exc) {
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     292   [ #  #  #  #  :          0 :                 if (exc.Context == xListener)
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
          #  #  #  #  #  
                #  #  # ]
     293   [ +  -  #  # ]:     379269 :                     iter.remove();
           [ +  -  #  # ]
           [ +  -  #  # ]
           [ +  -  #  # ]
           [ +  -  #  # ]
           [ #  #  #  # ]
           [ #  #  #  # ]
           [ #  #  #  # ]
     294                 :            :             }
     295                 :            : #endif
     296                 :            :         }
     297                 :            :     }
     298                 :     234441 : }
     299                 :            : 
     300                 :            : template< typename ListenerT, typename EventT >
     301                 :     160125 : inline void OInterfaceContainerHelper::notifyEach( void ( SAL_CALL ListenerT::*NotificationMethod )( const EventT& ), const EventT& Event )
     302                 :            : {
     303 [ +  - ][ +  - ]:     160125 :     forEach< ListenerT, NotifySingleListener< ListenerT, EventT > >( NotifySingleListener< ListenerT, EventT >( NotificationMethod, Event ) );
         [ +  - ][ #  # ]
         [ +  - ][ #  # ]
         [ #  # ][ #  # ]
     304                 :     160125 : }
     305                 :            : 
     306                 :            : //===================================================================
     307                 :            : /**
     308                 :            :   A helper class to store interface references of different types.
     309                 :            : 
     310                 :            :   @see OInterfaceIteratorHelper
     311                 :            :   @see OInterfaceContainerHelper
     312                 :            :  */
     313                 :            : template< class key , class hashImpl , class equalImpl >
     314                 :            : class OMultiTypeInterfaceContainerHelperVar
     315                 :            : {
     316                 :            : public:
     317                 :            :     // these are here to force memory de/allocation to sal lib.
     318                 :      11867 :     inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
     319                 :      11867 :         { return ::rtl_allocateMemory( nSize ); }
     320                 :      11867 :     inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
     321                 :      11867 :         { ::rtl_freeMemory( pMem ); }
     322                 :            :     inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
     323                 :            :         { return pMem; }
     324                 :            :     inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
     325                 :            :         {}
     326                 :            : 
     327                 :            :     /**
     328                 :            :       Create a container of interface containers.
     329                 :            : 
     330                 :            :       @param rMutex the mutex to protect multi thread access.
     331                 :            :                          The lifetime must be longer than the lifetime
     332                 :            :                          of this object.
     333                 :            :      */
     334                 :            :     inline OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & rMutex ) SAL_THROW(());
     335                 :            :     /**
     336                 :            :       Deletes all containers.
     337                 :            :      */
     338                 :            :     inline ~OMultiTypeInterfaceContainerHelperVar() SAL_THROW(());
     339                 :            : 
     340                 :            :     /**
     341                 :            :       Return all id's under which at least one interface is added.
     342                 :            :      */
     343                 :            :     inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const SAL_THROW(());
     344                 :            : 
     345                 :            :     /**
     346                 :            :       Return the container created under this key.
     347                 :            :       The InterfaceContainerHelper exists until the whole MultiTypeContainer is destroyed.
     348                 :            :       @return the container created under this key. If the container
     349                 :            :                  was not created, null was returned.
     350                 :            :      */
     351                 :            :     inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const SAL_THROW(());
     352                 :            : 
     353                 :            :     /** Inserts an element into the container with the specified key.
     354                 :            :         The position is not specified, thus it is not specified in which order events are fired.
     355                 :            : 
     356                 :            :         @attention
     357                 :            :         If you add the same interface more than once, then it will be added to the elements list
     358                 :            :         more than once and thus if you want to remove that interface from the list, you have to call
     359                 :            :         removeInterface() the same number of times.
     360                 :            :         In the latter case, you will also get events fired more than once (if the interface is a
     361                 :            :         listener interface).
     362                 :            : 
     363                 :            :         @param rKey
     364                 :            :                the id of the container
     365                 :            :         @param r
     366                 :            :                interface to be added; it is allowed, to insert null or
     367                 :            :                the same interface more than once
     368                 :            :         @return
     369                 :            :                 the new count of elements in the container
     370                 :            :     */
     371                 :            :     inline sal_Int32 SAL_CALL addInterface(
     372                 :            :         const key & rKey,
     373                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
     374                 :            :         SAL_THROW(());
     375                 :            : 
     376                 :            :     /** Removes an element from the container with the specified key.
     377                 :            :         It uses interface equality to remove the interface.
     378                 :            : 
     379                 :            :         @param rKey
     380                 :            :                the id of the container
     381                 :            :         @param rxIFace
     382                 :            :                interface to be removed
     383                 :            :         @return
     384                 :            :                 the new count of elements in the container
     385                 :            :     */
     386                 :            :     inline sal_Int32 SAL_CALL removeInterface(
     387                 :            :         const key & rKey,
     388                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
     389                 :            :         SAL_THROW(());
     390                 :            : 
     391                 :            :     /**
     392                 :            :       Call disposing on all references in the container, that
     393                 :            :       support XEventListener. Then clears the container.
     394                 :            :       @param rEvt the event object which is passed during disposing() call
     395                 :            :      */
     396                 :            :     inline void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
     397                 :            :     /**
     398                 :            :       Remove all elements of all containers. Does not delete the container.
     399                 :            :      */
     400                 :            :     inline void SAL_CALL clear() SAL_THROW(());
     401                 :            : 
     402                 :            :     typedef key keyType;
     403                 :            : private:
     404                 :            :     typedef ::std::vector< std::pair < key , void* > > InterfaceMap;
     405                 :            :     InterfaceMap *m_pMap;
     406                 :            :     ::osl::Mutex &  rMutex;
     407                 :            : 
     408                 :    1258277 :     inline typename InterfaceMap::iterator find(const key &rKey) const
     409                 :            :     {
     410                 :    1258277 :         typename InterfaceMap::iterator iter = m_pMap->begin();
     411                 :    1258277 :         typename InterfaceMap::iterator end = m_pMap->end();
     412                 :            : 
     413 [ +  - ][ +  + ]:    1444297 :         while( iter != end )
     414                 :            :         {
     415                 :            :             equalImpl equal;
     416   [ +  -  -  + ]:     186020 :             if( equal( iter->first, rKey ) )
              [ +  +  + ]
                 [ +  + ]
     417                 :            :                 break;
     418         [ +  - ]:     186020 :             iter++;
     419                 :            :         }
     420                 :    1258277 :         return iter;
     421                 :            :     }
     422                 :            : 
     423                 :            :     inline OMultiTypeInterfaceContainerHelperVar( const OMultiTypeInterfaceContainerHelperVar & ) SAL_THROW(());
     424                 :            :     inline OMultiTypeInterfaceContainerHelperVar & operator = ( const OMultiTypeInterfaceContainerHelperVar & ) SAL_THROW(());
     425                 :            : };
     426                 :            : 
     427                 :            : 
     428                 :            : 
     429                 :            : 
     430                 :            : /**
     431                 :            :   This struct contains the standard variables of a broadcaster. Helper
     432                 :            :   classes only know a reference to this struct instead of references
     433                 :            :   to the four members. The access to the members must be guarded with
     434                 :            :   rMutex.
     435                 :            : 
     436                 :            :   The additional template parameter keyType has been added, because gcc
     437                 :            :   can't compile addListener( const container::keyType &key ).
     438                 :            :  */
     439                 :            : template < class container , class keyType >
     440                 :    1044740 : struct OBroadcastHelperVar
     441                 :            : {
     442                 :            :     /** The shared mutex. */
     443                 :            :     ::osl::Mutex &                      rMutex;
     444                 :            :     /** ListenerContainer class is thread safe. */
     445                 :            :     container   aLC;
     446                 :            :     /** Dispose call ready. */
     447                 :            :     sal_Bool                            bDisposed;
     448                 :            :     /** In dispose call. */
     449                 :            :     sal_Bool                            bInDispose;
     450                 :            : 
     451                 :            :     /**
     452                 :            :       Initialize the structur. bDispose and bInDispose are set to false.
     453                 :            :       @param rMutex_ the mutex reference.
     454                 :            :      */
     455                 :    1057040 :     OBroadcastHelperVar( ::osl::Mutex & rMutex_ ) SAL_THROW(())
     456                 :            :         : rMutex( rMutex_ )
     457                 :            :         , aLC( rMutex_ )
     458                 :            :         , bDisposed( sal_False )
     459                 :    1057040 :         , bInDispose( sal_False )
     460                 :    1057040 :     {}
     461                 :            : 
     462                 :            :     /**
     463                 :            :       adds a listener threadsafe.
     464                 :            :      **/
     465                 :      80343 :     inline void addListener(
     466                 :            :         const keyType &key,
     467                 :            :         const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
     468                 :            :         SAL_THROW(())
     469                 :            :     {
     470         [ +  - ]:      80343 :         ::osl::MutexGuard guard( rMutex );
     471                 :            :         OSL_ENSURE( !bInDispose, "do not add listeners in the dispose call" );
     472                 :            :         OSL_ENSURE( !bDisposed, "object is disposed" );
     473 [ +  - ][ +  - ]:      80343 :         if( ! bInDispose && ! bDisposed  )
     474 [ +  - ][ +  - ]:      80343 :             aLC.addInterface( key , r );
     475                 :      80343 :     }
     476                 :            : 
     477                 :            :     /**
     478                 :            :       removes a listener threadsafe
     479                 :            :      **/
     480                 :      52842 :     inline void removeListener(
     481                 :            :         const keyType &key,
     482                 :            :         const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
     483                 :            :         SAL_THROW(())
     484                 :            :     {
     485         [ +  - ]:      52842 :         ::osl::MutexGuard guard( rMutex );
     486                 :            :         OSL_ENSURE( !bDisposed, "object is disposed" );
     487 [ +  + ][ +  - ]:      52842 :         if( ! bInDispose && ! bDisposed  )
     488 [ +  - ][ +  - ]:      52842 :             aLC.removeInterface( key , r );
     489                 :      52842 :     }
     490                 :            : 
     491                 :            :     /**
     492                 :            :       Return the container created under this key.
     493                 :            :       @return the container created under this key. If the container
     494                 :            :                 was not created, null was returned. This can be used to optimize
     495                 :            :               performance ( construction of an event object can be avoided ).
     496                 :            :      ***/
     497                 :     246225 :     inline OInterfaceContainerHelper * SAL_CALL getContainer( const keyType &key ) const SAL_THROW(())
     498                 :     246225 :         { return aLC.getContainer( key ); }
     499                 :            : };
     500                 :            : 
     501                 :            : /*------------------------------------------
     502                 :            : *
     503                 :            : * In general, the above templates are used with a Type as key.
     504                 :            : * Therefore a default declaration is given ( OMultiTypeInterfaceContainerHelper and OBroadcastHelper )
     505                 :            : *
     506                 :            : *------------------------------------------*/
     507                 :            : 
     508                 :            : // helper function call class
     509                 :            : struct hashType_Impl
     510                 :            : {
     511                 :            :     size_t operator()(const ::com::sun::star::uno::Type & s) const SAL_THROW(())
     512                 :            :     { return (size_t) s.getTypeName().hashCode(); }
     513                 :            : };
     514                 :            : 
     515                 :            : 
     516                 :            : /** Specialized class for key type com::sun::star::uno::Type,
     517                 :            :     without explicit usage of STL symbols.
     518                 :            : */
     519                 :            : class CPPUHELPER_DLLPUBLIC OMultiTypeInterfaceContainerHelper
     520                 :            : {
     521                 :            : public:
     522                 :            :     // these are here to force memory de/allocation to sal lib.
     523                 :        464 :     inline static void * SAL_CALL operator new( size_t nSize ) SAL_THROW(())
     524                 :        464 :         { return ::rtl_allocateMemory( nSize ); }
     525                 :        368 :     inline static void SAL_CALL operator delete( void * pMem ) SAL_THROW(())
     526                 :        368 :         { ::rtl_freeMemory( pMem ); }
     527                 :            :     inline static void * SAL_CALL operator new( size_t, void * pMem ) SAL_THROW(())
     528                 :            :         { return pMem; }
     529                 :            :     inline static void SAL_CALL operator delete( void *, void * ) SAL_THROW(())
     530                 :            :         {}
     531                 :            : 
     532                 :            :     /**
     533                 :            :       Create a container of interface containers.
     534                 :            : 
     535                 :            :       @param rMutex the mutex to protect multi thread access.
     536                 :            :                          The lifetime must be longer than the lifetime
     537                 :            :                          of this object.
     538                 :            :      */
     539                 :            :     OMultiTypeInterfaceContainerHelper( ::osl::Mutex & rMutex ) SAL_THROW(());
     540                 :            :     /**
     541                 :            :       Delete all containers.
     542                 :            :      */
     543                 :            :     ~OMultiTypeInterfaceContainerHelper() SAL_THROW(());
     544                 :            : 
     545                 :            :     /**
     546                 :            :       Return all id's under which at least one interface is added.
     547                 :            :      */
     548                 :            :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getContainedTypes() const SAL_THROW(());
     549                 :            : 
     550                 :            :     /**
     551                 :            :       Return the container created under this key.
     552                 :            :       @return the container created under this key. If the container
     553                 :            :                  was not created, null was returned.
     554                 :            :      */
     555                 :            :     OInterfaceContainerHelper * SAL_CALL getContainer( const ::com::sun::star::uno::Type & rKey ) const SAL_THROW(());
     556                 :            : 
     557                 :            :     /** Inserts an element into the container with the specified key.
     558                 :            :         The position is not specified, thus it is not specified in which order events are fired.
     559                 :            : 
     560                 :            :         @attention
     561                 :            :         If you add the same interface more than once, then it will be added to the elements list
     562                 :            :         more than once and thus if you want to remove that interface from the list, you have to call
     563                 :            :         removeInterface() the same number of times.
     564                 :            :         In the latter case, you will also get events fired more than once (if the interface is a
     565                 :            :         listener interface).
     566                 :            : 
     567                 :            :         @param rKey
     568                 :            :                the id of the container
     569                 :            :         @param r
     570                 :            :                interface to be added; it is allowed, to insert null or
     571                 :            :                the same interface more than once
     572                 :            :         @return
     573                 :            :                 the new count of elements in the container
     574                 :            :     */
     575                 :            :     sal_Int32 SAL_CALL addInterface(
     576                 :            :         const ::com::sun::star::uno::Type & rKey,
     577                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r )
     578                 :            :         SAL_THROW(());
     579                 :            : 
     580                 :            :     /** Removes an element from the container with the specified key.
     581                 :            :         It uses interface equality to remove the interface.
     582                 :            : 
     583                 :            :         @param rKey
     584                 :            :                the id of the container
     585                 :            :         @param rxIFace
     586                 :            :                interface to be removed
     587                 :            :         @return
     588                 :            :                 the new count of elements in the container
     589                 :            :     */
     590                 :            :     sal_Int32 SAL_CALL removeInterface(
     591                 :            :         const ::com::sun::star::uno::Type & rKey,
     592                 :            :         const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace )
     593                 :            :         SAL_THROW(());
     594                 :            : 
     595                 :            :     /**
     596                 :            :       Call disposing on all object in the container that
     597                 :            :       support XEventListener. Than clear the container.
     598                 :            :      */
     599                 :            :     void    SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ) SAL_THROW(());
     600                 :            :     /**
     601                 :            :       Remove all elements of all containers. Does not delete the container.
     602                 :            :      */
     603                 :            :     void SAL_CALL clear() SAL_THROW(());
     604                 :            : 
     605                 :            :     typedef ::com::sun::star::uno::Type keyType;
     606                 :            : private:
     607                 :            :     void *m_pMap;
     608                 :            :     ::osl::Mutex &  rMutex;
     609                 :            : 
     610                 :            :     inline OMultiTypeInterfaceContainerHelper( const OMultiTypeInterfaceContainerHelper & ) SAL_THROW(());
     611                 :            :     inline OMultiTypeInterfaceContainerHelper & operator = ( const OMultiTypeInterfaceContainerHelper & ) SAL_THROW(());
     612                 :            : };
     613                 :            : 
     614                 :            : typedef OBroadcastHelperVar< OMultiTypeInterfaceContainerHelper , OMultiTypeInterfaceContainerHelper::keyType > OBroadcastHelper;
     615                 :            : 
     616                 :            : }
     617                 :            : 
     618                 :            : #endif
     619                 :            : 
     620                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10