gatelib  2.1
g_cont_it_base.h
1 #pragma once
2 
3 #include "g_cont_it_unspec.h"
4 
5 namespace g
6 {
7 namespace cont
8 {
9 template<class T, class REF, class REF_C , class IT , class IT_C > class base_cont;
10 template<class T> class cont_with_positioner;
11 
12 template < class T , class REF , class REF_C > class it_base : public ItUnspec
13 {
14 private:
15  it_base(const it_base&) : mRecipientP ( NULL ) , mIndex ( G_CONT_INDEX_NOT_VALID ) {}//copy of iterator prohibited
16 
17 public:
18  typedef cont_with_positioner<REF> RecipientBase_t;
19  friend class cont_with_positioner<REF>;
20  template<class,class,class,class,class> friend class base_cont;
21 
22  typedef REF Ref_t;
23  typedef REF_C RefConst_t;
24 
25  virtual ~it_base() {}
26 
27  virtual bool isIn ( ) const { return ( mRecipientP != NULL && mRecipientP->mPositionerP->isIn(mIndex) ); }
28  virtual bool isMine ( const RecipientBase_t& aRecipient ) const { return ( &aRecipient == mRecipientP ); }
29  virtual void toBegin ( ) { mIndex = mRecipientP->mPositionerP->first ( ); }
30  virtual void toEnd ( ) { mIndex = mRecipientP->mPositionerP->last ( ); }
31  virtual void forward ( GUint32_t inc = 1 ) { mRecipientP->mPositionerP->forward ( mIndex , inc ); }
32  virtual void backward ( GUint32_t dec = 1 ) { mRecipientP->mPositionerP->backward ( mIndex , dec ); }
33  //if inc > 0 forward otherwise backward
34  virtual void moveOf ( int inc ) { (inc>0)?forward((GUint32_t)inc):backward((GUint32_t)-inc); }
35  virtual bool isNull ( ) const { return ( mIndex == G_CONT_INDEX_NOT_VALID && mRecipientP == NULL ); }
36 
37  bool operator == ( const it_base& aOther ) const { return aOther.mIndex == mIndex; }
38  bool operator != ( const it_base& aOther ) const { return !operator==(aOther); }
39 
40 protected:
41  it_base ( ) : mRecipientP ( NULL ) , mIndex ( G_CONT_INDEX_NOT_VALID ) {}
42 
43  virtual void mInit ( const RecipientBase_t& aRec , IterFrom_t aIterFrom );
44  virtual void mCopy ( const it_base& );
45 
46  const RecipientBase_t* mRecipientP;
47  int mIndex;
48 };
49 
50 template < class T , class REF , class REF_C > void it_base<T,REF,REF_C>::mInit ( const RecipientBase_t& aRec , IterFrom_t aIterFrom )
51 {
52  mRecipientP = &aRec;
53 
54  switch ( aIterFrom )
55  {
56  case head: mIndex = aRec.mPositionerP->first ( );break;
57  case tail: mIndex = aRec.mPositionerP->last ( );break;
58  }
59 
60  G_VERBOSE_MSG_L3("Init iterator recipient " << std::hex << (int)mRecipientP << std::dec );
61 }
62 
63 template < class T , class REF , class REF_C > void it_base <T,REF,REF_C>::mCopy ( const it_base<T,REF,REF_C>& aIt )
64 {
65  mRecipientP = aIt.mRecipientP;
66  mIndex = aIt.mIndex;
67 }
68 
69 }//namespace cont
70 }//namespace g
71 
Definition: g.mthread.ThreadSimpleEvent.h:5