1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef _COMPHELPER_ENUMHELPER_HXX_ 25 #define _COMPHELPER_ENUMHELPER_HXX_ 26 27 #include <vector> 28 #include <com/sun/star/container/XNameAccess.hpp> 29 #include <com/sun/star/container/XEnumeration.hpp> 30 #include <com/sun/star/container/XIndexAccess.hpp> 31 #include <com/sun/star/lang/XEventListener.hpp> 32 #include <cppuhelper/implbase1.hxx> 33 #include <cppuhelper/implbase2.hxx> 34 #include <osl/mutex.hxx> 35 #include "comphelper/comphelperdllapi.h" 36 37 //......................................................................... 38 namespace comphelper 39 { 40 //......................................................................... 41 42 namespace starcontainer = ::com::sun::star::container; 43 namespace staruno = ::com::sun::star::uno; 44 namespace starlang = ::com::sun::star::lang; 45 46 //================================================================== 47 //= OEnumerationLock 48 //================================================================== 49 struct OEnumerationLock 50 { 51 public: 52 ::osl::Mutex m_aLock; 53 }; 54 55 //================================================================== 56 //= OEnumerationByName 57 //================================================================== 58 /** provides an <type scope="com.sun.star.container">XEnumeration</type> access based 59 on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface 60 */ 61 class COMPHELPER_DLLPUBLIC OEnumerationByName : private OEnumerationLock 62 , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration , 63 starlang::XEventListener > 64 { 65 staruno::Sequence< ::rtl::OUString > m_aNames; 66 sal_Int32 m_nPos; 67 staruno::Reference< starcontainer::XNameAccess > m_xAccess; 68 sal_Bool m_bListening; 69 70 public: 71 OEnumerationByName(const staruno::Reference< starcontainer::XNameAccess >& _rxAccess); 72 OEnumerationByName(const staruno::Reference< starcontainer::XNameAccess >& _rxAccess, 73 const staruno::Sequence< ::rtl::OUString >& _aNames ); 74 virtual ~OEnumerationByName(); 75 76 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); 77 virtual staruno::Any SAL_CALL nextElement( ) 78 throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); 79 80 virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException); 81 82 private: 83 COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); 84 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); 85 }; 86 87 //================================================================== 88 //= OEnumerationByIndex 89 //================================================================== 90 /** provides an <type scope="com.sun.star.container">XEnumeration</type> access based 91 on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface 92 */ 93 class COMPHELPER_DLLPUBLIC OEnumerationByIndex : private OEnumerationLock 94 , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration , 95 starlang::XEventListener > 96 { 97 sal_Int32 m_nPos; 98 staruno::Reference< starcontainer::XIndexAccess > m_xAccess; 99 sal_Bool m_bListening; 100 101 public: 102 OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess); 103 virtual ~OEnumerationByIndex(); 104 105 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); 106 virtual staruno::Any SAL_CALL nextElement( ) 107 throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); 108 109 virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException); 110 111 private: 112 COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); 113 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); 114 }; 115 116 //================================================================== 117 //= OAnyEnumeration 118 //================================================================== 119 /** provides an <type scope="com.sun.star.container">XEnumeration</type> 120 for an outside set vector of Any's. 121 122 */ 123 class COMPHELPER_DLLPUBLIC OAnyEnumeration : private OEnumerationLock 124 , public ::cppu::WeakImplHelper1< starcontainer::XEnumeration > 125 { 126 sal_Int32 m_nPos; 127 staruno::Sequence< staruno::Any > m_lItems; 128 129 public: 130 OAnyEnumeration(const staruno::Sequence< staruno::Any >& lItems); 131 virtual ~OAnyEnumeration(); 132 133 virtual sal_Bool SAL_CALL hasMoreElements( ) throw(staruno::RuntimeException); 134 virtual staruno::Any SAL_CALL nextElement( ) 135 throw(starcontainer::NoSuchElementException, starlang::WrappedTargetException, staruno::RuntimeException); 136 137 }; 138 139 //......................................................................... 140 } 141 //... namespace comphelper ....................................................... 142 143 #endif // _COMPHELPER_ENUMHELPER_HXX_ 144 145 146 147