添加中介者模式

master
a7458969 2020-05-21 17:32:46 +08:00
parent be3e09a06f
commit c74021ed3c
2 changed files with 51 additions and 2 deletions

View File

@ -34,7 +34,7 @@ aux_source_directory(src DIRSRCS)
aux_source_directory(src/pattern PaternSrc)
add_library(General OBJECT ${DIRSRCS} ${PaternSrc} src/pattern/signleton.hpp src/pattern/Observer.hpp src/pattern/stratergy.hpp src/pattern/adapter.hpp src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h src/encrypt/rsa.cpp
add_library(General OBJECT ${DIRSRCS} ${PaternSrc} src/pattern/signleton.hpp src/pattern/Observer.hpp src/pattern/stratergy.hpp "src/ b-+/adapter.hpp" src/encrypt/base64.cpp src/encrypt/base64.h src/encrypt/aes.cpp src/encrypt/aes.h src/encrypt/rsa.cpp
src/math/BigInt.hpp src/net/TcpClient.cpp src/net/TcpClient.h src/net/PackageReceiver.cpp src/net/PackageReceiver.h src/function/btree.cpp src/function/btree.h src/algorithm/sorter.hpp)
set(COPYITEM inc)

View File

@ -4,6 +4,8 @@
#ifndef GENERAL_ADAPTER_H
#define GENERAL_ADAPTER_H
#include <string>
#include <map>
template <typename T>
class Adapter{
T mAdapter;
@ -31,10 +33,57 @@ template <typename T>
class ResponsabilityChan{
public:
int AddNext(ResponsabilityChan *p){
}
private:
ResponsabilityChan *mHead;
ResponsabilityChan *mTail;
};
class Mediator;
template<typename T>
class MediatorColleague{
public:
MediatorColleague(std::string name,Mediator *p){
mName = name;
mMediater = p;
}
std::string GetName(){
return mName;
};
int SetMediater(Mediator* p){
mMediater = p;
}
virtual int Send(std::string colleage,T* data){
}
private:
MediatorColleague(){
}
std::string mName;
Mediator *mMediater;
};
class Mediator{
public:
virtual int Register(MediatorColleague *p){ // 注册
if (nullptr == p){
return -1;
}
if(mColleague.find(p->GetName()) != mColleague.end()){
return -1;
}
mColleague[p->GetName()] = p;
p->SetMediater(this);
return -1;
}
virtual int Relay(MediatorColleague *p){ //转发
return -1;
}
private:
std::map<std::string,MediatorColleague*> mColleague;
};
#endif //GENERAL_ADAPTER_H