1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef _COMPHELPER_ENUMHELPER_HXX_
21 #define _COMPHELPER_ENUMHELPER_HXX_
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XEnumeration.hpp>
26 #include <com/sun/star/container/XIndexAccess.hpp>
27 #include <com/sun/star/lang/XEventListener.hpp>
28 #include <cppuhelper/implbase1.hxx>
29 #include <cppuhelper/implbase2.hxx>
30 #include <osl/mutex.hxx>
31 #include "comphelper/comphelperdllapi.h"
33 //.........................................................................
36 //.........................................................................
38 namespace starcontainer
= ::com::sun::star::container
;
39 namespace staruno
= ::com::sun::star::uno
;
40 namespace starlang
= ::com::sun::star::lang
;
42 //==================================================================
44 //==================================================================
45 struct OEnumerationLock
51 //==================================================================
52 //= OEnumerationByName
53 //==================================================================
54 /** provides an <type scope="com.sun.star.container">XEnumeration</type> access based
55 on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface
57 class COMPHELPER_DLLPUBLIC OEnumerationByName
: private OEnumerationLock
58 , public ::cppu::WeakImplHelper2
< starcontainer::XEnumeration
,
59 starlang::XEventListener
>
61 staruno::Sequence
< OUString
> m_aNames
;
63 staruno::Reference
< starcontainer::XNameAccess
> m_xAccess
;
64 sal_Bool m_bListening
;
67 OEnumerationByName(const staruno::Reference
< starcontainer::XNameAccess
>& _rxAccess
);
68 OEnumerationByName(const staruno::Reference
< starcontainer::XNameAccess
>& _rxAccess
,
69 const staruno::Sequence
< OUString
>& _aNames
);
70 virtual ~OEnumerationByName();
72 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw(staruno::RuntimeException
);
73 virtual staruno::Any SAL_CALL
nextElement( )
74 throw(starcontainer::NoSuchElementException
, starlang::WrappedTargetException
, staruno::RuntimeException
);
76 virtual void SAL_CALL
disposing(const starlang::EventObject
& aEvent
) throw(staruno::RuntimeException
);
79 COMPHELPER_DLLPRIVATE
void impl_startDisposeListening();
80 COMPHELPER_DLLPRIVATE
void impl_stopDisposeListening();
83 //==================================================================
84 //= OEnumerationByIndex
85 //==================================================================
86 /** provides an <type scope="com.sun.star.container">XEnumeration</type> access based
87 on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface
89 class COMPHELPER_DLLPUBLIC OEnumerationByIndex
: private OEnumerationLock
90 , public ::cppu::WeakImplHelper2
< starcontainer::XEnumeration
,
91 starlang::XEventListener
>
94 staruno::Reference
< starcontainer::XIndexAccess
> m_xAccess
;
95 sal_Bool m_bListening
;
98 OEnumerationByIndex(const staruno::Reference
< starcontainer::XIndexAccess
>& _rxAccess
);
99 virtual ~OEnumerationByIndex();
101 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw(staruno::RuntimeException
);
102 virtual staruno::Any SAL_CALL
nextElement( )
103 throw(starcontainer::NoSuchElementException
, starlang::WrappedTargetException
, staruno::RuntimeException
);
105 virtual void SAL_CALL
disposing(const starlang::EventObject
& aEvent
) throw(staruno::RuntimeException
);
108 COMPHELPER_DLLPRIVATE
void impl_startDisposeListening();
109 COMPHELPER_DLLPRIVATE
void impl_stopDisposeListening();
112 //==================================================================
114 //==================================================================
115 /** provides an <type scope="com.sun.star.container">XEnumeration</type>
116 for an outside set vector of Any's.
119 class COMPHELPER_DLLPUBLIC OAnyEnumeration
: private OEnumerationLock
120 , public ::cppu::WeakImplHelper1
< starcontainer::XEnumeration
>
123 staruno::Sequence
< staruno::Any
> m_lItems
;
126 OAnyEnumeration(const staruno::Sequence
< staruno::Any
>& lItems
);
127 virtual ~OAnyEnumeration();
129 virtual sal_Bool SAL_CALL
hasMoreElements( ) throw(staruno::RuntimeException
);
130 virtual staruno::Any SAL_CALL
nextElement( )
131 throw(starcontainer::NoSuchElementException
, starlang::WrappedTargetException
, staruno::RuntimeException
);
135 //.........................................................................
137 //... namespace comphelper .......................................................
139 #endif // _COMPHELPER_ENUMHELPER_HXX_
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */