using namespace std;
#include "hmatrixcatiter.h"
#include "hdebug.h"
#include <iostream>
#include <iomanip>
ClassImp(HMatrixCatIter)
HMatrixCatIter::HMatrixCatIter(void) {
fCategory=NULL;
fSizes=NULL;
fCursor=0;
fDir=kIterForward;
}
HMatrixCatIter::HMatrixCatIter(HMatrixCategory *cat,Bool_t dir) {
fCategory=cat;
fSizes=cat->fIndexTable->getDimensions();
fCursor=0;
fDir=dir;
}
HMatrixCatIter::~HMatrixCatIter(void) {
}
TCollection *HMatrixCatIter::GetCollection(void) const {
return fCategory->fData;
}
TObject *HMatrixCatIter::Next(void) {
TObject *r=NULL;
Int_t i;
if (fDir==kIterForward) {
if (fCursor < fEnd ) {
r=fCategory->fData->At(fCategory->fIndexTable->getIndex(fCursor));
fAntCursor=fCursor;
do {
fCursor++;
} while ( (fCursor<fEnd) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0);
} else r=NULL;
} else {
if (fCursor > fBegin ) {
r=fCategory->fData->At(fCategory->fIndexTable->getIndex(fCursor));
fAntCursor=fCursor;
do {
fCursor--;
} while ( (fCursor>fBegin) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0);
} else r=NULL;
}
return r;
}
void HMatrixCatIter::Reset(void) {
#if DEBUG_LEVEL>2
gDebuger->enterFunc("HMatrixCatIter::Reset");
#endif
Int_t i=0;
fSizes=fCategory->fIndexTable->getDimensions();
if (fDir==kIterForward) {
fCursor=0;
fBegin=0;
fEnd=fCategory->fIndexTable->getEntries();
fCurrentLoc.setNIndex(fSizes->fN);
for (i=0;i<fSizes->fN;i++) fCurrentLoc[i]=0;
while ( (fCursor<fEnd) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0) {
fCursor++;
}
fBegin=fAntCursor=fCursor;
} else {
Int_t i;
fCursor=fCategory->fIndexTable->getEntries()-1;
fBegin=fCursor;
fEnd=-1;
fCurrentLoc.setNIndex(fSizes->GetSize());
for (i=0;i<fSizes->GetSize();i++) {
fCurrentLoc.setIndex(i,fSizes->At(i)-1);
}
while ( (fCursor>fBegin) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0) {
fCursor--;
}
fBegin=fAntCursor=fCursor;
}
#if DEBUG_LEVEL>2
gDebuger->leaveFunc("HMatrixCatIter::Reset");
#endif
}
Bool_t HMatrixCatIter::gotoLocation(HLocation &loc) {
#if DEBUG_LEVEL>2
gDebuger->enterFunc("HMatrixCatIter::gotoLocation");
#endif
Int_t i=0;
if (loc.getNIndex()==0) {
Reset();
} else {
fCurrentLoc.readIndexes(loc);
fCursor=fCurrentLoc.getLinearIndex(fSizes);
fBegin=fCursor;
++loc;
fEnd=loc.getLinearIndex(fSizes);
if (fEnd>fCategory->fIndexTable->getEntries()) {
fEnd=fCategory->fIndexTable->getEntries();
}
--loc;
if (fCursor>=fCategory->fIndexTable->getEntries()) return kFALSE;
if (fDir==kIterForward) {
fCursor=fBegin;
while ( (fCursor<fEnd) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0) {
fCursor++;
}
fBegin=fAntCursor=fCursor;
} else {
fCursor=fEnd;
while ( (fCursor>fBegin) &&
(i=fCategory->fIndexTable->getIndex(fCursor))<0) {
fCursor--;
}
fEnd=fAntCursor=fCursor;
}
}
return kTRUE;
}
HLocation &HMatrixCatIter::getLocation(void) {
Int_t prod=1;
Int_t i=0;
for (i=fCurrentLoc.getNIndex()-1;i>-1;i--) {
fCurrentLoc[i]=(fAntCursor/prod) % fSizes->fArray[i];
prod*=fSizes->fArray[i];
}
return fCurrentLoc;
}
Last change: Sat May 22 12:59:27 2010
Last generated: 2010-05-22 12:59
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.