namespace dftCommon
{
class StateMachine
{
Value* m_pStates;
unsigned int m_nCount;
public:
StateMachine(unsigned int nStateCount = 16); // Fixed
~StateMachine();
void SetState(unsigned int nIndex, Value NewState);
Value GetState(unsigned int nIndex);
void SaveStates(Value* pStates, unsigned int nCount);
void LoadStates(const Value* pStates, unsigned int nCount);
};
}
dftCommon::StateMachine::StateMachine(unsigned int nStateCount)
{
assert(nStateCount > 1);
m_pStates = new Value[nStateCount];
m_nCount = nStateCount;
memset(&m_pStates, 0, nStateCount);
}
dftCommon::StateMachine::~StateMachine()
{
delete m_pStates;
m_nCount = 0;
}
void dftCommon::StateMachine::SetState(unsigned int nIndex, Value NewState)
{
assert(nIndex < m_nCount);
m_pStates[nIndex] = NewState;
}
dftCommon::Value dftCommon::StateMachine::GetState(unsigned int nIndex)
{
assert(nIndex < m_nCount);
return m_pStates[nIndex];
return 0;
}
void dftCommon::StateMachine::SaveStates(dftCommon::Value* pStates, unsigned int nCount)
{
assert(pStates != 0);
// We only have enough states for an m_nCount, so we'll only fill that many.
if(nCount > m_nCount)
nCount = m_nCount;
for(unsigned int nIndex = 0; nIndex < nCount; ++nIndex)
pStates[nIndex] = m_pStates[nIndex];
}
void dftCommon::StateMachine::LoadStates(const dftCommon::Value* pStates, unsigned int nCount)
{
assert(pStates != 0);
// We only have enough room for m_nCount states, so we'll only get that many.
if(nCount > m_nCount)
nCount = m_nCount;
for(unsigned int nIndex = 0; nIndex < m_nCount; ++nIndex)
m_pStates[nIndex] = pStates[nIndex];
}
enum TEST_STATES { TEST_TITLE = 0 };
dftCommon::StateMachine g_StateMachine;
g_StateMachine.SetState(TEST_TITLE, "StateMachine Test");
I've stepped through it with my debugger, but the constructor code is never called. Did I miss something or is this a bug with MSVC++ 6? It stops on line 19 (the assertion in dftCommon::StateMachine::SetState().)
[Edited by - Programmer16 on June 23, 2005 12:58:00 AM]