xref: /trunk/main/framework/inc/helper/ocomponentenumeration.hxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
25 #define __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //  my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #ifndef __FRAMEWORK_OMUTEXMEMBER_HXX_
32 #include <threadhelp/threadhelpbase.hxx>
33 #endif
34 #include <macros/generic.hxx>
35 #include <macros/xinterface.hxx>
36 #include <macros/xtypeprovider.hxx>
37 #include <macros/debug.hxx>
38 #include <general.h>
39 
40 //_________________________________________________________________________________________________________________
41 //  interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/lang/XEventListener.hpp>
44 #include <com/sun/star/container/XEnumeration.hpp>
45 #include <com/sun/star/lang/XComponent.hpp>
46 
47 //_________________________________________________________________________________________________________________
48 //  other includes
49 //_________________________________________________________________________________________________________________
50 #include <cppuhelper/implbase2.hxx>
51 
52 //_________________________________________________________________________________________________________________
53 //  namespace
54 //_________________________________________________________________________________________________________________
55 
56 namespace framework{
57 
58 //_________________________________________________________________________________________________________________
59 //  exported const
60 //_________________________________________________________________________________________________________________
61 
62 //_________________________________________________________________________________________________________________
63 //  exported definitions
64 //_________________________________________________________________________________________________________________
65 
66 /*-************************************************************************************************************//**
67     @short          implement a helper for a oneway enumeration of components
68     @descr          You can step during this list only for one time! Its a snapshot.
69                     Don't forget to release the reference. You are the owner of an instance of this implementation.
70                     You can't use this as a baseclass. Please use it as a dynamical object for return.
71 
72     @implements     XInterface
73                     XTypeProvider
74                     XEventListener
75                     XEnumeration
76 
77     @base           ThreadHelpBase
78                     OWeakObject
79 
80     @devstatus      ready to use
81     @threadsafe     yes
82 *//*-*************************************************************************************************************/
83 
84 class OComponentEnumeration :   public ThreadHelpBase               ,
85                                 public ::cppu::WeakImplHelper2< ::com::sun::star::container::XEnumeration,::com::sun::star::lang::XEventListener >
86 {
87     //-------------------------------------------------------------------------------------------------------------
88     //  public methods
89     //-------------------------------------------------------------------------------------------------------------
90 
91     public:
92 
93         //---------------------------------------------------------------------------------------------------------
94         //  constructor / destructor
95         //---------------------------------------------------------------------------------------------------------
96 
97         /*-****************************************************************************************************//**
98             @short      constructor to initialize this enumeration
99             @descr      An enumeration is a list with oneway-access! You can get every member only for one time.
100                         This method allow to initialize this oneway list with values.
101 
102             @seealso    -
103 
104             @param      "seqComponents" is a sequence of interfaces, which are components.
105             @return     -
106 
107             @onerror    Do nothing and reset this object to default with an empty list.
108         *//*-*****************************************************************************************************/
109 
110         OComponentEnumeration( const css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >& seqComponents );
111 
112         //---------------------------------------------------------------------------------------------------------
113         //  XEventListener
114         //---------------------------------------------------------------------------------------------------------
115 
116         /*-****************************************************************************************************//**
117             @short      last chance to release all references and free memory
118             @descr      This method is called, if the enumeration is used completely and has no more elements.
119                         Then we must destroy our list and release all references to other objects.
120 
121             @seealso    interface XEventListener
122 
123             @param      "aEvent" describe the source of this event.
124             @return     -
125 
126             @onerror    -
127         *//*-*****************************************************************************************************/
128 
129         virtual void SAL_CALL disposing( const css::lang::EventObject& aEvent );
130 
131         //---------------------------------------------------------------------------------------------------------
132         //  XEnumeration
133         //---------------------------------------------------------------------------------------------------------
134 
135         /*-****************************************************************************************************//**
136             @short      check count of accessible elements of enumeration
137             @descr      You can call this method to get information about accessible elements in future.
138                         Elements you have already getted are not accessible!
139 
140             @seealso    interface XEnumeration
141 
142             @param      -
143             @return     sal_True  = if more elements accessible<BR>
144                         sal_False = other way
145 
146             @onerror    sal_False<BR>
147                         (List is emtpy and there no accessible elements ...)
148         *//*-*****************************************************************************************************/
149 
150         virtual sal_Bool SAL_CALL hasMoreElements();
151 
152         /*-****************************************************************************************************//**
153             @short      give the next element, if some exist
154             @descr      If a call "hasMoreElements()" return true, you can get the next element of list.
155 
156             @seealso    interface XEnumeration
157 
158             @param      -
159             @return     A Reference to a component, safed in an Any-structure.
160 
161             @onerror    If end of enumeration is arrived or there are no elements in list => a NoSuchElementException is thrown.
162         *//*-*****************************************************************************************************/
163 
164         virtual css::uno::Any SAL_CALL nextElement();
165 
166     //-------------------------------------------------------------------------------------------------------------
167     //  protected methods
168     //-------------------------------------------------------------------------------------------------------------
169 
170     protected:
171 
172         /*-****************************************************************************************************//**
173             @short      standard destructor
174             @descr      This method destruct an instance of this class and clear some member.
175                         We make it protected, because its not supported to use this class as normal instance!
176                         You must create it dynamical in memory and use a pointer.
177 
178             @seealso    -
179 
180             @param      -
181             @return     -
182 
183             @onerror    -
184         *//*-*****************************************************************************************************/
185 
186         virtual ~OComponentEnumeration();
187 
188         /*-****************************************************************************************************//**
189             @short      reset instance to default values
190 
191             @descr      There are two ways to delete an instance of this class.<BR>
192                         1) delete with destructor<BR>
193                         2) dispose from parent or factory ore ...<BR>
194                         This method do the same for both ways! It free used memory and release references ...
195 
196             @seealso    method dispose()
197             @seealso    destructor ~TaskEnumeration()
198 
199             @param      -
200 
201             @return     -
202 
203             @onerror    -
204         *//*-*****************************************************************************************************/
205 
206         virtual void impl_resetObject();
207 
208     //-------------------------------------------------------------------------------------------------------------
209     //  private methods
210     //-------------------------------------------------------------------------------------------------------------
211 
212     private:
213 
214     //-------------------------------------------------------------------------------------------------------------
215     //  debug methods
216     //  (should be private everyway!)
217     //-------------------------------------------------------------------------------------------------------------
218 
219         /*-****************************************************************************************************//**
220             @short      debug-method to check incoming parameter of some other methods of this class
221             @descr      The following methods are used to check parameters for other methods
222                         of this class. The return value is used directly for an ASSERT(...).
223 
224             @seealso    ASSERT in implementation!
225 
226             @param      references to checking variables
227             @return     sal_False on invalid parameter<BR>
228                         sal_True  otherway
229 
230             @onerror    -
231         *//*-*****************************************************************************************************/
232 
233     #ifdef ENABLE_ASSERTIONS
234 
235     private:
236 
237         static sal_Bool impldbg_checkParameter_OComponentEnumerationCtor    (   const   css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >& seqComponents   );
238         static sal_Bool impldbg_checkParameter_disposing                    (   const   css::lang::EventObject&                                             aEvent          );
239 
240     #endif  // #ifdef ENABLE_ASSERTIONS
241 
242     //-------------------------------------------------------------------------------------------------------------
243     //  variables
244     //  (should be private everyway!)
245     //-------------------------------------------------------------------------------------------------------------
246 
247     private:
248 
249         sal_uInt32                                                              m_nPosition         ;   /// current position in enumeration
250         css::uno::Sequence< css::uno::Reference< css::lang::XComponent > >      m_seqComponents     ;   /// list of current components
251 
252 };      //  class OComponentEnumeration
253 
254 }       //  namespace framework
255 
256 #endif  //  #ifndef __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
257