#include "CivInpSubject.h"
#include "CivInpObserver.h"

CivInpSubject::~CivInpSubject()
{

}

void CivInpSubject::attach(CivInpObserver* obsever)
{
	mObservers.push_back(obsever);
}

void CivInpSubject::detach(CivInpObserver* obsever)
{
	std::list<CivInpObserver*>::iterator it = std::find(mObservers.begin(), mObservers.end(), obsever);
	if (it != mObservers.end())
	{
		std::swap(*it, mObservers.back());
		mObservers.pop_back();
	}
}

void CivInpSubject::notify()
{
	std::list<CivInpObserver*>::const_iterator const_iter = mObservers.cbegin();
	for (; const_iter != mObservers.cend(); const_iter++)
	{
		(*const_iter)->update(this);
	}
}

void CivInpSubject::setState(const State& st)
{
	mState = st;
}

State CivInpSubject::state()
{
	return mState;
}