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( ); 77 virtual staruno::Any SAL_CALL nextElement( ); 78 79 virtual void SAL_CALL disposing(const starlang::EventObject& aEvent); 80 81 private: 82 COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); 83 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); 84 }; 85 86 //================================================================== 87 //= OEnumerationByIndex 88 //================================================================== 89 /** provides an <type scope="com.sun.star.container">XEnumeration</type> access based 90 on an object implementing the <type scope="com.sun.star.container">XNameAccess</type> interface 91 */ 92 class COMPHELPER_DLLPUBLIC OEnumerationByIndex : private OEnumerationLock 93 , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration , 94 starlang::XEventListener > 95 { 96 sal_Int32 m_nPos; 97 staruno::Reference< starcontainer::XIndexAccess > m_xAccess; 98 sal_Bool m_bListening; 99 100 public: 101 OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess); 102 virtual ~OEnumerationByIndex(); 103 104 virtual sal_Bool SAL_CALL hasMoreElements( ); 105 virtual staruno::Any SAL_CALL nextElement( ); 106 107 virtual void SAL_CALL disposing(const starlang::EventObject& aEvent); 108 109 private: 110 COMPHELPER_DLLPRIVATE void impl_startDisposeListening(); 111 COMPHELPER_DLLPRIVATE void impl_stopDisposeListening(); 112 }; 113 114 //================================================================== 115 //= OAnyEnumeration 116 //================================================================== 117 /** provides an <type scope="com.sun.star.container">XEnumeration</type> 118 for an outside set vector of Any's. 119 120 */ 121 class COMPHELPER_DLLPUBLIC OAnyEnumeration : private OEnumerationLock 122 , public ::cppu::WeakImplHelper1< starcontainer::XEnumeration > 123 { 124 sal_Int32 m_nPos; 125 staruno::Sequence< staruno::Any > m_lItems; 126 127 public: 128 OAnyEnumeration(const staruno::Sequence< staruno::Any >& lItems); 129 virtual ~OAnyEnumeration(); 130 131 virtual sal_Bool SAL_CALL hasMoreElements( ); 132 virtual staruno::Any SAL_CALL nextElement( ); 133 134 }; 135 136 //......................................................................... 137 } 138 //... namespace comphelper ....................................................... 139 140 #endif // _COMPHELPER_ENUMHELPER_HXX_ 141