Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef _COMPHELPER_ENUMHELPER_HXX_
21 : #define _COMPHELPER_ENUMHELPER_HXX_
22 :
23 : #include <vector>
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"
32 :
33 : //.........................................................................
34 : namespace comphelper
35 : {
36 : //.........................................................................
37 :
38 : namespace starcontainer = ::com::sun::star::container;
39 : namespace staruno = ::com::sun::star::uno;
40 : namespace starlang = ::com::sun::star::lang;
41 :
42 : //==================================================================
43 : //= OEnumerationLock
44 : //==================================================================
45 8532 : struct OEnumerationLock
46 : {
47 : public:
48 : ::osl::Mutex m_aLock;
49 : };
50 :
51 : //==================================================================
52 : //= OEnumerationByName
53 : //==================================================================
54 : /** provides an com.sun.star.container::XEnumeration access based
55 : on an object implementing the com.sun.star.container::XNameAccess interface
56 : */
57 : class COMPHELPER_DLLPUBLIC OEnumerationByName : private OEnumerationLock
58 : , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration ,
59 : starlang::XEventListener >
60 : {
61 : staruno::Sequence< OUString > m_aNames;
62 : sal_Int32 m_nPos;
63 : staruno::Reference< starcontainer::XNameAccess > m_xAccess;
64 : sal_Bool m_bListening;
65 :
66 : public:
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();
71 :
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);
75 :
76 : virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException);
77 :
78 : private:
79 : COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
80 : COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
81 : };
82 :
83 : //==================================================================
84 : //= OEnumerationByIndex
85 : //==================================================================
86 : /** provides an com.sun.star.container::XEnumeration access based
87 : on an object implementing the com.sun.star.container::XNameAccess interface
88 : */
89 : class COMPHELPER_DLLPUBLIC OEnumerationByIndex : private OEnumerationLock
90 : , public ::cppu::WeakImplHelper2< starcontainer::XEnumeration ,
91 : starlang::XEventListener >
92 : {
93 : sal_Int32 m_nPos;
94 : staruno::Reference< starcontainer::XIndexAccess > m_xAccess;
95 : sal_Bool m_bListening;
96 :
97 : public:
98 : OEnumerationByIndex(const staruno::Reference< starcontainer::XIndexAccess >& _rxAccess);
99 : virtual ~OEnumerationByIndex();
100 :
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);
104 :
105 : virtual void SAL_CALL disposing(const starlang::EventObject& aEvent) throw(staruno::RuntimeException);
106 :
107 : private:
108 : COMPHELPER_DLLPRIVATE void impl_startDisposeListening();
109 : COMPHELPER_DLLPRIVATE void impl_stopDisposeListening();
110 : };
111 :
112 : //==================================================================
113 : //= OAnyEnumeration
114 : //==================================================================
115 : /** provides an com.sun.star.container::XEnumeration
116 : for an outside set vector of Any's.
117 :
118 : */
119 : class COMPHELPER_DLLPUBLIC OAnyEnumeration : private OEnumerationLock
120 : , public ::cppu::WeakImplHelper1< starcontainer::XEnumeration >
121 : {
122 : sal_Int32 m_nPos;
123 : staruno::Sequence< staruno::Any > m_lItems;
124 :
125 : public:
126 : OAnyEnumeration(const staruno::Sequence< staruno::Any >& lItems);
127 : virtual ~OAnyEnumeration();
128 :
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);
132 :
133 : };
134 :
135 : //.........................................................................
136 : }
137 : //... namespace comphelper .......................................................
138 :
139 : #endif // _COMPHELPER_ENUMHELPER_HXX_
140 :
141 :
142 :
143 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|