MVoteMgr.h
00001 #ifndef _MVOTEMGR_H 00002 #define _MVOTEMGR_H 00003 00004 //#pragma once 00005 00006 #include "MUID.h" 00007 using namespace std; 00008 #include <list> 00009 #include <map> 00010 00011 00012 enum MVOTE { 00013 MVOTE_GIVEUP, 00014 MVOTE_YES, 00015 MVOTE_NO 00016 }; 00017 00018 00019 class MVoter { 00020 protected: 00021 MUID m_uidVoter; 00022 public: 00023 MVoter(MUID uid) { m_uidVoter = uid; } 00024 MUID GetID() { return m_uidVoter; } 00025 }; 00026 class MVoterMap : public map<MUID, MVoter*> {}; 00027 00028 00029 class MVoteDiscuss { 00030 protected: 00031 MUID m_uidStage; // 스테이지UID 00032 string m_strDiscuss; // 안건 00033 unsigned long m_nBeginTime; // 발의된 시간 00034 list<MUID> m_YesVoterList; // 찬성자 00035 list<MUID> m_NoVoterList; // 반대자 00036 00037 public: 00038 MVoteDiscuss(const MUID& uidStage); 00039 virtual ~MVoteDiscuss(); 00040 00041 MUID GetStageUID() { return m_uidStage; } 00042 const char* GetDiscussName() { return m_strDiscuss.c_str(); } 00043 unsigned long GetBeginTime() { return m_nBeginTime; } 00044 size_t GetYesVoterCount() { return m_YesVoterList.size(); } 00045 size_t GetNoVoterCount() { return m_NoVoterList.size(); } 00046 00047 bool CheckVoter(const MUID& uid); // 투표자인지 검사 00048 void Vote(const MUID& uid, MVOTE nVote); 00049 public: 00050 virtual bool OnJudge(bool bJudge) = 0; 00051 }; 00052 00053 00054 class MVoteMgr { 00055 public: 00056 enum VOTEMGR_ERROR { 00057 VOTEMGR_ERROR_OK, 00058 VOTEMGR_ERROR_UNKNOWN, 00059 VOTEMGR_ERROR_VOTE_NODISCUSS, 00060 VOTEMGR_ERROR_VOTE_INPROGRESS, 00061 VOTEMGR_ERROR_VOTE_ALREADY_VOTED 00062 }; 00063 00064 protected: 00065 MVoterMap m_VoterMap; 00066 MVoteDiscuss* m_pDiscuss; 00067 VOTEMGR_ERROR m_nLastDiscussError; 00068 00069 protected: 00070 bool CheckDiscuss(); 00071 void FinishDiscuss(bool bJudge); 00072 00073 public: 00074 MVoteMgr(); 00075 virtual ~MVoteMgr(); 00076 00077 MVoter* FindVoter(const MUID& uid); 00078 void AddVoter(const MUID& uid); 00079 void RemoveVoter(const MUID& uid); 00080 00081 MVoteDiscuss* GetDiscuss() { return m_pDiscuss; } 00082 VOTEMGR_ERROR GetLastError() { return m_nLastDiscussError; } 00083 void SetLastError(VOTEMGR_ERROR nError) { m_nLastDiscussError = nError; } 00084 00085 bool CallVote(MVoteDiscuss* pDiscuss); 00086 bool Vote(const MUID& uid, MVOTE nVote); 00087 void Tick(unsigned long nClock); 00088 }; 00089 00090 /* 00091 void Client() 00092 { 00093 MVoteMgr m_VoteMgr; 00094 00095 m_VoteMgr.AddVoter( MUID(0,1) ); 00096 m_VoteMgr.AddVoter( MUID(0,2) ); 00097 m_VoteMgr.AddVoter( MUID(0,3) ); 00098 00099 m_VoteMgr.CallVote(new MVoteDiscussKick()); 00100 00101 m_VoteMgr.Vote(MUID(0,1), MVOTE_YES); 00102 m_VoteMgr.Vote(MUID(0,2), MVOTE_YES); 00103 m_VoteMgr.Vote(MUID(0,3), MVOTE_NO); 00104 } 00105 */ 00106 00107 #endif
MAIET entertainment