Codemesh Runtime v3 C++ API Reference  3.9.205
xmog_iterator.h
1 //
2 // Copyright (c) 1999-2020 by Codemesh, Inc.. ALL RIGHTS RESERVED.
3 //
4 
5 #ifndef xmog_iterator_inc
6 #define xmog_iterator_inc
7 
8 
9 #include "xmog_java_client.h"
10 
11 
18 struct Iterator_tag {};
19 
20 
27 struct Enumeration_tag {};
28 
29 
34 class XMOG_DECLSPEC xmog_iterator_base
35 {
36 private:
37 
38  xmog_base collection_;
39  xmog_base iterator_;
40  xmog_base current_;
41 
42  const xmog_java_class * clazz_;
43  xmog_java_method * next_;
44  xmog_java_method * hasNext_;
45  xmog_java_method * previous_;
46  xmog_java_method * hasPrevious_;
47  xmog_java_method * size_;
48  jint index_;
49 
50  void init( xmog_localenv * env );
51 
52 protected:
53 
54  void copy( const xmog_iterator_base & rhs );
55 
56  jobject inner_current( xmog_localenv * env = NULL, xmog_flags flags = xmogDefaultFlags );
57 
58  void inner_next( xmog_localenv * env = NULL, xmog_flags flags = xmogDefaultFlags );
59 
60  bool inner_hasNext( xmog_localenv * env = NULL );
61 
62  void inner_previous( xmog_localenv * env = NULL, xmog_flags flags = xmogDefaultFlags );
63 
64  bool inner_hasPrevious( xmog_localenv * env = NULL );
65 
66  jint inner_size( xmog_localenv * env = NULL ) const;
67 
68 public:
69 
70  enum
71  {
72  xmogDefaultFlags = xmog_base::GLOBAL,
73  BEGIN_INDEX = -1,
74  END_INDEX = -2,
75  RBEGIN_INDEX = -3,
76  REND_INDEX = -4
77  };
78 
80 
81  xmog_iterator_base( const xmog_base & collection, const xmog_java_class & clazz, jint ind );
82 
84 
85  xmog_iterator_base( const xmog_iterator_base & rhs, bool inc, bool dec );
86 
88 
89  bool operator != ( const xmog_iterator_base & rhs ) const;
90 
91  bool operator == ( const xmog_iterator_base & rhs ) const;
92 
93  bool operator < ( const xmog_iterator_base & rhs ) const;
94 
95  bool operator <= ( const xmog_iterator_base & rhs ) const;
96 
97  bool operator > ( const xmog_iterator_base & rhs ) const;
98 
99  bool operator >= ( const xmog_iterator_base & rhs ) const;
100 
101 };
102 
103 
104 template< typename Elem >
106 {
107 private:
108 
109  Elem current;
110 
111 public:
112 
115  current()
116  {
117  }
118 
119  xmog_iterator<Elem>( const xmog_base & collection, const xmog_java_class & clazz, jint ind ) :
120  xmog_iterator_base( collection, clazz, ind ),
121  current( inner_current(), xmogDefaultFlags )
122  {
123  }
124 
126  xmog_iterator_base( rhs ),
127  current( rhs.current )
128  {
129  }
130 
131  xmog_iterator<Elem>( const xmog_iterator<Elem> & rhs, bool inc ) :
132  xmog_iterator_base( rhs, true, false ),
133  current( inner_current(), xmogDefaultFlags )
134  {
135  }
136 
138  {
139  }
140 
141  xmog_iterator<Elem> & operator = ( const xmog_iterator<Elem> & rhs )
142  {
143  copy( rhs );
144  current = rhs.current;
145  return *this;
146  }
147 
148  operator Elem & ()
149  {
150  return current;
151  }
152 
153  Elem & operator * ()
154  {
155  return current;
156  }
157 
158  const Elem & operator * () const
159  {
160  return current;
161  }
162 
163  Elem * operator -> ()
164  {
165  return &current;
166  }
167 
168  Elem * const operator -> () const
169  {
170  return &current;
171  }
172 
173  xmog_iterator<Elem> & operator ++ ()
174  {
175  inner_next();
176  current = Elem( inner_current(), xmogDefaultFlags );
177  return *this;
178  }
179 
180  xmog_iterator<Elem> operator ++ ( int )
181  {
182  xmog_iterator<Elem> result( *this );
183  inner_next();
184  current = Elem( inner_current(), xmogDefaultFlags );
185  return result;
186  }
187 };
188 
189 
190 template< typename Elem >
192 {
193 private:
194 
195  Elem current;
196 
197 public:
198 
201  current()
202  {
203  }
204 
205  xmog_reverse_iterator<Elem>( const xmog_base & collection, const xmog_java_class & clazz, jint ind ) :
206  xmog_iterator_base( collection, clazz, ind ),
207  current( inner_current(), xmogDefaultFlags )
208  {
209  }
210 
212  xmog_iterator_base( rhs ),
213  current( rhs.current )
214  {
215  }
216 
218  xmog_iterator_base( rhs, false, true ),
219  current( inner_current(), xmogDefaultFlags )
220  {
221  }
222 
224  {
225  }
226 
227  xmog_reverse_iterator<Elem> & operator = ( const xmog_reverse_iterator<Elem> & rhs )
228  {
229  copy( rhs );
230  current = rhs.current;
231  return *this;
232  }
233 
234  operator Elem & ()
235  {
236  return current;
237  }
238 
239  Elem & operator * ()
240  {
241  return current;
242  }
243 
244  const Elem & operator * () const
245  {
246  return current;
247  }
248 
249  Elem * const operator -> () const
250  {
251  return &current;
252  }
253 
254  xmog_reverse_iterator<Elem> & operator -- ()
255  {
256  inner_previous();
257  current = Elem( inner_current(), xmogDefaultFlags );
258  return *this;
259  }
260 
261  xmog_reverse_iterator<Elem> operator -- ( int )
262  {
263  xmog_reverse_iterator<Elem> result( *this );
264  inner_previous();
265  current = Elem( inner_current(), xmogDefaultFlags );
266  return result;
267  }
268 };
269 
270 
271 template< typename Elem >
273 {
274 private:
275 
276  Elem current;
277 
278 public:
279 
282  current()
283  {
284  }
285 
286  xmog_bidir_iterator<Elem>( const xmog_base & collection, const xmog_java_class & clazz, jint ind ) :
287  xmog_iterator_base( collection, clazz, ind ),
288  current( inner_current(), xmogDefaultFlags )
289  {
290  }
291 
293  xmog_iterator_base( rhs ),
294  current( rhs.current )
295  {
296  }
297 
298  xmog_bidir_iterator<Elem>( const xmog_bidir_iterator<Elem> & rhs, bool inc, bool dec ) :
299  xmog_iterator_base( rhs, inc, dec ),
300  current( inner_current(), xmogDefaultFlags )
301  {
302  }
303 
305  {
306  }
307 
308  xmog_bidir_iterator<Elem> & operator = ( const xmog_bidir_iterator<Elem> & rhs )
309  {
310  copy( rhs );
311  current = rhs.current;
312  return *this;
313  }
314 
315  operator Elem & ()
316  {
317  return current;
318  }
319 
320  Elem & operator * ()
321  {
322  return current;
323  }
324 
325  Elem * operator -> ()
326  {
327  return &current;
328  }
329 
330  xmog_bidir_iterator<Elem> & operator ++ ()
331  {
332  inner_next();
333  current = Elem( inner_current(), xmogDefaultFlags );
334  return *this;
335  }
336 
337  xmog_bidir_iterator<Elem> operator ++ ( int )
338  {
339  xmog_bidir_iterator<Elem> result( *this );
340  inner_next();
341  current = Elem( inner_current(), xmogDefaultFlags );
342  return result;
343  }
344 
345  xmog_bidir_iterator<Elem> & operator -- ()
346  {
347  inner_previous();
348  current = Elem( inner_current(), xmogDefaultFlags );
349  return *this;
350  }
351 
352  xmog_bidir_iterator<Elem> operator -- ( int )
353  {
354  xmog_bidir_iterator<Elem> result( *this );
355  inner_previous();
356  current = Elem( inner_current(), xmogDefaultFlags );
357  return result;
358  }
359 };
360 
361 #if (XMOG_SUPPORTS_STL == 1)
362 
363 #include <iterator>
364 
365 template< typename Elem > struct std::iterator_traits< xmog_iterator< Elem > >
366 {
367  typedef ptrdiff_t difference_type;
368  typedef Elem value_type;
369  typedef Elem* pointer;
370  typedef Elem& reference;
371  typedef std::forward_iterator_tag iterator_category;
372 };
373 
374 template< typename Elem > struct std::iterator_traits< xmog_bidir_iterator< Elem > >
375 {
376  typedef ptrdiff_t difference_type;
377  typedef Elem value_type;
378  typedef Elem* pointer;
379  typedef Elem& reference;
380  typedef std::bidirectional_iterator_tag iterator_category;
381 };
382 
383 #endif /* XMOG_SUPPORTS_STL */
384 
385 #endif /* ifndef xmog_iterator_inc */
Enumeration_tag
A type that is used for template specializtion of iterators.
Definition: xmog_iterator.h:27
xmog_bidir_iterator
Definition: xmog_iterator.h:272
xmog_java_method
A class implementing the xmog_java_dynamic interface for accessing Java methods via JNI or Codemesh's...
Definition: xmog_java_method.h:38
xmog_base
The baseclass for all proxy types in the framework.
Definition: xmog_base.h:29
xmog_localenv
A class representing per-thread information for the integration runtime.
Definition: xmog_localenv.h:32
xmog_iterator_base
The runtime library class that provides services to C++ iterators over Java collections.
Definition: xmog_iterator.h:34
Iterator_tag
A type that is used for template specialization of iterators.
Definition: xmog_iterator.h:18
xmog_iterator
Definition: xmog_iterator.h:105
xmog_java_class
A C++ wrapper for Java types.
Definition: xmog_java_class.h:31
xmog_reverse_iterator
Definition: xmog_iterator.h:191

Copyright (c) 1999-2020 by Codemesh, Inc., ALL RIGHTS RESERVED.