You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.0 KiB
C++

#include "StdAfx.h"
#include "Subject.h"
CSubject::CSubject(void)
{
}
CSubject::~CSubject(void)
{
}
//ע<><D7A2><EFBFBD>۲<EFBFBD><DBB2><EFBFBD>
void CSubject::Attach(CObserver *p)
{
m_ObserverVec.push_back(p);
}
//ɾ<><C9BE><EFBFBD>۲<EFBFBD><DBB2><EFBFBD>
void CSubject::Delete(CObserver *p)
{
vector<CObserver*>::iterator iter = m_ObserverVec.begin();
vector<CObserver*>::iterator iter_end = m_ObserverVec.end();
for(;iter!=iter_end;iter++)
{
if((*iter) == p)
{
m_ObserverVec.erase(iter);
break;
}
}
}
//֪ͨ<CDA8><D6AA><EFBFBD>й۲<D0B9><DBB2>߸<EFBFBD><DFB8><EFBFBD>
void CSubject::NotifyObservers()
{
vector<CObserver*>::iterator iter = m_ObserverVec.begin();
vector<CObserver*>::iterator iter_end = m_ObserverVec.end();
for(;iter!=iter_end;iter++)
{
(*iter)->Update();
}
}
void CSubject::SetObserversVal1(double val)
{
vector<CObserver*>::iterator iter = m_ObserverVec.begin();
vector<CObserver*>::iterator iter_end = m_ObserverVec.end();
for(;iter!=iter_end;iter++)
{
(*iter)->SetVal1(val);
}
}