merge the formfield patch from ooo-build
[ooovba.git] / framework / source / helper / ocomponentenumeration.cxx
blobed386663801200b9341687124f058ec91f228163
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ocomponentenumeration.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include <helper/ocomponentenumeration.hxx>
39 #ifndef _FRAMEWORK_THREADHELP_RESETABLEGUARD_HXX_
40 #include <threadhelp/resetableguard.hxx>
41 #endif
43 //_________________________________________________________________________________________________________________
44 // interface includes
45 //_________________________________________________________________________________________________________________
47 //_________________________________________________________________________________________________________________
48 // includes of other projects
49 //_________________________________________________________________________________________________________________
50 #include <vcl/svapp.hxx>
52 //_________________________________________________________________________________________________________________
53 // namespace
54 //_________________________________________________________________________________________________________________
56 namespace framework{
58 using namespace ::com::sun::star::container ;
59 using namespace ::com::sun::star::lang ;
60 using namespace ::com::sun::star::uno ;
61 using namespace ::cppu ;
62 using namespace ::osl ;
63 using namespace ::rtl ;
65 //_________________________________________________________________________________________________________________
66 // non exported const
67 //_________________________________________________________________________________________________________________
69 //_________________________________________________________________________________________________________________
70 // non exported definitions
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
74 // declarations
75 //_________________________________________________________________________________________________________________
77 //*****************************************************************************************************************
78 // constructor
79 //*****************************************************************************************************************
80 OComponentEnumeration::OComponentEnumeration( const Sequence< Reference< XComponent > >& seqComponents )
81 // Init baseclasses first
82 // Attention:
83 // Don't change order of initialization!
84 // ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
85 // we must garant right initialization and a valid value of this! First initialize
86 // baseclasses and then members. And we need the mutex for other baseclasses !!!
87 : ThreadHelpBase ( &Application::GetSolarMutex() )
88 // Init member
89 , m_nPosition ( 0 ) // 0 is the first position for a valid list and the right value for an invalid list to!
90 , m_seqComponents ( seqComponents )
92 // Safe impossible states
93 // "Method" not defined for ALL parameters!
94 LOG_ASSERT( impldbg_checkParameter_OComponentEnumerationCtor( seqComponents ), "OComponentEnumeration::OComponentEnumeration()\nInvalid parameter detected!\n" )
97 //*****************************************************************************************************************
98 // destructor
99 //*****************************************************************************************************************
100 OComponentEnumeration::~OComponentEnumeration()
102 // Reset instance, free memory ....
103 impl_resetObject();
106 //*****************************************************************************************************************
107 // XEventListener
108 //*****************************************************************************************************************
109 void SAL_CALL OComponentEnumeration::disposing( const EventObject&
110 #if OSL_DEBUG_LEVEL > 0
111 aEvent
112 #endif
113 ) throw( RuntimeException )
115 // Ready for multithreading
116 ResetableGuard aGuard( m_aLock );
118 // Safe impossible cases
119 // This method is not specified for all incoming parameters.
120 LOG_ASSERT( impldbg_checkParameter_disposing( aEvent ), "OComponentEnumeration::disposing()\nInvalid parameter detected!\n" )
122 // Reset instance to defaults, release references and free memory.
123 impl_resetObject();
126 //*****************************************************************************************************************
127 // XEnumeration
128 //*****************************************************************************************************************
129 sal_Bool SAL_CALL OComponentEnumeration::hasMoreElements() throw( RuntimeException )
131 // Ready for multithreading
132 ResetableGuard aGuard( m_aLock );
134 // First position in a valid list is 0.
135 // => The last one is getLength() - 1!
136 // m_nPosition's current value is the position for the next element, which will be return, if user call "nextElement()"
137 // => We have more elements if current position less then the length of the list!
138 return ( m_nPosition < (sal_uInt32)(m_seqComponents.getLength()) );
141 //*****************************************************************************************************************
142 // XEnumeration
143 //*****************************************************************************************************************
144 Any SAL_CALL OComponentEnumeration::nextElement() throw( NoSuchElementException ,
145 WrappedTargetException ,
146 RuntimeException )
148 // Ready for multithreading
149 ResetableGuard aGuard( m_aLock );
151 // If we have no elements or end of enumeration is arrived ...
152 if ( hasMoreElements() == sal_False )
154 // .. throw an exception!
155 throw NoSuchElementException();
158 // Else; Get next element from list ...
159 Any aComponent;
160 aComponent <<= m_seqComponents[m_nPosition];
161 // ... and step to next element!
162 ++m_nPosition;
164 // Return listitem.
165 return aComponent;
168 //*****************************************************************************************************************
169 // proteced method
170 //*****************************************************************************************************************
171 void OComponentEnumeration::impl_resetObject()
173 // Attention:
174 // Write this for multiple calls - NOT AT THE SAME TIME - but for more then one call again)!
175 // It exist two ways to call this method. From destructor and from disposing().
176 // I can't say, which one is the first. Normaly the disposing-call - but other way ....
178 // Delete list of components.
179 m_seqComponents.realloc( 0 );
180 // Reset position in list.
181 // The list has no elements anymore. m_nPosition is normaly the current position in list for nextElement!
182 // But a position of 0 in a list of 0 items is an invalid state. This constellation can't work in future.
183 // End of enumeration is arrived!
184 // (see hasMoreElements() for more details...)
185 m_nPosition = 0 ;
188 //_________________________________________________________________________________________________________________
189 // debug methods
190 //_________________________________________________________________________________________________________________
192 /*-----------------------------------------------------------------------------------------------------------------
193 The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
194 we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!
196 ATTENTION
198 If you miss a test for one of this parameters, contact the autor or add it himself !(?)
199 But ... look for right testing! See using of this methods!
200 -----------------------------------------------------------------------------------------------------------------*/
202 #ifdef ENABLE_ASSERTIONS
204 //*****************************************************************************************************************
205 // An empty list is allowed ... hasMoreElements() will return false then!
206 sal_Bool OComponentEnumeration::impldbg_checkParameter_OComponentEnumerationCtor( const Sequence< Reference< XComponent > >& seqComponents )
208 // Set default return value.
209 sal_Bool bOK = sal_True;
210 // Check parameter.
211 if (
212 ( &seqComponents == NULL )
215 bOK = sal_False ;
217 // Return result of check.
218 return bOK ;
221 //*****************************************************************************************************************
222 sal_Bool OComponentEnumeration::impldbg_checkParameter_disposing( const EventObject& aEvent )
224 // Set default return value.
225 sal_Bool bOK = sal_True;
226 // Check parameter.
227 if (
228 ( &aEvent == NULL ) ||
229 ( aEvent.Source.is() == sal_False )
232 bOK = sal_False ;
234 // Return result of check.
235 return bOK ;
238 #endif // #ifdef ENABLE_ASSERTIONS
240 } // namespace framework