C++ 对象间通信框架 V2.0 ××××××× 之(五)
类定义:
=======================================================================
// MemberFuncPointer.h: interface for the CMemberFuncPointer class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_)
#define AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_ #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 // 成员函数指针最大长度
#define MEMBER_FUNC_POINTER_MAX_SIZE 32
class CMemberFuncPointer
{
public:
void Reset();
void Set(const void*pFunc,int p_size);
void Get(void*pFunc);
CMemberFuncPointer();
CMemberFuncPointer(const char pointerdata[],int p_size);
CMemberFuncPointer(void* pointerdata,int p_size);
virtual ~CMemberFuncPointer(); bool operator==(const CMemberFuncPointer &mfp) const;
bool operator!=(const CMemberFuncPointer &mfp) const; CMemberFuncPointer& operator=(const CMemberFuncPointer &mfp); private:
int m_size;
char m_pointer_data[MEMBER_FUNC_POINTER_MAX_SIZE];
}; #endif // !defined(AFX_MEMBERFUNCPOINTER_H__4D78718D_778E_4427_BBC1_C5F2D52C64E5__INCLUDED_)
MemberFuncPointer.h
// MemberFuncPointer.cpp: implementation of the CMemberFuncPointer class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "OverlapRoutine.h"
#include "MemberFuncPointer.h" #ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// CMemberFuncPointer::CMemberFuncPointer()
{
this->m_size = ;
} CMemberFuncPointer::CMemberFuncPointer(const char pointerdata[],int p_size)
{
if(p_size<=MEMBER_FUNC_POINTER_MAX_SIZE)
{
this->m_size = p_size;
memcpy(this->m_pointer_data,pointerdata,p_size);
}
else
{
this->m_size = ;
}
} CMemberFuncPointer::CMemberFuncPointer(void* pointerdata,int p_size)
{
if(p_size<=MEMBER_FUNC_POINTER_MAX_SIZE)
{
this->m_size = p_size;
memcpy(this->m_pointer_data,pointerdata,p_size);
}
else
{
this->m_size = ;
}
} CMemberFuncPointer::~CMemberFuncPointer()
{ } bool CMemberFuncPointer::operator==(const CMemberFuncPointer &mfp) const
{
if(this->m_size==mfp.m_size) //mfp.m_size 可以访问私有成员
{
if(==memcmp(this->m_pointer_data,mfp.m_pointer_data,this->m_size))
{
return true;
}
} return false;
} bool CMemberFuncPointer::operator!=(const CMemberFuncPointer &mfp) const
{
if(this->m_size==mfp.m_size) //mfp.m_size 可以访问私有成员
{
if(==memcmp(this->m_pointer_data,mfp.m_pointer_data,this->m_size))
{
return false;
}
} return true;
} void CMemberFuncPointer::Get(void *pFunc)
{
memcpy(pFunc,this->m_pointer_data,this->m_size);
} void CMemberFuncPointer::Set(const void *pFunc,int p_size)
{
memcpy(this->m_pointer_data,pFunc,p_size);
this->m_size = p_size;
} void CMemberFuncPointer::Reset()
{
this->m_size = ;
} CMemberFuncPointer& CMemberFuncPointer::operator =(const CMemberFuncPointer &mfp)
{
if(this != &mfp)
{
memcpy(this->m_pointer_data,mfp.m_pointer_data,mfp.m_size); //mfp.m_pointer_data 可以访问私有成员
this->m_size = mfp.m_size; //mfp.m_size 可以访问私有成员
} return *this;
}
CMemberFuncPointer.cpp
// _ss_slot_item.h: interface for the C_ss_slot_item class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX__SS_SLOT_ITEM_H__9F9FE84E_5DDA_480C_88CA_9B8AAB534B07__INCLUDED_)
#define AFX__SS_SLOT_ITEM_H__9F9FE84E_5DDA_480C_88CA_9B8AAB534B07__INCLUDED_ #include "ss_type_def.h"
#include <Afxtempl.h> #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 /*
信号接收对象类: 包括信号接收对象指针,槽接口对象列表
*/ class C_ss_slot_item
{
public:
int DisConnectSS(CMemberFuncPointer slot_F);
void Set_SLOTFUNC(SS_STAIC_SLOTFUNC slotfunc);
int Signal(void *pSrc, void *pDes);
int Add(CMemberFuncPointer &slot_F);
void* Get_slotSelf();
void Set_slotSelf(void *slot_pSelf);
C_ss_slot_item();
virtual ~C_ss_slot_item(); private:
void* m_slot_pSelf;
CArray<CMemberFuncPointer*,CMemberFuncPointer*>*m_pMFPArray;
SS_STAIC_SLOTFUNC m_slot_pFunc;
CMemberFuncPointer m_curFuncPointer;
}; #endif // !defined(AFX__SS_SLOT_ITEM_H__9F9FE84E_5DDA_480C_88CA_9B8AAB534B07__INCLUDED_)
_ss_slot_item.h
// _ss_slot_item.cpp: implementation of the C_ss_slot_item class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "OverlapRoutine.h"
#include "_ss_slot_item.h"
#include <Afxtempl.h> #ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// C_ss_slot_item::C_ss_slot_item()
{
this->m_slot_pSelf = NULL;
this->m_pMFPArray = new CArray<CMemberFuncPointer*,CMemberFuncPointer*>;
this->m_slot_pFunc = NULL;
} C_ss_slot_item::~C_ss_slot_item()
{ } void C_ss_slot_item::Set_slotSelf(void *slot_pSelf)
{
this->m_slot_pSelf = (void*)slot_pSelf;
} void* C_ss_slot_item::Get_slotSelf()
{
return this->m_slot_pSelf;
} int C_ss_slot_item::Add(CMemberFuncPointer &slot_F)
{
int len = this->m_pMFPArray->GetSize();
CMemberFuncPointer *pTemp = NULL;
for(int i=;i<len;i++)
{
pTemp = this->m_pMFPArray->GetAt(i);
if(*pTemp == slot_F)
{
return ;
}
}
pTemp = new CMemberFuncPointer;
*pTemp = slot_F;
this->m_pMFPArray->Add(pTemp);
return ;
} int C_ss_slot_item::Signal(void *pSrc, void *pDes)
{
int res = ;
if(this->m_slot_pFunc!=NULL)
{
int len = this->m_pMFPArray->GetSize();
for(int i=;i<len;i++)
{
CMemberFuncPointer tempFP = *(this->m_pMFPArray->GetAt(i));
if(this->m_curFuncPointer != tempFP)
{
this->m_curFuncPointer = tempFP;
this->m_slot_pFunc(this->m_slot_pSelf,tempFP,pSrc,pDes);
res+=;
} //防止嵌套调用死循环
this->m_curFuncPointer.Reset();
}
}
return res;
} void C_ss_slot_item::Set_SLOTFUNC(SS_STAIC_SLOTFUNC slotfunc)
{
this->m_slot_pFunc = slotfunc;
} int C_ss_slot_item::DisConnectSS(CMemberFuncPointer slot_F)
{
int len = this->m_pMFPArray->GetSize();
CMemberFuncPointer *pTemp;
for(int i=;i<len;i++)
{
pTemp = this->m_pMFPArray->GetAt(i);
if(*pTemp==slot_F)
{
delete pTemp;
this->m_pMFPArray->RemoveAt(i);
return ;
}
}
return ;
}
_ss_slot_item.cpp
// _ss_signal_item.h: interface for the C_ss_signal_item class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX__SS_SIGNAL_ITEM_H__CA28EC16_931C_4ACA_8897_0A81B3DA967B__INCLUDED_)
#define AFX__SS_SIGNAL_ITEM_H__CA28EC16_931C_4ACA_8897_0A81B3DA967B__INCLUDED_ #include "_ss_signal_func.h"
#include <Afxtempl.h> #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
/*
信号发起方对象类: 包含发起方对象指针,信号接口对象列表
*/
class C_ss_signal_item
{
public:
int DisConnectSS(CMemberFuncPointer signal_F, void *slot_pSelf, CMemberFuncPointer slot_F);
int Signal(CMemberFuncPointer signal_F,void *pSrc, void *pDes);
void Set_signalSelf(void *signal_pSelf);
int Add(CMemberFuncPointer &signal_F, void *slot_pSelf, CMemberFuncPointer& slot_F,SS_STAIC_SLOTFUNC slot_pFunc);
void* Get_signalSelf();
C_ss_signal_item();
virtual ~C_ss_signal_item();
private:
void* m_signal_pSelf;
CArray<C_ss_signal_func*,C_ss_signal_func*>*m_pSFArray;
SS_STAIC_SLOTFUNC m_slotfunc;
}; #endif // !defined(AFX__SS_SIGNAL_ITEM_H__CA28EC16_931C_4ACA_8897_0A81B3DA967B__INCLUDED_)
_ss_signal_item.h
// _ss_signal_item.cpp: implementation of the C_ss_signal_item class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "OverlapRoutine.h"
#include "_ss_signal_item.h" #ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif //////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
C_ss_signal_item::C_ss_signal_item()
{
this->m_signal_pSelf = NULL;
this->m_pSFArray = new CArray<C_ss_signal_func*,C_ss_signal_func*>;
this->m_slotfunc = NULL;
} C_ss_signal_item::~C_ss_signal_item()
{ } void* C_ss_signal_item::Get_signalSelf()
{
return this->m_signal_pSelf;
} int C_ss_signal_item::Add(CMemberFuncPointer &signal_F, void *slot_pSelf,CMemberFuncPointer& slot_F,SS_STAIC_SLOTFUNC slot_pFunc)
{
int len = this->m_pSFArray->GetSize();
C_ss_signal_func* pTemp=NULL;
for(int i=;i<len;i++)
{
pTemp = this->m_pSFArray->GetAt(i);
if(pTemp->Get_signal_F()==signal_F)
{
return pTemp->Add(slot_pSelf,slot_F,slot_pFunc);
}
} pTemp = new C_ss_signal_func;
pTemp->Set_signal_F(signal_F); if(==pTemp->Add(slot_pSelf,slot_F,slot_pFunc))
{
this->m_pSFArray->Add(pTemp);
return ;
} delete pTemp;
return -;
} void C_ss_signal_item::Set_signalSelf(void *signal_pSelf)
{
this->m_signal_pSelf = (void*)signal_pSelf;
} int C_ss_signal_item::Signal(CMemberFuncPointer signal_F, void *pSrc, void *pDes)
{
int res = ;
int len = this->m_pSFArray->GetSize();
C_ss_signal_func *p_signal_func;
for(int i =;i<len;i++)
{
p_signal_func = this->m_pSFArray->GetAt(i);
if(p_signal_func->Get_signal_F()==signal_F)
{
res = p_signal_func->Signal(pSrc,pDes);
return res;
}
}
return res;
} int C_ss_signal_item::DisConnectSS(CMemberFuncPointer signal_F, void *slot_pSelf, CMemberFuncPointer slot_F)
{
int len = this->m_pSFArray->GetSize();
C_ss_signal_func *pTemp = NULL;
for(int i=;i<len;i++)
{
pTemp = this->m_pSFArray->GetAt(i);
if(pTemp->Get_signal_F()==signal_F)
{
return pTemp->DisConnectSS(slot_pSelf,slot_F);
}
}
return ;
}
_ss_signal_item.cpp
// _ss_signal_func.h: interface for the C_ss_signal_func class.
//
////////////////////////////////////////////////////////////////////// #if !defined(AFX__SS_SIGNAL_FUNC_H__59FB419F_4520_420E_BE2A_D9E6248FD1A1__INCLUDED_)
#define AFX__SS_SIGNAL_FUNC_H__59FB419F_4520_420E_BE2A_D9E6248FD1A1__INCLUDED_ #include "_ss_slot_item.h"
#include "MemberFuncPointer.h" // Added by ClassView
#include <Afxtempl.h> #if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000 /*
信号接口对象类: 包括信号接口对象地址,信号接收对象列表
*/ class C_ss_signal_func
{
public:
int DisConnectSS(void *slot_pSelf, CMemberFuncPointer slot_F);
int Signal(void *pSrc, void *pDes);
void Set_signal_F(CMemberFuncPointer &signal_F);
int Add(void *slot_pSelf,CMemberFuncPointer &slot_F,SS_STAIC_SLOTFUNC slot_pFunc);
CMemberFuncPointer& Get_signal_F();
C_ss_signal_func();
virtual ~C_ss_signal_func();
private:
CMemberFuncPointer m_signal_F;
CArray<C_ss_slot_item*,C_ss_slot_item*>*m_pSlotArray;
}; #endif // !defined(AFX__SS_SIGNAL_FUNC_H__59FB419F_4520_420E_BE2A_D9E6248FD1A1__INCLUDED_)
_ss_signal_func.h
// _ss_signal_func.cpp: implementation of the C_ss_signal_func class.
//
////////////////////////////////////////////////////////////////////// #include "stdafx.h"
#include "OverlapRoutine.h"
#include "_ss_signal_func.h" #ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif //////////////////////////////////////////////////////////////////////
// Construction/Destruction
////////////////////////////////////////////////////////////////////// C_ss_signal_func::C_ss_signal_func()
{
this->m_pSlotArray = new CArray<C_ss_slot_item*,C_ss_slot_item*>;
} C_ss_signal_func::~C_ss_signal_func()
{ } CMemberFuncPointer& C_ss_signal_func::Get_signal_F()
{
return this->m_signal_F;
} int C_ss_signal_func::Add(void *slot_pSelf,CMemberFuncPointer &slot_F,SS_STAIC_SLOTFUNC slot_pFunc)
{
int len = this->m_pSlotArray->GetSize();
C_ss_slot_item *pTemp=NULL;
for(int i=;i<len;i++)
{
pTemp = this->m_pSlotArray->GetAt(i);
if(pTemp->Get_slotSelf()==slot_pSelf)
{
return pTemp->Add(slot_F);
}
} pTemp = new C_ss_slot_item;
pTemp->Set_slotSelf(slot_pSelf);
pTemp->Set_SLOTFUNC(slot_pFunc);
if(==pTemp->Add(slot_F))
{
this->m_pSlotArray->Add(pTemp);
return ;
} delete pTemp;
return -;
} void C_ss_signal_func::Set_signal_F(CMemberFuncPointer &signal_F)
{
this->m_signal_F = signal_F;
} int C_ss_signal_func::Signal(void *pSrc, void *pDes)
{
int res = ;
int len = this->m_pSlotArray->GetSize();
C_ss_slot_item *p_slot_item;
for(int i=;i<len;i++)
{
p_slot_item = this->m_pSlotArray->GetAt(i);
res += p_slot_item->Signal(pSrc,pDes);
}
return res;
} int C_ss_signal_func::DisConnectSS(void *slot_pSelf, CMemberFuncPointer slot_F)
{
int len = this->m_pSlotArray->GetSize();
C_ss_slot_item *pTemp = NULL;
for(int i=;i<len;i++)
{
pTemp = this->m_pSlotArray->GetAt(i);
if(pTemp->Get_slotSelf()==slot_pSelf)
{
return pTemp->DisConnectSS(slot_F);
}
}
return ;
}
_ss_signal_func.cpp
C++ 对象间通信框架 V2.0 ××××××× 之(五)的更多相关文章
- C++ 对象间通信框架 V2.0 ××××××× 之一
V2.0 主要是信号槽连接的索引性能做了改进,新设计了程序构架实现了多级分层索引,索引时间性能基本不受连接表的大小影响. 类定义:CSignalSlot C_MemberFuncPointer C_s ...
- C++ 对象间通信框架 V2.0 ××××××× 之(三)
类定义:CSignalSlot ======================================================================= // SignalSlo ...
- C++ 对象间通信框架 V2.0 ××××××× 之(二)
公共头文件:ss_type_def.h ================================================================================ ...
- C++ 对象间通信框架 V2.0 ××××××× 之(四)
类定义:CMemberFuncPointer ======================================================================= // Me ...
- 文件断点续传原理与实现—— ESFramework 通信框架4.0 进阶(12)
在ESFramework通信框架 4.0 快速上手(13) -- 文件传送,如此简单一文的详细介绍和ESFramework通信框架 4.0 快速上手(14) -- 聊天系统Demo,增加文件传送功能( ...
- C++对象间通信组件,让C++对象“无障碍交流”
介绍 这是很久之前的一个项目了,最近刚好有些时间,就来总结一下吧! 推荐初步熟悉项目后阅读本文: https://gitee.com/smalldyy/easy-msg-cpp 从何而来 这要从我从事 ...
- 可靠通信的保障 —— 使用ACK机制发送自定义信息——ESFramework 通信框架4.0 快速上手(12)
使用ESPlus.Application.CustomizeInfo.Passive.ICustomizeInfoOutter接口的Send方法,我们已经可以给服务端或其它在线客户端发送自定义信息了, ...
- 接口自动化 基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版]
基于python+Testlink+Jenkins实现的接口自动化测试框架[V2.0改进版] by:授客 QQ:1033553122 由于篇幅问题,,暂且采用网盘分享的形式: 下载地址: [授客] ...
- ESPlatform 支持的三种群集模型 —— ESFramework通信框架 4.0 进阶(09)
对于最多几千人同时在线的通信应用,通常使用单台服务器就可以支撑.但是,当同时在线的用户数达到几万.几十万.甚至百万的时候,我们就需要很多的服务器来分担负载.但是,依据什么规则和结构来组织这些服务器,并 ...
随机推荐
- mysql常用知识点之limit
limit函数的应用.limit后面跟整数,如limit 5,表示在结果集中取前5条:limit后跟整数区间,如limit 2,5,表示在结果集中 从第3条开始,取5条数据,第一个整数表示结果集的顺序 ...
- mysql驱动表与被驱动表及join优化
驱动表与被驱动表 先了解在join连接时哪个表是驱动表,哪个表是被驱动表:1.当使用left join时,左表是驱动表,右表是被驱动表2.当使用right join时,右表时驱动表,左表是驱动表3.当 ...
- JavaScript Return Object.Type
var getType = function(obj) { if (obj == null) { return String(obj); } return typeof obj === 'object ...
- Js AJAX Event
;(function () { if ( typeof window.CustomEvent === "function" ) return false; function Cus ...
- [19/09/19-星期四] Python中的字典和集合
一.字典 # 字典 # 使用 {} 来创建字典 d = {} # 创建了一个空字典 # 创建一个保护有数据的字典 # 语法: # {key:value,key:value,key:value} # 字 ...
- vmware下使用nat方法联网
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明.本文链接:https://blog.csdn.net/Li_Zefeng/article/det ...
- C#多线程下更新UI的几种方法
1. 使用UI线程的SynchronizationContext的Post/Send方法,这种情况一般在窗体构造函数或者FormLoad中获取同步上下文: 范例: public partial cla ...
- 前端开发HTML&css入门——一些其他常用的文本标签
em标签和strong标签 i标签和b标签 small标签 cite标签 q标签和blockquote标签 em主要表示语气上的强调,em在浏览器中默认使用斜体显示strong表示强调的内容,比em更 ...
- Mybatis SQL 使用JAVA 静态资源
常量:${@com.htsc.backtest.component.Global@PAGE_SIZE} 静态方法:${@com.htsc.backtest.component.Global@doMet ...
- 【串线篇】spring boot嵌入式Servlet容器启动原理;
什么时候创建嵌入式的Servlet容器工厂?什么时候获取嵌入式的Servlet容器并启动Tomcat: 获取嵌入式的Servlet容器工厂: 1).SpringBoot应用启动运行run方法 2).r ...