summaryrefslogtreecommitdiff
path: root/src/T2DLL/T2CustomerTableIterator.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/T2DLL/T2CustomerTableIterator.cpp')
-rw-r--r--src/T2DLL/T2CustomerTableIterator.cpp49
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;
+ }
}