added a convenience method to remove the current iteration from the interfaceiterator

This commit is contained in:
Jörg Budischewski
2001-02-05 12:16:33 +00:00
parent 3708c9985d
commit 6e70a6c156

View File

@@ -2,9 +2,9 @@
* *
* $RCSfile: interfacecontainer.h,v $ * $RCSfile: interfacecontainer.h,v $
* *
* $Revision: 1.5 $ * $Revision: 1.6 $
* *
* last change: $Author: mh $ $Date: 2001-01-31 09:40:45 $ * last change: $Author: jbu $ $Date: 2001-02-05 13:16:33 $
* *
* The Contents of this file are made available subject to the terms of * The Contents of this file are made available subject to the terms of
* either of the following licenses * either of the following licenses
@@ -90,42 +90,50 @@ namespace cppu
//=================================================================== //===================================================================
class OInterfaceContainerHelper; class OInterfaceContainerHelper;
/** /**
* This is the iterator of a InterfaceContainerHelper. The iterator This is the iterator of a InterfaceContainerHelper. The iterator
* ist is not thread save. It is not allowed to assign or copy an ist is not thread save. It is not allowed to assign or copy an
* instance of this class. instance of this class.
*
* @version 0.1 @version 0.1
* @author Markus Meyer @author Markus Meyer
* @since 03/12/98 @since 03/12/98
* @see OInterfaceContainerHelper @see OInterfaceContainerHelper
*/ */
class OInterfaceIteratorHelper class OInterfaceIteratorHelper
{ {
public: public:
OInterfaceIteratorHelper(); OInterfaceIteratorHelper();
/** /**
* Create an iterator over the elements of the container. The iterator Create an iterator over the elements of the container. The iterator
* copies the elements of the conatainer. A change to the container does not copies the elements of the conatainer. A change to the container does not
* affect the iterator.<BR> affect the iterator.<BR>
* Remark: The copy is on demand. The iterator copy the elements only if the container Remark: The copy is on demand. The iterator copy the elements only if the container
* change the contens. It is not allowed to destroy the container if a iterator exist. change the contents. It is not allowed to destroy the container if a iterator exist.
*
* @param rCont the container of the elements. @param rCont the container of the elements.
*/ */
OInterfaceIteratorHelper( OInterfaceContainerHelper & rCont ); OInterfaceIteratorHelper( OInterfaceContainerHelper & rCont );
/** /**
* Release the connection to the container. Release the connection to the container.
*/ */
~OInterfaceIteratorHelper(); ~OInterfaceIteratorHelper();
/** Return true, if there are more elements in the iterator. */ /** Return true, if there are more elements in the iterator. */
sal_Bool SAL_CALL hasMoreElements() const { return nRemain != 0; } sal_Bool SAL_CALL hasMoreElements() const { return nRemain != 0; }
/** Return the next element of the iterator. Call this method if /** Return the next element of the iterator. Calling this method if
* hasMoreElements return false, is an error. hasMoreElements return false, is an error.
*/ */
::com::sun::star::uno::XInterface * SAL_CALL next(); ::com::sun::star::uno::XInterface * SAL_CALL next();
/** Removes the current element (the last one returned by next())
from the underlying container. Calling this method before
next() has been called or calling it twice with no next()
inbetween is an error.
@since udk211 (has been added in udk210)
*/
void SAL_CALL remove();
private: private:
OInterfaceContainerHelper & rCont; OInterfaceContainerHelper & rCont;
sal_Bool bIsList; sal_Bool bIsList;
@@ -138,14 +146,14 @@ private:
//=================================================================== //===================================================================
/** /**
* A container of interfaces. To access the elements use an iterator. A container of interfaces. To access the elements use an iterator.
* This implementation is thread save.<BR> This implementation is thread save.<BR>
* <B>Inserting null pointers is allowed, but is not tested and does not work.</B> <B>Inserting null pointers is allowed, but is not tested and does not work.</B>
*
* @version 0.1 @version 0.1
* @author Markus Meyer @author Markus Meyer
* @since 03/12/98 @since 03/12/98
* @see OInterfaceIteratorHelper @see OInterfaceIteratorHelper
*/ */
class OInterfaceContainerHelper class OInterfaceContainerHelper
{ {
@@ -157,60 +165,60 @@ public:
{ ::rtl_freeMemory( pMem ); } { ::rtl_freeMemory( pMem ); }
/** /**
* Create an interface container. The internal representation Create an interface container. The internal representation
* is an array, so it is not effective to store a large number is an array, so it is not effective to store a large number
* of elements. of elements.
*
* @param rMutex the mutex to protect multi thread access. @param rMutex the mutex to protect multi thread access.
* The lifetime must be longer than the lifetime The lifetime must be longer than the lifetime
* of this object. of this object.
*/ */
OInterfaceContainerHelper( ::osl::Mutex & rMutex ); OInterfaceContainerHelper( ::osl::Mutex & rMutex );
/** /**
* Release all interfaces. All iterators must be destroyed before Release all interfaces. All iterators must be destroyed before
* the container. the container.
*/ */
~OInterfaceContainerHelper(); ~OInterfaceContainerHelper();
/** /**
* Return the number of Elements in the container. Only usefull if you are acquire Return the number of Elements in the container. Only usefull if you are acquire
* the mutex. the mutex.
*/ */
sal_Int32 SAL_CALL getLength() const; sal_Int32 SAL_CALL getLength() const;
/** /**
* Return all interfaces added to this container. Return all interfaces added to this container.
**/ **/
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const; ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > > SAL_CALL getElements() const;
/** /**
* Insert an element in the container. The position is not specified. Insert an element in the container. The position is not specified.
* @param rxIFace the added interface. It is allowed to insert null or @param rxIFace the added interface. It is allowed to insert null or
* the same pointer more than once. the same pointer more than once.
* @return the new count of elements in the container. @return the new count of elements in the container.
*/ */
sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ); sal_Int32 SAL_CALL addInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
/** /**
* Remove an element from the container. It uses the equal definition of Remove an element from the container. It uses the equal definition of
* uno objects to remove the interfaces. uno objects to remove the interfaces.
* @param rxIFace the removed interface. @param rxIFace the removed interface.
* @return the new count of elements in the container. @return the new count of elements in the container.
*/ */
sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ); sal_Int32 SAL_CALL removeInterface( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
/** /**
* Call disposing on all object in the container that Call disposing on all object in the container that
* support XEventListener. Than clear the container. support XEventListener. Than clear the container.
*/ */
void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ); void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
/** /**
* Remove all elements. Remove all elements.
*/ */
void SAL_CALL clear(); void SAL_CALL clear();
private: private:
friend class OInterfaceIteratorHelper; friend class OInterfaceIteratorHelper;
/** /**
* bIsList == TRUE -> pData of type Sequence< XInterfaceSequence >, bIsList == TRUE -> pData of type Sequence< XInterfaceSequence >,
* otherwise pData == of type (XEventListener *) otherwise pData == of type (XEventListener *)
*/ */
void * pData; void * pData;
::osl::Mutex & rMutex; ::osl::Mutex & rMutex;
@@ -223,8 +231,8 @@ friend class OInterfaceIteratorHelper;
OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & ); OInterfaceContainerHelper & operator = ( const OInterfaceContainerHelper & );
/** /**
* Dulicate content of the conaitner and release the old one without destroing. Dulicate content of the conaitner and release the old one without destroing.
* The mutex must be locked and the memberbInUse must be true. The mutex must be locked and the memberbInUse must be true.
*/ */
void copyAndResetInUse(); void copyAndResetInUse();
public: public:
@@ -234,73 +242,73 @@ public:
//=================================================================== //===================================================================
/** /**
* A generic class to support the implementation of the XConnectionPointContainer interface. A generic class to support the implementation of the XConnectionPointContainer interface.
* This class holds a STL hash_map to acces the InterfaceContainerHelper through a generic This class holds a STL hash_map to acces the InterfaceContainerHelper through a generic
* key value. key value.
* The InterfaceContainerHelper you get with the method getContainer( ... ) exist The InterfaceContainerHelper you get with the method getContainer( ... ) exist
* until the whole PropertyListenerContainer is destroyed. until the whole PropertyListenerContainer is destroyed.
*
* @author Markus Meyer @author Markus Meyer
* @since 03/12/98 @since 03/12/98
* @see OInterfaceIteratorHelper @see OInterfaceIteratorHelper
* @see OInterfaceContainerHelper @see OInterfaceContainerHelper
*/ */
template< class key , class hashImpl , class equalImpl > template< class key , class hashImpl , class equalImpl >
class OMultiTypeInterfaceContainerHelperVar class OMultiTypeInterfaceContainerHelperVar
{ {
public: public:
/** /**
* Create a container of interface containers. Create a container of interface containers.
*
* @param rMutex the mutex to protect multi thread access. @param rMutex the mutex to protect multi thread access.
* The lifetime must be longer than the lifetime The lifetime must be longer than the lifetime
* of this object. of this object.
*/ */
inline OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & ); inline OMultiTypeInterfaceContainerHelperVar( ::osl::Mutex & );
/** /**
* Delete all containers. Delete all containers.
*/ */
inline ~OMultiTypeInterfaceContainerHelperVar(); inline ~OMultiTypeInterfaceContainerHelperVar();
/** /**
* Return all id's under which at least one interface is added. Return all id's under which at least one interface is added.
*/ */
inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const; inline ::com::sun::star::uno::Sequence< key > SAL_CALL getContainedTypes() const;
/** /**
* Return the container created under this key. Return the container created under this key.
* @return the container created under this key. If the container @return the container created under this key. If the container
* was not created, null was returned. was not created, null was returned.
*/ */
inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const; inline OInterfaceContainerHelper * SAL_CALL getContainer( const key & ) const;
/** /**
* Insert an element in the container specified with the key. The position is not specified. Insert an element in the container specified with the key. The position is not specified.
* @param rKey the id of the container. @param rKey the id of the container.
* @param rxIFace the added interface. It is allowed to insert null or @param rxIFace the added interface. It is allowed to insert null or
* the same pointer more than once. the same pointer more than once.
* @return the new count of elements in the container. @return the new count of elements in the container.
*/ */
inline sal_Int32 SAL_CALL addInterface( inline sal_Int32 SAL_CALL addInterface(
const key & rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r ); const key & rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & r );
/** /**
* Remove an element from the container specified with the key. Remove an element from the container specified with the key.
* It uses the equal definition of uno objects to remove the interfaces. It uses the equal definition of uno objects to remove the interfaces.
* @param rKey the id of the container. @param rKey the id of the container.
* @param rxIFace the removed interface. @param rxIFace the removed interface.
* @return the new count of elements in the container. @return the new count of elements in the container.
*/ */
inline sal_Int32 SAL_CALL removeInterface( inline sal_Int32 SAL_CALL removeInterface(
const key & rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace ); const key & rKey, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > & rxIFace );
/** /**
* Call disposing on all object in the container that Call disposing on all object in the container that
* support XEventListener. Than clear the container. support XEventListener. Than clear the container.
*/ */
inline void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt ); inline void SAL_CALL disposeAndClear( const ::com::sun::star::lang::EventObject & rEvt );
/** /**
* Remove all elements of all containers. Does not delete the container. Remove all elements of all containers. Does not delete the container.
*/ */
inline void SAL_CALL clear(); inline void SAL_CALL clear();
@@ -317,13 +325,13 @@ private:
/** /**
* This struct contains the standard variables of a broadcaster. Helper This struct contains the standard variables of a broadcaster. Helper
* classes only know a reference to this struct instead of references classes only know a reference to this struct instead of references
* to the four members. The access to the members must be guarded with to the four members. The access to the members must be guarded with
* rMutex. rMutex.
*
* The additional template parameter keyType has been added, because gcc The additional template parameter keyType has been added, because gcc
* can't compile addListener( const container::keyType &key ). can't compile addListener( const container::keyType &key ).
*/ */
template < class container , class keyType > template < class container , class keyType >
struct OBroadcastHelperVar struct OBroadcastHelperVar
@@ -338,8 +346,8 @@ struct OBroadcastHelperVar
sal_Bool bInDispose; sal_Bool bInDispose;
/** /**
* Initialize the structur. bDispose and bInDispose are set to false. Initialize the structur. bDispose and bInDispose are set to false.
* @param rMutex the mutex reference. @param rMutex the mutex reference.
*/ */
OBroadcastHelperVar( ::osl::Mutex & rMutex_ ) OBroadcastHelperVar( ::osl::Mutex & rMutex_ )
: rMutex( rMutex_ ) : rMutex( rMutex_ )
@@ -349,7 +357,7 @@ struct OBroadcastHelperVar
{} {}
/** /**
* adds a listener threadsafe. adds a listener threadsafe.
**/ **/
inline void addListener( const keyType &key , const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r ) inline void addListener( const keyType &key , const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > &r )
{ {
@@ -361,7 +369,7 @@ struct OBroadcastHelperVar
} }
/** /**
* removes a listener threadsafe removes a listener threadsafe
**/ **/
inline void removeListener( const keyType &key , const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r ) inline void removeListener( const keyType &key , const ::com::sun::star::uno::Reference < ::com::sun::star::uno::XInterface > & r )
{ {
@@ -372,10 +380,10 @@ struct OBroadcastHelperVar
} }
/** /**
* Return the container created under this key. Return the container created under this key.
* @return the container created under this key. If the container @return the container created under this key. If the container
* was not created, null was returned. This can be used to optimize was not created, null was returned. This can be used to optimize
* performance ( construction of an event object can be avoided ). performance ( construction of an event object can be avoided ).
***/ ***/
inline OInterfaceContainerHelper * SAL_CALL getContainer( const keyType &key ) const inline OInterfaceContainerHelper * SAL_CALL getContainer( const keyType &key ) const
{ {