#include <iostream>
#include <vector>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;
class CEntry;
typedef vector<CEntry> E_vec;
class CObserver
{
public:
CObserver();
~CObserver();
int Add_Member(CEntry m);
int Remove_Member();
int Update(string m);
public:
E_vec m_vec;
string m_date;
};
class CEntry
{
public:
CEntry(CObserver * m,int state);
CEntry(int state);
~CEntry();
public:
int Update();
public:
CObserver * m_date;
int m_state;
};
template <typename T>
struct SCompare:public binary_function<T,T,bool>
{
bool operator()(T a,T b)
{
return a.m_state == b.m_state;
}
};
CObserver::CObserver()
{
cout<<"CObserver Constructor!"<<endl;
m_date = "";
}
CObserver::~CObserver()
{
cout<<"CObserver Destructor!"<<endl;
}
int CObserver::Add_Member(CEntry m)
{
m_vec.push_back(m);
cout<<"CObserver Add_Member!"<<endl;
return 0;
}
bool CC(CEntry a,int s)
{
return a.m_state == 3;
}
int CObserver::Remove_Member()
{
m_vec.back();
m_vec.pop_back();
cout<<"CObserver Remove_Member!"<<endl;
return 0;
}
int CObserver::Update(string m)
{
if(m_date.empty())
{
m_date = m;
cout<<"CObserver Update NULL!"<<endl;
}
else
{
cout<<"CObserver Update:["<<m_date<<"],change:["<<m<<"]"<<endl;
m_date.erase();
m_date = m;
}
E_vec::iterator e_iter;
for(e_iter = m_vec.begin();e_iter != m_vec.end();++e_iter)
{
(*e_iter).Update();
}
return 1;
}
CEntry::CEntry(CObserver * m,int state)
{
m_date = m;
m_state = state;
}
CEntry::CEntry(int state)
{
m_date = NULL;
m_state = state;
}
int CEntry::Update()
{
cout<<"CEntry Update!"<<m_date->m_date<<","<<m_state<<endl;
return 0;
}
CEntry::~CEntry()
{
}