#include "StdAfx.h" #include "GlobalFunc.h" #include "T2FInfoPtIterator.h" #include "T2FloorInfo.h" #include "T2MoverArrayList.h" #include "T2RequestArrayList.h" #include "T2TenantArrayList.h" #include "T2UnitInfo.h" T2FInfoPtIterator::T2FInfoPtIterator(const T2FloorInfo& inFloorInfo, POINT inPt) : mFloorInfo(inFloorInfo) , mLeftBound(mFloorInfo.mBuildArea.left) , mRightBound(mFloorInfo.mBuildArea.right - 1) { if (PtInRect(&mFloorInfo.mBuildArea, inPt)) { mCurrH = inPt.x; mCurrUnitInfo = mFloorInfo.GetUnitInfo(inPt.y, mCurrH); mLastIDSeen = 0; } else { mCurrH = -2; } } /*virtual*/ T2FInfoPtIterator::~T2FInfoPtIterator() { } BOOL T2FInfoPtIterator::CurrentH(int& outH) const { BOOL result = true; if (IsValidPosition()) outH = mCurrH; else result = false; return result; } BOOL T2FInfoPtIterator::CalcRightUnitInfo() { BOOL result = true; if (mCurrH != -2) { if (mCurrH != -1) { if (mCurrH < mRightBound) { mCurrH++; mCurrUnitInfo++; } else { mCurrH = -2; result = false; } } else { mCurrH = mLeftBound; } } else { result = false; } return result; } BOOL T2FInfoPtIterator::CalcLeftUnitInfo() { BOOL result = true; if (mCurrH != -2) { if (mCurrH != -1) { if (mCurrH > mLeftBound) { mCurrH--; mCurrUnitInfo--; } else { result = false; } } else { mCurrH = mRightBound; } } else { result = false; } return result; } BOOL T2FInfoPtIterator::Current(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (IsValidPosition()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::Right(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (CalcRightUnitInfo()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::Left(T2UnitInfo*& outUnitInfo) { BOOL result = true; if (CalcLeftUnitInfo()) outUnitInfo = mCurrUnitInfo; else result = false; return result; } BOOL T2FInfoPtIterator::RightTenant(T2Tenant*& outTenant) { BOOL found; T2UnitInfo *unitInfo; for (found = Right(unitInfo); found; found = Right(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return found; } BOOL T2FInfoPtIterator::LeftTenant(T2Tenant*& outTenant) { BOOL found; T2UnitInfo *unitInfo; for (found = Left(unitInfo); found; found = Left(unitInfo)) { unsigned int tenantID = unitInfo->GetTenantID(); if (tenantID != mLastIDSeen) { mLastIDSeen = tenantID; if (tenantID != 0) { outTenant = mFloorInfo.mTenantArrayList->GetTenantByID(tenantID); break; } } } return found; }