diff options
author | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
---|---|---|
committer | Ash Wolf <ninji@wuffs.org> | 2023-06-28 22:22:32 +0100 |
commit | c0c336500955a23e344651e5412c9d9d441ef4ee (patch) | |
tree | 790769c748db307cf3314f6e896e2f61c68561a2 /src/T2DLL/T2CustomerTableIterator.cpp | |
parent | 37e364b2c6cc7487a1c888d256a73e5337bb7189 (diff) | |
download | t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.tar.gz t2win-c0c336500955a23e344651e5412c9d9d441ef4ee.zip |
first pass of T2DLL
Diffstat (limited to 'src/T2DLL/T2CustomerTableIterator.cpp')
-rw-r--r-- | src/T2DLL/T2CustomerTableIterator.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/T2DLL/T2CustomerTableIterator.cpp b/src/T2DLL/T2CustomerTableIterator.cpp index 4e3fd46..ad7e872 100644 --- a/src/T2DLL/T2CustomerTableIterator.cpp +++ b/src/T2DLL/T2CustomerTableIterator.cpp @@ -1,13 +1,58 @@ #include "T2CustomerTableIterator.h" +#include "T2TenantMemberDef.h" +#include "T2TenantMemberTableDef.h" +#include "UT2Utils.h" -T2CustomerTableIterator::T2CustomerTableIterator(const T2TenantMemberTableDef*) { +T2CustomerTableIterator::T2CustomerTableIterator(const T2TenantMemberTableDef* inTable) { + mTable = inTable; + + if (mTable) { + mLastNum = mTable->GetNumOfElem(); + mBound = UT2Utils::Randomize(mLastNum); + mNextIndex = -1; + } else { + mNextIndex = -2; + } } T2CustomerTableIterator::~T2CustomerTableIterator() { } -int T2CustomerTableIterator::Next(T2TenantMemberDef*&, unsigned int&) { +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; + } } |