ZeusBase-Library  2.0.4
Iterators.hpp
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (C) 2011 by Benjamin Hadorn (b_hadorn@bluewin.ch)
3  *****************************************************************************
4  * Project : Zeus Base Library
5  * Module : Iterators
6  * Package : Zeus.ZeusBase.System
7  * Author : Benjamin Hadorn
8  * Date : 27.12.2011
9  * System : Zeus-Framework
10  *****************************************************************************
11  * Licence: *
12  * This library is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU Lesser General Public License as *
14  * published by the Free Software Foundation; either version *
15  * 2.1 of the License, or (at your option) any later version. *
16  * *
17  * This library is distributed in the hope that it will be useful, *
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
20  * GNU Lesser General Public License for more details. *
21  * *
22  * You should have received a copy of the GNU Lesser General Public *
23  * License along with this library; if not, write to the Free Software *
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
25  *****************************************************************************/
26 
27 /*****************************************************************************
28  * Changes:
29  * 27.12.2011 bha: created zeus 2.0
30  *****************************************************************************/
31 
32 #ifndef IteratorsHPP
33 #define IteratorsHPP
34 
38 #include <assert.h>
39 
41 
42 /****************************************************************************/
48 /****************************************************************************/
49 template <class T> class TAbstractIterator : public TAutoPtrBase<IListIterator<T> >, private IListIterator<T>
50 {
51  public:
52  /***********************************************************************/
55  /***********************************************************************/
56  inline virtual void MQUALIFIER reset() const
57  {
58  if (this->m_pInterface != NULL)
59  {
60  this->m_pInterface->reset();
61  }
62  }
63 
64  /***********************************************************************/
67  /***********************************************************************/
68  inline virtual const T& MQUALIFIER getNextItemConst() const
69  {
70  assert(this->m_pInterface != NULL);
71  return this->m_pInterface->getNextItemConst();
72  }
73 
74  /***********************************************************************/
77  /***********************************************************************/
78  inline virtual bool MQUALIFIER hasNextItem() const
79  {
80  bool bRetval = false;
81  if (this->m_pInterface != NULL)
82  {
83  bRetval = this->m_pInterface->hasNextItem();
84  }
85  return bRetval;
86  }
87 
88  protected:
89  /***********************************************************************/
92  /***********************************************************************/
95  {}
96 
97  /***********************************************************************/
103  /***********************************************************************/
104  inline TAbstractIterator(const IListIterator<T>* pIt, bool bAllocPointer = false)
105  : TAutoPtrBase<IListIterator<T> >(pIt, bAllocPointer)
106  {}
107 
108  /***********************************************************************/
114  /***********************************************************************/
115  inline TAbstractIterator(IListIterator<T>* pIt, bool bAllocPointer = false)
116  : TAutoPtrBase<IListIterator<T> >(pIt, bAllocPointer)
117  {}
118 
119  /***********************************************************************/
122  /***********************************************************************/
123  inline virtual T& MQUALIFIER getNextItem() const = 0;
124 
125  private:
126  /***********************************************************************/
129  /***********************************************************************/
130  inline virtual Retval MQUALIFIER askForInterface(const InterfaceID& /*rInterfaceID*/, IZUnknown*& /*rpIface*/)
131  {
132  return RET_METHOD_NOT_IMPL;
133  }
134 
135  /***********************************************************************/
138  /***********************************************************************/
139  inline virtual void MQUALIFIER addRef() const {}
140 
141  /***********************************************************************/
144  /***********************************************************************/
145  inline virtual void MQUALIFIER release() const
146  {}
147 
151  TAbstractIterator<T>& operator=(const TAbstractIterator<T>& rIt);
152 };
153 
154 //############################################################################
155 // LIST ITERATORS
156 /****************************************************************************/
159 /****************************************************************************/
160 template <class T> class TIterator : public TAbstractIterator<T>
161 {
162  public:
163  /***********************************************************************/
166  /***********************************************************************/
167  inline TIterator()
168  : TAbstractIterator<T>()
169  {}
170 
171  /***********************************************************************/
177  /***********************************************************************/
178  inline TIterator(IListIterator<T>* pIt, bool bAllocPointer = false)
179  : TAbstractIterator<T>(pIt, bAllocPointer)
180  {}
181 
182  /***********************************************************************/
185  /***********************************************************************/
186  inline TIterator(const TIterator<T>& rIt)
187  : TAbstractIterator<T>(rIt.m_pInterface, true)
188  {}
189 
190  /***********************************************************************/
194  /***********************************************************************/
195  inline TIterator<T>& operator=(const TIterator<T>& rIt)
196  {
197  this->assign(rIt.m_pInterface);
198  return *this;
199  }
200 
201  /***********************************************************************/
205  /***********************************************************************/
207  {
208  this->attach(pIt);
209  return *this;
210  }
211 
212  /***********************************************************************/
216  /***********************************************************************/
217  inline bool operator==(const TIterator<T>& rWrapper) const
218  {
219  return this->equals(rWrapper.m_pInterface);
220  }
221 
222  /***********************************************************************/
226  /***********************************************************************/
227  inline bool operator==(const IListIterator<T>* pIt) const
228  {
229  return this->equals(pIt);
230  }
231 
232  /***********************************************************************/
236  /***********************************************************************/
237  inline bool operator!=(const TIterator<T>& rWrapper) const
238  {
239  return !this->equals(rWrapper.m_pInterface);
240  }
241 
242  /***********************************************************************/
246  /***********************************************************************/
247  inline bool operator!=(const IListIterator<T>* pIt) const
248  {
249  return !this->equals(pIt);
250  }
251 
252  /***********************************************************************/
255  /***********************************************************************/
256  inline virtual T& MQUALIFIER getNextItem() const
257  {
258  assert(this->m_pInterface != NULL);
259  return this->m_pInterface->getNextItem();
260  }
261 
262  private:
263 };
264 
265 /****************************************************************************/
268 /****************************************************************************/
269 template <class T> class TConstIterator : public TAbstractIterator<T>
270 {
271  public:
272  /***********************************************************************/
275  /***********************************************************************/
276  inline TConstIterator()
277  : TAbstractIterator<T>()
278  {}
279 
280  /***********************************************************************/
286  /***********************************************************************/
287  inline TConstIterator(const IListIterator<T>* pIt, bool bAllocPointer = false)
288  : TAbstractIterator<T>(pIt, bAllocPointer)
289  {}
290 
291  /***********************************************************************/
294  /***********************************************************************/
296  : TAbstractIterator<T>(rIt.m_pInterface, true)
297  {}
298 
299  /***********************************************************************/
303  /***********************************************************************/
305  {
306  this->assign(rIt.m_pInterface);
307  return *this;
308  }
309 
310  /***********************************************************************/
314  /***********************************************************************/
316  {
317  this->attach(pIt);
318  return *this;
319  }
320 
321  /***********************************************************************/
325  /***********************************************************************/
326  inline bool operator==(const TConstIterator<T>& rWrapper) const
327  {
328  return this->equals(rWrapper.m_pInterface);
329  }
330 
331  /***********************************************************************/
335  /***********************************************************************/
336  inline bool operator==(const IListIterator<T>* pIt) const
337  {
338  return this->equals(pIt);
339  }
340 
341  /***********************************************************************/
345  /***********************************************************************/
346  inline bool operator!=(const TConstIterator<T>& rWrapper) const
347  {
348  return !this->equals(rWrapper.m_pInterface);
349  }
350 
351  /***********************************************************************/
355  /***********************************************************************/
356  inline bool operator!=(const IListIterator<T>* pIt) const
357  {
358  return !this->equals(pIt);
359  }
360 
361  private:
362  /***********************************************************************/
365  /***********************************************************************/
366  inline virtual T& MQUALIFIER getNextItem() const
367  {
368  assert(this->m_pInterface != NULL);
369  return this->m_pInterface->getNextItem();
370  }
371 };
372 
373 //############################################################################
374 // MAP ITERATORS
375 /****************************************************************************/
378 /****************************************************************************/
379 template <class TKeyType, class T> class TAbstractMapIterator
380  : public TAutoPtrBase<IMapIterator<TKeyType, T> >,
381  private IMapIterator<TKeyType, T>
382 {
383  public:
384  /***********************************************************************/
387  /***********************************************************************/
388  inline virtual void MQUALIFIER reset() const
389  {
390  if (this->m_pInterface != NULL)
391  {
392  this->m_pInterface->reset();
393  }
394  }
395 
396  /***********************************************************************/
399  /***********************************************************************/
400  inline virtual const T& MQUALIFIER getNextItemConst() const
401  {
402  assert(this->m_pInterface != NULL);
403  return this->m_pInterface->getNextItemConst();
404  }
405 
406  /***********************************************************************/
409  /***********************************************************************/
410  inline virtual bool MQUALIFIER hasNextItem() const
411  {
412  bool bRetval = false;
413  if (this->m_pInterface != NULL)
414  {
415  bRetval = this->m_pInterface->hasNextItem();
416  }
417  return bRetval;
418  }
419 
420  /*************************************************************************/
423  /*************************************************************************/
424  inline virtual Retval MQUALIFIER getNextKeyConst(TKeyType& rKey) const
425  {
426  assert(this->m_pInterface != NULL);
427  return this->m_pInterface->getNextKeyConst(rKey);
428  }
429 
430  /*************************************************************************/
433  /*************************************************************************/
434  inline virtual const T& MQUALIFIER getNextItemWithKeyConst(TKeyType& rKey) const
435  {
436  assert(this->m_pInterface != NULL);
437  return this->m_pInterface->getNextItemWithKeyConst(rKey);
438  }
439 
440  protected:
441  /***********************************************************************/
444  /***********************************************************************/
446  : TAutoPtrBase<IMapIterator<TKeyType, T> >()
447  {}
448 
449  /***********************************************************************/
455  /***********************************************************************/
456  inline TAbstractMapIterator(const IMapIterator<TKeyType, T>* pIt, bool bAllocPointer = false)
457  : TAutoPtrBase<IMapIterator<TKeyType, T> >(pIt, bAllocPointer)
458  {}
459 
460  /***********************************************************************/
466  /***********************************************************************/
467  inline TAbstractMapIterator(IMapIterator<TKeyType, T>* pIt, bool bAllocPointer = false)
468  : TAutoPtrBase<IMapIterator<TKeyType, T> >(pIt, bAllocPointer)
469  {}
470 
471  virtual T& MQUALIFIER getNextItem() const = 0;
472  virtual Retval MQUALIFIER getNextKey(TKeyType& rKey) =0;
473  virtual T& MQUALIFIER getNextItemWithKey(TKeyType& rKey) const = 0;
474 
475 
476  private:
477  /***********************************************************************/
480  /***********************************************************************/
481  inline virtual Retval MQUALIFIER askForInterface(const InterfaceID& /*rInterfaceID*/, IZUnknown*& /*rpIface*/)
482  {
483  return RET_METHOD_NOT_IMPL;
484  }
485 
486  /***********************************************************************/
489  /***********************************************************************/
490  inline virtual void MQUALIFIER addRef() const {}
491 
492  /***********************************************************************/
495  /***********************************************************************/
496  inline virtual void MQUALIFIER release() const
497  {}
498 
503 };
504 
505 
506 /****************************************************************************/
509 /****************************************************************************/
510 template <class TKeyType, class T> class TMapIterator : public TAbstractMapIterator<TKeyType, T>
511 {
512  public:
513  /***********************************************************************/
516  /***********************************************************************/
517  inline TMapIterator()
518  : TAbstractMapIterator<TKeyType, T>()
519  {}
520 
521  /***********************************************************************/
527  /***********************************************************************/
528  inline TMapIterator(IMapIterator<TKeyType, T>* pIt, bool bAllocPointer = false)
529  : TAbstractMapIterator<TKeyType, T>(pIt, bAllocPointer)
530  {}
531 
532  /***********************************************************************/
535  /***********************************************************************/
537  : TAbstractMapIterator<TKeyType, T>(rIt.m_pInterface, true)
538  {}
539 
540  /***********************************************************************/
544  /***********************************************************************/
546  {
547  this->assign(rIt.m_pInterface);
548  return *this;
549  }
550 
551  /***********************************************************************/
555  /***********************************************************************/
557  {
558  this->attach(pIt);
559  return *this;
560  }
561 
562  /***********************************************************************/
566  /***********************************************************************/
567  inline bool operator==(const TMapIterator<TKeyType, T>& rWrapper) const
568  {
569  return this->equals(rWrapper.m_pInterface);
570  }
571 
572  /***********************************************************************/
576  /***********************************************************************/
577  inline bool operator==(const IMapIterator<TKeyType, T>* pIt) const
578  {
579  return this->equals(pIt);
580  }
581 
582  /***********************************************************************/
586  /***********************************************************************/
587  inline bool operator!=(const TMapIterator<TKeyType, T>& rWrapper) const
588  {
589  return !this->equals(rWrapper.m_pInterface);
590  }
591 
592  /***********************************************************************/
596  /***********************************************************************/
597  inline bool operator!=(const IMapIterator<TKeyType, T>* pIt) const
598  {
599  return !this->equals(pIt);
600  }
601 
602  /***********************************************************************/
605  /***********************************************************************/
606  inline virtual T& MQUALIFIER getNextItem() const
607  {
608  assert(this->m_pInterface != NULL);
609  return this->m_pInterface->getNextItem();
610  }
611 
612  /***********************************************************************/
615  /***********************************************************************/
616  inline virtual Retval MQUALIFIER getNextKey(TKeyType& rKey)
617  {
618  assert(this->m_pInterface != NULL);
619  return this->m_pInterface->getNextKey(rKey);
620  }
621 
622  /***********************************************************************/
625  /***********************************************************************/
626  inline virtual T& MQUALIFIER getNextItemWithKey(TKeyType& rKey) const
627  {
628  assert(this->m_pInterface != NULL);
629  return this->m_pInterface->getNextItemWithKey(rKey);
630  }
631 
632  private:
633 };
634 
635 
636 /****************************************************************************/
639 /****************************************************************************/
640 template <class TKeyType, class T> class TConstMapIterator : public TAbstractMapIterator<TKeyType, T>
641 {
642  public:
643  /***********************************************************************/
646  /***********************************************************************/
648  : TAbstractMapIterator<TKeyType, T>()
649  {}
650 
651  /***********************************************************************/
657  /***********************************************************************/
658  inline TConstMapIterator(const IMapIterator<TKeyType, T>* pIt, bool bAllocPointer = false)
659  : TAbstractMapIterator<TKeyType, T>(pIt, bAllocPointer)
660  {}
661 
662  /***********************************************************************/
665  /***********************************************************************/
667  : TAbstractMapIterator<TKeyType, T>(rIt.m_pInterface, true)
668  {}
669 
670  /***********************************************************************/
674  /***********************************************************************/
676  {
677  this->assign(rIt.m_pInterface);
678  return *this;
679  }
680 
681  /***********************************************************************/
685  /***********************************************************************/
687  {
688  this->attach(pIt);
689  return *this;
690  }
691 
692  /***********************************************************************/
696  /***********************************************************************/
697  inline bool operator==(const TConstMapIterator<TKeyType, T>& rWrapper) const
698  {
699  return this->equals(rWrapper.m_pInterface);
700  }
701 
702  /***********************************************************************/
706  /***********************************************************************/
707  inline bool operator==(const IMapIterator<TKeyType, T>* pIt) const
708  {
709  return this->equals(pIt);
710  }
711 
712  /***********************************************************************/
716  /***********************************************************************/
717  inline bool operator!=(const TConstMapIterator<TKeyType, T>& rWrapper) const
718  {
719  return !this->equals(rWrapper.m_pInterface);
720  }
721 
722  /***********************************************************************/
726  /***********************************************************************/
727  inline bool operator!=(const IMapIterator<TKeyType, T>* pIt) const
728  {
729  return !this->equals(pIt);
730  }
731 
732  private:
733  /***********************************************************************/
736  /***********************************************************************/
737  inline virtual T& MQUALIFIER getNextItem() const
738  {
739  assert(this->m_pInterface != NULL);
740  return this->m_pInterface->getNextItem();
741  }
742 
743  /***********************************************************************/
746  /***********************************************************************/
747  inline virtual Retval MQUALIFIER getNextKey(TKeyType& rKey)
748  {
749  assert(this->m_pInterface != NULL);
750  return this->m_pInterface->getNextKey(rKey);
751  }
752 
753  /***********************************************************************/
756  /***********************************************************************/
757  inline virtual T& MQUALIFIER getNextItemWithKey(TKeyType& rKey) const
758  {
759  assert(this->m_pInterface != NULL);
760  return this->m_pInterface->getNextItemWithKey(rKey);
761  }
762 };
763 
765 
766 #endif
bool operator!=(const TConstIterator< T > &rWrapper) const
Definition: Iterators.hpp:346
#define END_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:96
bool operator!=(const TMapIterator< TKeyType, T > &rWrapper) const
Definition: Iterators.hpp:587
TAbstractMapIterator(IMapIterator< TKeyType, T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:467
Definition: Iterators.hpp:269
TConstIterator(const TConstIterator< T > &rIt)
Definition: Iterators.hpp:295
#define RET_METHOD_NOT_IMPL
Definition: RetvalDefines.hpp:43
TMapIterator< TKeyType, T > & operator=(const TMapIterator< TKeyType, T > &rIt)
Definition: Iterators.hpp:545
TIterator< T > & operator=(const TIterator< T > &rIt)
Definition: Iterators.hpp:195
Definition: IListIterator.hpp:44
virtual const T &MQUALIFIER getNextItemConst() const
Definition: Iterators.hpp:68
virtual Retval MQUALIFIER getNextKey(TKeyType &rKey)
Definition: Iterators.hpp:616
virtual const T &MQUALIFIER getNextItemWithKeyConst(TKeyType &rKey) const
Definition: Iterators.hpp:434
virtual Retval MQUALIFIER getNextKeyConst(TKeyType &rKey) const
Definition: Iterators.hpp:424
TAbstractMapIterator(const IMapIterator< TKeyType, T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:456
Definition: IMapIterator.hpp:44
Definition: PlatformDefines.hpp:327
Definition: Iterators.hpp:640
Definition: Iterators.hpp:379
bool operator!=(const IMapIterator< TKeyType, T > *pIt) const
Definition: Iterators.hpp:727
virtual bool MQUALIFIER hasNextItem() const
Definition: Iterators.hpp:410
TConstMapIterator()
Definition: Iterators.hpp:647
bool operator==(const TMapIterator< TKeyType, T > &rWrapper) const
Definition: Iterators.hpp:567
TAbstractIterator()
Definition: Iterators.hpp:93
TAbstractIterator(IListIterator< T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:115
TAbstractMapIterator()
Definition: Iterators.hpp:445
virtual T &MQUALIFIER getNextItemWithKey(TKeyType &rKey) const
Definition: Iterators.hpp:626
#define MQUALIFIER
Definition: LinuxPlatform.hpp:64
virtual const T &MQUALIFIER getNextItemConst() const
Definition: Iterators.hpp:400
TConstMapIterator< TKeyType, T > & operator=(const IMapIterator< TKeyType, T > *pIt)
Definition: Iterators.hpp:686
TIterator()
Definition: Iterators.hpp:167
bool operator==(const TConstMapIterator< TKeyType, T > &rWrapper) const
Definition: Iterators.hpp:697
#define BEGIN_NAMESPACE_Zeus
Definition: PlatformDefines.hpp:95
bool operator!=(const IListIterator< T > *pIt) const
Definition: Iterators.hpp:356
TMapIterator()
Definition: Iterators.hpp:517
TConstIterator< T > & operator=(const TConstIterator< T > &rIt)
Definition: Iterators.hpp:304
TIterator(const TIterator< T > &rIt)
Definition: Iterators.hpp:186
TConstMapIterator< TKeyType, T > & operator=(const TConstMapIterator< TKeyType, T > &rIt)
Definition: Iterators.hpp:675
bool operator!=(const TConstMapIterator< TKeyType, T > &rWrapper) const
Definition: Iterators.hpp:717
bool operator==(const TConstIterator< T > &rWrapper) const
Definition: Iterators.hpp:326
TConstIterator(const IListIterator< T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:287
Definition: AutoPtr.hpp:44
virtual void MQUALIFIER reset() const
Definition: Iterators.hpp:388
bool operator==(const IMapIterator< TKeyType, T > *pIt) const
Definition: Iterators.hpp:577
TConstMapIterator(const TConstMapIterator< TKeyType, T > &rIt)
Definition: Iterators.hpp:666
bool operator!=(const IListIterator< T > *pIt) const
Definition: Iterators.hpp:247
virtual bool MQUALIFIER hasNextItem() const
Definition: Iterators.hpp:78
virtual void MQUALIFIER reset() const
Definition: Iterators.hpp:56
bool operator!=(const IMapIterator< TKeyType, T > *pIt) const
Definition: Iterators.hpp:597
bool operator==(const IListIterator< T > *pIt) const
Definition: Iterators.hpp:336
Definition: Iterators.hpp:160
TIterator(IListIterator< T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:178
TMapIterator< TKeyType, T > & operator=(IMapIterator< TKeyType, T > *pIt)
Definition: Iterators.hpp:556
bool operator!=(const TIterator< T > &rWrapper) const
Definition: Iterators.hpp:237
TIterator< T > & operator=(IListIterator< T > *pIt)
Definition: Iterators.hpp:206
TAbstractIterator(const IListIterator< T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:104
TMapIterator(IMapIterator< TKeyType, T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:528
bool operator==(const TIterator< T > &rWrapper) const
Definition: Iterators.hpp:217
TConstMapIterator(const IMapIterator< TKeyType, T > *pIt, bool bAllocPointer=false)
Definition: Iterators.hpp:658
TConstIterator()
Definition: Iterators.hpp:276
Definition: Iterators.hpp:49
TMapIterator(const TMapIterator< TKeyType, T > &rIt)
Definition: Iterators.hpp:536
Definition: Iterators.hpp:510
virtual T &MQUALIFIER getNextItem() const
Definition: Iterators.hpp:606
IListIterator< T > * m_pInterface
Definition: AutoPtr.hpp:256
Definition: IZUnknown.hpp:65
bool operator==(const IListIterator< T > *pIt) const
Definition: Iterators.hpp:227
bool operator==(const IMapIterator< TKeyType, T > *pIt) const
Definition: Iterators.hpp:707
TConstIterator< T > & operator=(const IListIterator< T > *pIt)
Definition: Iterators.hpp:315
virtual T &MQUALIFIER getNextItem() const
Definition: Iterators.hpp:256


Written by Benjamin Hadorn http://www.xatlantis.ch.
Last change made on Tue Sep 13 2016 22:30:41