#pragma once
#include
#include
/*
Size : Unlimited
I/O : LIFO, FIFO
*/
template
class NLStack
{
public :
enum OutType
{
LIFO = 0,
FIFO = 1,
};
private:
NLStack()
{
Clear();
}
public:
NLStack(int out) : m_Out(out)
{
Clear();
}
void Clear()
{
if ( m_Stack.empty() == false )
{
m_Stack.clear();
}
}
int Count()
{
return static_cast( m_Stack.size() ) ;
}
bool IsEmpty()
{
return m_Stack.empty();
}
// store data
void Push( T data )
{
m_Stack.push_back( data );
}
// extract data
bool Pop ( T*data )
{
if ( IsEmpty() )
return false;
switch( m_Out)
{
case FIFO:
//FIFO
memcpy( data, &m_Stack.front(), sizeof(T) );
m_Stack.pop_front();
break;
case LIFO:
//LIFO
memcpy( data, &m_Stack.back(), sizeof(T) );
m_Stack.pop_back();
break;
}
return true;
}
void SetOutType( int out )
{
m_Out = out;
}
private:
std::list m_Stack;
int m_Out;
};