xref: /trunk/main/forms/source/xforms/enumeration.cxx (revision 24acc546)
1*24acc546SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*24acc546SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*24acc546SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*24acc546SAndrew Rist  * distributed with this work for additional information
6*24acc546SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*24acc546SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*24acc546SAndrew Rist  * "License"); you may not use this file except in compliance
9*24acc546SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*24acc546SAndrew Rist  *
11*24acc546SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*24acc546SAndrew Rist  *
13*24acc546SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*24acc546SAndrew Rist  * software distributed under the License is distributed on an
15*24acc546SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*24acc546SAndrew Rist  * KIND, either express or implied.  See the License for the
17*24acc546SAndrew Rist  * specific language governing permissions and limitations
18*24acc546SAndrew Rist  * under the License.
19*24acc546SAndrew Rist  *
20*24acc546SAndrew Rist  *************************************************************/
21*24acc546SAndrew Rist 
22*24acc546SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_forms.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "enumeration.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <com/sun/star/container/NoSuchElementException.hpp>
30cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/WrappedTargetException.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
33cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir using com::sun::star::container::NoSuchElementException;
36cdf0e10cSrcweir using com::sun::star::container::XIndexAccess;
37cdf0e10cSrcweir using com::sun::star::lang::WrappedTargetException;
38cdf0e10cSrcweir using com::sun::star::uno::Any;
39cdf0e10cSrcweir using com::sun::star::uno::Reference;
40cdf0e10cSrcweir using com::sun::star::uno::RuntimeException;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
Enumeration(XIndexAccess * pContainer)43cdf0e10cSrcweir Enumeration::Enumeration( XIndexAccess* pContainer )
44cdf0e10cSrcweir     : mxContainer( pContainer ),
45cdf0e10cSrcweir       mnIndex( 0 )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     OSL_ENSURE( mxContainer.is(), "no container?" );
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
hasMoreElements()50cdf0e10cSrcweir sal_Bool Enumeration::hasMoreElements()
51cdf0e10cSrcweir     throw( RuntimeException )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     if( ! mxContainer.is() )
54cdf0e10cSrcweir         throw RuntimeException();
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     return mnIndex < mxContainer->getCount();
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
nextElement()59cdf0e10cSrcweir Any Enumeration::nextElement()
60cdf0e10cSrcweir     throw( NoSuchElementException,
61cdf0e10cSrcweir            WrappedTargetException,
62cdf0e10cSrcweir            RuntimeException )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     if( ! mxContainer.is() )
65cdf0e10cSrcweir         throw RuntimeException();
66cdf0e10cSrcweir     if( mnIndex >= mxContainer->getCount() )
67cdf0e10cSrcweir         throw NoSuchElementException();
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     return mxContainer->getByIndex( mnIndex++ );
70cdf0e10cSrcweir }
71