#include "StdAfx.h" #include "T2Archive.h" #include "T2ReturnStack.h" T2ReturnStack::T2ReturnStack() { Init(); } T2ReturnStack::~T2ReturnStack() { } void T2ReturnStack::Init() { for (int i = 0; i < 3; i++) { mEntries[i].tenant = 0; mEntries[i].time = 0; } mCount = 0; } BOOL T2ReturnStack::Current(unsigned int &tenant, unsigned int &time) { if (mCount > 0) { tenant = mEntries[0].tenant; time = mEntries[0].time; return true; } return false; } BOOL T2ReturnStack::Push(unsigned int tenant, unsigned int time) { if (mCount < 3) { for (int i = mCount - 1; i >= 0; i--) { mEntries[i + 1] = mEntries[i]; } mCount++; mEntries[0].tenant = tenant; mEntries[0].time = time; return true; } else { return false; } } BOOL T2ReturnStack::Pop(unsigned int &tenant, unsigned int &time) { if (mCount > 0) { tenant = mEntries[0].tenant; time = mEntries[0].time; for (int i = 1; i < mCount; i++) { mEntries[i - 1] = mEntries[i]; } mCount--; return true; } else { return false; } } BOOL T2ReturnStack::IsSetTime() const { BOOL result = false; if (mCount > 0 && mEntries[0].time != 0) result = true; return result; } unsigned int T2ReturnStack::GetTenant() const { unsigned int result = 0; if (mCount > 0) result = mEntries[0].tenant; return result; } unsigned int T2ReturnStack::GetTime() const { unsigned int result = 0; if (mCount > 0) result = mEntries[0].time; return result; } void T2ReturnStack::SetTime(unsigned int time) { if (mCount > 0) mEntries[0].time = time; } void T2ReturnStack::DayChanged() { for (int i = 0; i < mCount; i++) { if (mEntries[i].time >= 1440) { mEntries[i].time -= 1440; } else if (mEntries[i].time > 1438) { mEntries[i].time = 0; } } } BOOL T2ReturnStack::Remove(unsigned int tenant) { BOOL result = false; for (int i = 0; i < mCount; i++) { if (!result) { if (mEntries[i].tenant == tenant) result = true; } else { mEntries[i - 1] = mEntries[i]; } } if (result) mCount--; return result; } void T2ReturnStack::Peek(int index, unsigned int &tenant, unsigned int &time) { tenant = mEntries[index].tenant; time = mEntries[index].time; } void T2ReturnStack::Poke(int index, unsigned int tenant, unsigned int time) { mEntries[index].tenant = tenant; mEntries[index].time = time; } void T2ReturnStack::Read(T2Archive &stream, T2TowerDoc *towerDoc) { stream >> mCount; for (int i = 0; i < mCount; i++) { unsigned short v; stream >> v; mEntries[i].tenant = v; stream >> v; mEntries[i].time = v; } } void T2ReturnStack::Write(T2Archive &stream) { stream << mCount; for (int i = 0; i < mCount; i++) { unsigned short v; v = mEntries[i].tenant; stream << v; v = mEntries[i].time; stream << v; } }