#include "T2CustomerTableIterator.h" #include "T2TenantMemberDef.h" #include "T2TenantMemberTableDef.h" #include "UT2Utils.h" T2CustomerTableIterator::T2CustomerTableIterator(const T2TenantMemberTableDef* inTable) { mTable = inTable; if (mTable) { mLastNum = mTable->GetNumOfElem(); mBound = UT2Utils::Randomize(mLastNum); mNextIndex = -1; } else { mNextIndex = -2; } } T2CustomerTableIterator::~T2CustomerTableIterator() { } BOOL T2CustomerTableIterator::Next(T2TenantMemberDef*& outMemberDef, unsigned int& outRate) { BOOL result = false; BOOL done = false; while (!done) { CalcNextIndex(); if (mNextIndex != -2) { T2TenantMemberDef *theMember = mTable->GetElem(mNextIndex); if (theMember) { unsigned int rate = UT2Utils::Float2Int(theMember->GetRate()); if (rate > 0) { outMemberDef = theMember; outRate = rate; done = true; result = true; } } else { done = true; } } else { done = true; } } return result; } void T2CustomerTableIterator::CalcNextIndex() { if (mNextIndex == -1) { mNextIndex = mBound; } else if (mNextIndex != -2) { mNextIndex++; if (mNextIndex >= mLastNum) mNextIndex = 0; if (mNextIndex == mBound) mNextIndex = -2; } }