25#include <osl/diagnose.h>
26#include <com/sun/star/container/ElementExistException.hpp>
27#include <com/sun/star/container/NoSuchElementException.hpp>
28#include <com/sun/star/container/XEnumeration.hpp>
29#include <com/sun/star/container/XIndexReplace.hpp>
30#include <com/sun/star/container/XSet.hpp>
31#include <com/sun/star/container/XContainer.hpp>
32#include <com/sun/star/container/XContainerListener.hpp>
33#include <com/sun/star/lang/IllegalArgumentException.hpp>
34#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
35#include <com/sun/star/uno/Any.hxx>
36#include <com/sun/star/uno/Reference.hxx>
37#include <com/sun/star/uno/Type.hxx>
41typedef cppu::WeakImplHelper<
42 css::container::XIndexReplace,
44 css::container::XContainer>
47template<
class ELEMENT_TYPE>
51 typedef ELEMENT_TYPE
T;
52 typedef std::vector<css::uno::Reference<css::container::XContainerListener> >
Listeners_t;
72 OSL_ENSURE(
isValid (
t ),
"invalid item" );
88 OSL_ENSURE( !
hasItem(
t ),
"item to be added already present" );
89 OSL_ENSURE(
isValid(
t ),
"invalid item" );
99 OSL_ENSURE(
hasItem(
t ),
"item to be removed not present" );
100 OSL_ENSURE(
isValid(
t ),
"an invalid item, funny that!" );
114 return static_cast<sal_Int32
>(
maItems.size() );
119 return n >= 0 && n < static_cast<sal_Int32>(
maItems.size() );
127 virtual bool isValid(
const T& )
const {
return true; }
160 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 nIndex )
override
163 throw css::lang::IndexOutOfBoundsException();
169 const css::uno::Any& aElement )
override
173 throw css::lang::IndexOutOfBoundsException();
174 if( !( aElement >>=
t ) || !
isValid(
t ) )
175 throw css::lang::IllegalArgumentException();
187 virtual sal_Bool SAL_CALL
has(
const css::uno::Any& aElement )
override
190 return ( aElement >>=
t ) &&
hasItem(
t );
193 virtual void SAL_CALL
insert(
const css::uno::Any& aElement )
override
196 if( !( aElement >>=
t ) || !
isValid(
t ) )
197 throw css::lang::IllegalArgumentException();
199 throw css::container::ElementExistException();
203 virtual void SAL_CALL
remove(
const css::uno::Any& aElement )
override
206 if( !(aElement >>=
t) )
207 throw css::lang::IllegalArgumentException();
209 throw css::container::NoSuchElementException();
216 const css::uno::Reference<css::container::XContainerListener>& xListener )
override
218 OSL_ENSURE( xListener.is(),
"need listener!" );
225 const css::uno::Reference<css::container::XContainerListener>& xListener )
override
227 OSL_ENSURE( xListener.is(),
"need listener!" );
228 Listeners_t::iterator aIter =
240 css::container::ContainerEvent
aEvent(
241 static_cast<css::container::XIndexReplace*
>(
this ),
242 css::uno::Any(
nPos ),
247 listener->elementInserted(
aEvent );
253 css::container::ContainerEvent
aEvent(
254 static_cast<css::container::XIndexReplace*
>(
this ),
256 css::uno::Any( aOld ),
260 listener->elementRemoved(
aEvent );
267 css::container::ContainerEvent
aEvent(
268 static_cast<css::container::XIndexReplace*
>(
this ),
269 css::uno::Any(
nPos ),
271 css::uno::Any( aNew ) );
274 listener->elementReplaced(
aEvent );
sal_Int32 countItems() const
virtual void _remove(const T &)
called before item is removed from the collection
virtual void SAL_CALL remove(const css::uno::Any &aElement) override
std::vector< css::uno::Reference< css::container::XContainerListener > > Listeners_t
const T & getItem(sal_Int32 n) const
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
void removeItem(const T &t)
virtual void SAL_CALL replaceByIndex(sal_Int32 nIndex, const css::uno::Any &aElement) override
sal_Int32 addItem(const T &t)
virtual sal_Int32 SAL_CALL getCount() override
virtual bool isValid(const T &) const
called before insertion to determine whether item is valid
void _elementRemoved(const T &aOld)
bool hasItem(const T &t) const
void setItem(sal_Int32 n, const T &t)
void _elementReplaced(const sal_Int32 nPos, const T &aNew)
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 nIndex) override
bool isValidIndex(sal_Int32 n) const
virtual void SAL_CALL insert(const css::uno::Any &aElement) override
virtual sal_Bool SAL_CALL hasElements() override
virtual void _insert(const T &)
called after item has been inserted into the collection
virtual sal_Bool SAL_CALL has(const css::uno::Any &aElement) override
virtual css::uno::Type SAL_CALL getElementType() override
void _elementInserted(sal_Int32 nPos)
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
implement XEnumeration based on container::XIndexAccess
css::uno::Type const & get()
cppu::WeakImplHelper< css::container::XIndexReplace, css::container::XSet, css::container::XContainer > Collection_t