]> git.uio.no Git - u/mrichter/AliRoot.git/commitdiff
Added inner struct VoidCPlex::iterator; increase constness.
authormtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 8 Dec 2006 18:17:33 +0000 (18:17 +0000)
committermtadel <mtadel@f7af4fe6-9843-0410-8265-dc069ae4e863>
Fri, 8 Dec 2006 18:17:33 +0000 (18:17 +0000)
EVE/Reve/LinkDef.h
EVE/Reve/Plex.h

index e8ff02a2c393abae61063826ff42a8f873b4c359..369003b31c0836f6abf109bae54005d94ce78ed6 100644 (file)
@@ -51,6 +51,7 @@
 
 // Plexes
 #pragma link C++ class Reve::VoidCPlex+;
+#pragma link C++ class Reve::VoidCPlex::iterator-;
 
 // EventBase, VSDEvent, VSD
 #pragma link C++ class Reve::EventBase+;
index 9c87a76197abb1eead2a12a43840d9cc747eaaf6..40a025f789f03e40aa74a2f9298973061b6b1f41 100644 (file)
@@ -49,13 +49,38 @@ public:
   Int_t    VecSize()  const { return fVecSize; }
   Int_t    Capacity() const { return fCapacity; }
 
-  Char_t* Atom(Int_t idx)   { return fChunks[idx/fN]->fArray + idx%fN*fS; }
-  Char_t* Chunk(Int_t chk)  { return fChunks[chk]->fArray; }
-  Int_t   NAtoms(Int_t chk) { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
+  Char_t* Atom(Int_t idx)   const { return fChunks[idx/fN]->fArray + idx%fN*fS; }
+  Char_t* Chunk(Int_t chk)  const { return fChunks[chk]->fArray; }
+  Int_t   NAtoms(Int_t chk) const { return (chk < fVecSize-1) ? fN : (fSize-1)%fN + 1; }
 
   Char_t* NewAtom();
   Char_t* NewChunk();
 
+
+  // Iterators
+
+  struct iterator
+  {
+    VoidCPlex *fPlex;
+    Char_t    *fCurrent;
+    Int_t      fAtomIndex;
+    Int_t      fNextChunk;
+    Int_t      fAtomsToGo;
+
+    iterator(VoidCPlex* p) :
+      fPlex(p),  fCurrent(0), fAtomIndex(-1), fNextChunk(0), fAtomsToGo(0) {}
+    iterator(VoidCPlex& p) :
+      fPlex(&p), fCurrent(0), fAtomIndex(-1), fNextChunk(0), fAtomsToGo(0) {}
+
+    Bool_t  next();
+    void    reset() { fCurrent = 0; fNextChunk = fAtomsToGo = 0; }
+
+    Char_t* operator()() { return fCurrent; }
+    Char_t* operator*()  { return fCurrent; }
+    Int_t   index()      { return fAtomIndex; }
+  };
+
+
   ClassDef(VoidCPlex, 1)
 };
 
@@ -66,6 +91,24 @@ inline Char_t* VoidCPlex::NewAtom()
   return a;
 }
 
+inline Bool_t VoidCPlex::iterator::next()
+{
+  if (fAtomsToGo <= 0) {
+    if (fNextChunk < fPlex->fVecSize) {
+      fCurrent   = fPlex->Chunk(fNextChunk);
+      fAtomsToGo = fPlex->NAtoms(fNextChunk);
+      ++fNextChunk;
+    } else {
+      return kFALSE;
+    }
+  } else {
+    fCurrent += fPlex->fS;
+  }
+  ++fAtomIndex;
+  --fAtomsToGo;
+  return kTRUE;
+}
+
 
 /**************************************************************************/
 // Some-class CPlex