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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_forms.hxx"
26 
27 #include "enumeration.hxx"
28 
29 #include <com/sun/star/container/NoSuchElementException.hpp>
30 #include <com/sun/star/container/XIndexAccess.hpp>
31 #include <com/sun/star/lang/WrappedTargetException.hpp>
32 #include <com/sun/star/uno/Any.hxx>
33 #include <com/sun/star/uno/RuntimeException.hpp>
34 
35 using com::sun::star::container::NoSuchElementException;
36 using com::sun::star::container::XIndexAccess;
37 using com::sun::star::lang::WrappedTargetException;
38 using com::sun::star::uno::Any;
39 using com::sun::star::uno::Reference;
40 using com::sun::star::uno::RuntimeException;
41 
42 
Enumeration(XIndexAccess * pContainer)43 Enumeration::Enumeration( XIndexAccess* pContainer )
44     : mxContainer( pContainer ),
45       mnIndex( 0 )
46 {
47     OSL_ENSURE( mxContainer.is(), "no container?" );
48 }
49 
hasMoreElements()50 sal_Bool Enumeration::hasMoreElements()
51     throw( RuntimeException )
52 {
53     if( ! mxContainer.is() )
54         throw RuntimeException();
55 
56     return mnIndex < mxContainer->getCount();
57 }
58 
nextElement()59 Any Enumeration::nextElement()
60     throw( NoSuchElementException,
61            WrappedTargetException,
62            RuntimeException )
63 {
64     if( ! mxContainer.is() )
65         throw RuntimeException();
66     if( mnIndex >= mxContainer->getCount() )
67         throw NoSuchElementException();
68 
69     return mxContainer->getByIndex( mnIndex++ );
70 }
71