| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> c/c++ >> C++ zhong jian li dui xiang jian xiao xi lian jie de xi tong fang fa

C++ zhong jian li dui xiang jian xiao xi lian jie de xi tong fang fa

2008-06-01 02:07:31 编辑來源:互联网 评论
 
 
 
本文为【C++中建立对象间消息连接的系统方法】的拼音翻译版
  yong guo C++ jin xing guo mian xiang dui xiang cheng xu she ji de yong hu dou zhi dao , cheng xu zhong de dui xiang hen shao dan du cun zai 。 bu kao lv dui xiang jian de xiang hu zuo yong ji hu shi bu ke neng de 。 suo yi , biao shi dui xiang jian de guan xi huo jian li dui xiang jian de xiao xi lian jie shi mian xiang dui xiang cheng xu she ji de yi xiang chong yao ren wu 。
   ben wen zhe chong cong C++ cheng xu she ji de jiao du , ti chu yi zhong jian li dui xiang jian xiao xi lian jie de shi yong fang fa 。 jia ru ni xiang ju ti le jie mian xiang dui xiang cheng xu she ji ji shu , qing shen yue you guan zhuan zhu 。
  da jia dou zhi dao dui xiang shi shu ju he fang fa de feng zhuang ti 。 zai C++ zhong , ta men fen bie biao xian wei shu ju cheng yuan he cheng yuan han shu 。 cheng xu she ji zhe tong guo zhi xing dui xiang de ge zhong fang fa , lai gai bian dui xiang de zhuang tai ( ji gai bian dui xiang de shu xing shu ju )。 cong er shi gai dui xiang fa sheng mou xie “ shi jian ”。 dang yi dui xiang fa sheng mou shi jian shi , ta tong chang xu xiang qi ta xiang guan dui xiang fa song “ xiao xi ”, qing qiu ta men zuo chu yi xie chu li 。 zhe shi , fa sheng shi jian bing xiang qi ta dui xiang qing qiu chu li de dui xiang bei cheng wei “ shi jian dui xiang ”, er chu li shi jian de dui xiang bei cheng wei “ hui tiao dui xiang ”。 hui tiao dui xiang dui shi jian de chu li cheng wei “ hui tiao han shu ”。
  zai C++ zhong , zhe yi guo cheng xiang dang yu : dang shi jian dui xiang fa sheng shi jian shi , tiao yong hui tiao dui xiang de mou xie cheng yuan han shu 。 tong chang de zuo fa shi hui tiao dui xiang xiang shi jian dui xiang chuan di dui xiang zhi zhen 。 dan zhe zhong fang fa bu tong yong 。 wei le jian shao cheng xu she ji de gong zuo liang , ben wen ti chu yi zhong jian li dui xiang jian xiao xi lian jie de xi tong fang fa 。 ta de si lu shi : jiang “ shi jian fa sheng → qing qiu chu li → zhi xing chu li ” zhe yi guo cheng chou xiang cheng yi ge “ hui tiao ”(CallBack) lei 。 tong guo ji xu , yong hu ke yi qing song huo qu jian li dui xiang jian xiao xi lian jie de ji zhi 。
  yi 、 hui tiao lei de shu ju jie gou ji qi cheng yuan han shu
  ben wen ti chu de CallBack lei zhi chi san zhong hui tiao han shu 。 ta men shi : hui tiao dui xiang zhong de cheng yuan han shu , shu yu hui tiao lei de jing tai cheng yuan han shu he pu tong de C han shu 。CallBackle lei zhong bao han yi hui tiao han shu biao callBackList。 ta yong yu ji lu shi jian ming cheng , zhi xiang hui tiao han shu ji hui tiao dui xiang de zhi zhen 。 gai biao de mei yi ge jie dian wei yi ge shi jian ji lu EventRecord。 mei ge shi jian ji lu bao han san ge yu : shi jian ming zhi zhen eventName, zhi xiang hui tiao dui xiang de zhi zhen pointerToCBO, zhi xiang hui tiao han shu de zhi zhen pointerToCBF huo pointerToCBSF( qi zhong ,pointerToCBF zhi xiang hui tiao dui xiang de cheng yuan han shu ,pointerToCBSF zhi xiang hui tiao lei de jing tai cheng yuan han shu huo pu tong han shu 。 ta men tong chu yu yi gong yong ti nei )。CallBack lei suo ti gong de hui tiao ji zhi shi zhe yang de : zai shi jian dui xiang shang zhu ce hui tiao dui xiang zhong de hui tiao han shu ; dang shi jian fa sheng shi , shi jian dui xiang zai qi hui tiao biao zhong jian suo bing zhi xing hui tiao han shu 。 cong er shi er zhe de xiao xi lian jie de yi jian li 。( guan yu gai lei de ju ti shi xian , qing shen yue wen hou suo fu de cheng xu qing dan ) hui tiao dui xiang
  shi jian dui xiang
  shi jian ming hui tiao dui xiang zhi zhen hui tiao han shu zhi zhen
  “event” pointerCBO pointerToCBF huo
  pointerTOCBSF
  - - - - - -
  AddCallBack: zhu ce shi jian ming he zhi xiang hui tiao han shu , hui tiao dui xiang de zhi zhen
  CallCallBack: zai hui tiao biao zhong , jian suo zhu ce zai zhi ding shi jian shang hui tiao han shu bing tiao yong ta men
  shi jian fa sheng shi , tiao yong CallCallBack han shu
  dui shi jian event jin xing chu li de cheng yuan han shu
  cong CallBack lei ji xu de hui tiao biao callBackList, cheng yuan han shu AddCallBack he CallCallBack。
  dang hui tiao han shu wei jing tai cheng yuan han shu huo pu tong C han shu shi , pointerToCBO wei NULL。
  shi jian ming shi hui tiao biao callBackLis zhong de jian suo yao hai zi 。
  hui tiao dui xiang zhong qi ta cheng yuan han shu
  CallBack lei de cheng yuan han shu AddCallBack yong lai jiang hui tiao han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 ta you liang ge chong zai ban ben :
  void CallBack::AddCallBack(char *event,CallBackFunction cbf,CallBack *p);
  void CallBack::AddCallBack(char *event,CallBackStaticFunction cbsf);
  qi zhong , di yi ge AddCallBack yong lai jiang mou hui tiao dui xiang de cheng yuan han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 di er ge AddCallBack yong lai jiang huo mou hui tiao lei de jing tai cheng yuan han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 zai shang shen shu biao zhong ,event shi zhi xiang shi jian ming zi fu chuan de zhi zhen ,p shi zhi xiang hui tiao dui xiang de zhi zhen ,cbf he cbsf fen bie shi zhi xiang cheng yuan han shu ji jing tai cheng yuan han shu ( huo pu tong han shu ) de zhi zhen 。 dang hui tiao han shu lai zi mou hui tiao dui xiang SomeObject shi , chuan di cheng yuan han shu zhi zhen ying cai yong ru xia ge shi :
  (CallBackFunction)&SomeObject::MemberFunctionName; chuan di SomeObject lei de mou jing tai cheng yuan han shu zhi zhen ying cai yong ge shi :
  (CallBackStaticFunction)& SomeObject::FunctionName; chuan di cheng xu zhong pu tong han shu zhi zhen shi , zhi xu chuan di han shu ming ji ke 。
  CallBack lei de cheng yuan han shu void CallBack::CallCallBack(char *ename, CallData calldata = NULL) yong lai tiao yong zhu ce zai shi jian ename shang de suo you hui tiao han shu 。 qi zhong ,calldata wei shu ju zhi zhen (CallData shi ji shang jiu shi void*, xiang jian cheng xu qing dan )。 shi jian dui xiang ke tong guo ta xiang hui tiao dui xiang chuan di you yong de shu ju 。 gai cheng yuan han shu tong chang zai shi jian dui xiang de cheng yuan han shu zhong tiao yong , yin wei tong chang zhi you shi jian dui xiang de cheng yuan han shu cai neng gai bian dui xiang de nei bu shu ju , cong er shi mou xie shi jian fa sheng 。
  cheng yuan han shu RemoveCallback yong lai shan chu zhu ce zai shi jian dui xiang shang de hui tiao han shu 。 ta de san ge chong zai ban ben yi ci wei :
  void CallBack::RemoveCallBack(char *event,CallBackFunction cbf,CallBack *p);
  void CallBack::RemoveCallBack(char *event,CallBackStaticFunction cbsf);
  void CallBack::RemoveCallBack(char *event);
  qi zhong ,event,cbf,cbsf,p deng shen shu he cheng yuan han shu AddCallBack zhong ge shen shu yi yang 。 di yi ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang mou hui tiao dui xiang de yi ge cheng yuan han shu 。 di er ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang de mou pu tong han shu huo mou hui tiao lei de yi ge jing tai cheng yuan han shu 。 di san ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang de quan bu hui tiao han shu 。
  er 、CallBack lei de shi yong fang fa
  shi yong CallBack lei , ke an yi xia bu zhou jin xing :
  1. que ding cheng xu zhong na xie dui xiang jian cun zai guan xi , xu yao jian li xiao xi lian jie 。 bing que ding zai ge te ding xiao xi lian jie guan xi zhong , na ge dui xiang shi shi jian dui xiang , na ge dui xiang shi hui tiao dui xiang 。
  2. shi jian dui xiang lei he hui tiao dui xiang lei dou bi xu cong CallBack lei ji xu , yi huo de hui tiao zhi chi 。
  3. wei shi jian dui xiang zhu ce hui tiao shu ju 。 bao kuo : shi jian ming , hui tiao han shu ming , zhi xiang hui tiao dui xiang de zhi zhen 。
  4. dang ni gan ai hao de shi jian fa sheng shi , zai shi jian dui xiang lei yin fa shi jian de cheng yuan han shu zhong tiao yong CallCallBack han shu 。
  xia mian shi yi ge ju ti de li zi 。 tong guo ta ni hui dui Callback lei de shi yong fang fa you jin yi bu de le jie 。
  file:// ce shi cheng xu wen jian :test.cpp
  #include"callback.h"
  file://“ yang sheng qi ” lei
  class Speaker:public CallBack
  
   {
  private:
  int volume;
  public:
  Speaker(int v): volume(v) {}
  void IncreaseVolume(int v) file:// zeng jia yin liang cheng yuan han shu
  {
  volume += v;
  if(volume >20){ file://“ yin liang da yu 20” shi jian fa sheng le
  file:// tiao yong zhu ce zai liang shi jian shang de hui tiao han shu
  CallCallBack(" yin liang gai bian le ");
  CallCallBack(" yin liang da yu 20", &volume);
  }
  }
  void DecreaseVolume(int v) file:// jiang di yin liang cheng yuan han shu
  {
  volume -= v;
  if(volume < 5){ file://“ yin liang xiao yu 5” shi jian fa sheng le
  file:// tiao yong zhu ce zai liang shi jian shang de hui tiao han shu
  CallCallBack(" yin liang gai bian le ");
  CallCallBack(" yin liang xiao yu 5", &volume);
  }
  }
  };
  file://“ er duo ” lei
  class Ear : public CallBack
  {
  public:
  static void Response(CallData callData) file:// dui “ yin liang gai bian ” de fan ying
  {
  cout<<" yin liang gai bian le ."< }
  void HighVoiceResponse(CallData callData)// dui gao yin de fan ying
  {
  cout<<” wei ! tai chao le ! xian zai yin liang shi :"<<*((int *)callData)< }
  void LowVoiceResponse(CallData callData)// dui di yin de fan ying
  {
  cout<<" a ! wo ting bu qing le 。 xian zai yin liang shi :"<<*((int *)callData)< }
  };
  void main(void)
  {
  Speaker s(10); file:// xian zai yin liang wei 10
  Ear e;
  file:// wei shi jian dui xiang s zhu ce hui tiao han shu
  s.AddCallBack(" yin liang da yu 20”,(CallBackFunction)&Ear::HighVoiceResponse,&e);
  s.AddCallBack(" yin liang xiao yu 5”,(CallBackFunction)&Ear::LowVoiceResponse,&e);
  s.AddCallBack(" yin liang gai bian le ",(CallBackStaticFunction)&Ear::Response);
  s.IncreaseVolume(12);// jiang yin liang zeng jia 12, xian zai yin liang wei 22
  s.DecreaseVolume(20);// jiang yin liang jian shao 20, xian zai yin liang wei 2
  }
  yun xing jie guo :
  yin liang gai bian le .
  wei ! tai chao le ! xian zai yin liang shi :22
  yin liang gai bian le .
  a ! wo ting bu qing le 。 xian zai yin liang shi :2
  zai shang li zhong , yang sheng qi dui xiang s wei shi jian dui xiang , er duo dui xiang e wei hui tiao dui xiang 。。s shang bei zhu ce le san ge shi jian :“ yin liang gai bian le ”,“ yin liang da yu 20”,“ yin liang xiao yu 5”。 hui tiao han shu fen bie wei :Ear::Response, Ear::HighVoiceResponse,Ear::LowVoiceResponse。 dang yang sheng qi s tong guo qi cheng yuan han shu IncreaseVolume he DecreaseVolume gai bian yin liang shi , hui tiao dui xiang e hui zi dong zuo chu fan ying 。 ke jian , tong guo shi yong CallBack lei , zai dui xiang jian jian li xiao xi lian jie yi bian wei yi xiang hen jian dan he mei li de gong zuo 。
  you yu bi zhe shui ping you xian , gai lei de she ji bi you bu wan shan zhi chu 。 jia ru nin dui ta gan ai hao , bi zhe ke yu ge wei C++ wan jia gong tong tan tao zhe lei wen ti 。
  lian xi fang shi :fei_xiang@263.net
  geng duo nei rong qing kan C/C++ ji shu zhuan ti C/C++ jin jie ji shu wen dang xi tong an quan she zhi zhuan ti , huo
  fu : cheng xu qing dan ( ben cheng xu zai MS VC++5.0 he TC++3.0 shang yun bian yi tong guo )
  file:// hui tiao lei de lei jie gou :callback.h
  #ifndef _CALLBACK_H
  #define _CALLBACK_H
  #include<stdlib.h>
  #include<string.h>
  #include<iostream.h>
  #define CALLBACKLIST_INIT_SIZE 10
  #define CALLBACKLIST_INCREMENT 5
  class CallBack;
  typedef void *CallData;// hui tiao shu ju zhi zhen lei xing ding yi
  typedef void (CallBack::*CallBackFunction)(CallData); file:// zhi xiang hui tiao cheng yuan han shu de zhi zhen
  typedef void (*CallBackStaticFunction)(CallData); file:// zhi xiang jing tai cheng yuan han shu huo pu tong han shu de zhi zhen lei xing ding yi
  class EventRecord{
  private:
  char *eventName; file:// hui tiao shi jian ming cheng
  CallBack *pointerToCBO;// zhi xiang hui tiao dui xiang de zhi zhen
  file:// zhi xiang cheng yuan han shu de zhi zhen he zhi xiang jing tai cheng yuan han shu ( huo pu tong han shu ) zhi zhen de gong yong ti
  union{
  CallBackFunction pointerToCBF;
  CallBackStaticFunction pointerToCBSF;
  };
  public:
  EventRecord(void); file:// shi jian ji lu lei de que sheng gou zao han shu
  file:// gou zao bao han cheng yuan han shu de shi jian ji lu
  EventRecord(char *ename,CallBack *pCBO,CallBackFunction pCBF);
  
   file:// gou zao bao han jing tai cheng yuan han shu huo pu tong han shu de shi jian ji lu
  EventRecord(char *ename,CallBackStaticFunction pCBSF);
  ~EventRecord(void);// xi gou shi jian ji lu
  void operator = (const EventRecord& er);// chong zai fu zhi yun suan fu
  file:// pan ding dang qian shi jian ji lu de shi jian ming shi fou wei ename
  int operator == (char *ename) const;
  file:// pan ding dang qian shi jian ji lu shi fou he zhi ding shi jian ji lu xiang deng
  int operator == (const EventRecord& er) const;
  void Flush(void); file:// jiang dang qian shi jian ji lu qing kong
  int IsEmpty(void) const;// pan ding shi jian ji lu shi fou wei kong ( ji shi jian ming shi fou wei kong )
  friend class CallBack; file:// rang CallBack lei neng fang wen EventRecord de si you cheng yuan ;
  };
  class CallBack {
  private:
  EventRecord *callBackList; file:// hui tiao shi jian biao
  int curpos; file:// dang qian shi jian ji lu wei zhi
  int lastpos; file:// hui tiao biao zhong zui hou yi kong xian wei zhi
  int size; file:// hui tiao biao de da xiao
  void MoveFirst(void) { curpos = 0; }// jiang dang qian ji lu zhi wei di yi tiao ji lu
  void MoveNext(void) file:// jiang xia yi tiao ji lu zhi wei dang qian ji lu
  {
  if(curpos == lastpos) return;
  curpos++;
  }
  file:// pan ding hui tiao biao shi fou bei bian li wan
  int EndOfList(void) const { return curpos == lastpos; }
  public:
  CallBack(void);// gou zao han shu
  CallBack(const CallBack& cb);// kao bei gou zao han shu
  ~CallBack(void);// xi gou han shu
  void operator = (const CallBack& cb);// chong zai fu zhi yun suan fu
  file:// jiang hui tiao dui xiang de cheng yuan han shu 、 jing tai cheng yuan han shu ( huo pu tong han shu ) file:// zhu ce wei shi jian dui xiang de hui tiao han shu
  void AddCallBack(char *event,CallBackFunction cbf,CallBack *p);
  void AddCallBack(char *event,CallBackStaticFunction cbsf);
  file:// shan chu zhu ce zai zhi ding shi jian shang de hui tiao han shu
  void RemoveCallBack(char *event,CallBackFunction cbf,CallBack *p);
  void RemoveCallBack(char *event,CallBackStaticFunction cbsf);
  void RemoveCallBack(char *event);// shan chu mou shi jian de quan bu ji lu
  file:// zhi xing zhu ce zai mou yi shi jian shang de suo you hui tiao han shu
  void CallCallBack(char *event, CallData calldata = NULL);
  };
  #endif
  file:// hui tiao lei de shi xian :callback.cpp
  #include"callback.h"
  file://EventRecord lei de shi xian
  EventRecord::EventRecord(void)
  {
  eventName = NULL;
  pointerToCBO = NULL;
  file:// yin wei sizeof(CallBackFunction) > sizeof(CallBackStaticFunction)
  pointerToCBF = NULL;
  }
  EventRecord::EventRecord(char *ename, CallBack *pCBO, CallBackFunction pCBF)
  :pointerToCBO(pCBO), pointerToCBF(pCBF)
  {
  eventName = strdup(ename);
  }
  EventRecord::EventRecord(char *ename, CallBackStaticFunction pCBSF)
  :pointerToCBO(NULL), pointerToCBSF(pCBSF)
  {
  eventName = strdup(ename);
  }
  EventRecord::~EventRecord(void)
  {
  if(eventName) delete eventName;
  }
  void EventRecord::operator = (const EventRecord& er)
  {
  if(er.eventName)
  eventName = strdup(er.eventName);
  else
  eventName = NULL;
  pointerToCBO = er.pointerToCBO;
  pointerToCBF = er.pointerToCBF;
  }
  int EventRecord::operator == (char *ename) const
  {
  if((eventName == NULL)ename == NULL)
  return eventName == ename;
  else
  return strcmp(eventName,ename) == 0;
  
   }
  int EventRecord::operator == (const EventRecord& er) const
  {
  return (er == eventName) /*er he eventname bu neng jiao huan wei zhi */
  &&(pointerToCBO == er.pointerToCBO)
  &&(pointerToCBO ?
  (pointerToCBF == er.pointerToCBF):
  (pointerToCBSF == er.pointerToCBSF));
  }
  void EventRecord::Flush(void)
  {
  if(eventName){
  delete eventName;
  eventName = NULL;
  }
  pointerToCBO = NULL;
  pointerToCBF = NULL;
  }
  int EventRecord::IsEmpty(void) const
  {
  if(eventName == NULL)
  return 1;
  else
  return 0;
  }
  file://Callback lei de shi xian
  CallBack::CallBack(void)
  {
  file:// an chu shi chi cun wei hui tiao biao fen pei nei cun kong jian
  callBackList = new EventRecord[CALLBACKLIST_INIT_SIZE];
  if(!callBackList){
  cerr<<"CallBack: memory allocation error."<<endl;
  exit(1);
  }
  size = CALLBACKLIST_INIT_SIZE;
  lastpos = 0;
  curpos = 0;
  }
  CallBack::CallBack(const CallBack& cb): curpos(cb.curpos),lastpos(cb.lastpos),size(cb.size)
  {
  callBackList = new EventRecord[size];
  if(!callBackList){
  cerr<<"CallBack: memory allocation error."<<endl;
  exit(1);
  }
  file:// yi yi fu zhi ge tiao shi jian ji lu
  for(int i = 0; i < size; i++) callBackList[i] = cb.callBackList[i];
  }
  void CallBack::operator = (const CallBack& cb)
  {
  curpos = cb.curpos;
  lastpos = cb.lastpos;
  size = cb.size;
  delete [] callBackList;// shan chu jiu de hui tiao biao
  callBackList = new EventRecord[size];// chong xin fen pei nei cun kong jian
  if(!callBackList){
  cerr<<"CallBack: memory allocation error."<<endl;
  exit(1);
  }
  file:// yi yi fu zhi ge tiao shi jian ji lu
  for(int i = 0; i < size; i++) callBackList[i] = cb.callBackList[i];
  }
  CallBack::~CallBack(void)
  {
  delete [] callBackList;
  }
  void CallBack::AddCallBack(char *event, CallBackFunction pCBF, CallBack *pCBO)
  {
  file:// ru shi jian ming wei kong , tui chu
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  file:// xun zhao yin shan chu shi jian ji lu er chan sheng de di yi ge kong xian wei zhi , bing tian xie xin shi jian ji lu
  for(int start=0;start<lastpos;start++)
  if(callBackList[start].IsEmpty()){
  callBackList[start] = EventRecord(event,pCBO,pCBF);
  break;
  }
  if(start < lastpos) return; file:// que shi cun zai kong xian wei zhi
  file:// mei you kong xian wei zhi , zai hui tiao biao hou zhui jia xin ji lu
  if(lastpos == size) file:// hui tiao biao yi man , xu “ shen chang ”
  {
  EventRecord *tempList = callBackList;// zan cun jiu hui tiao biao zhi zhen
  file:// yi yi ding de bu chang “ shen chang ” hui tiao biao
  callBackList = new EventRecord[size + CALLBACKLIST_INCREMENT];
  if(!callBackList){
  cerr<<"CallBack: memory allocation error."<<endl;
  exit(1);
  }
  file:// fu zhi jiu hui tiao biao zhong de ji lu
  for(int i = 0; i < size; i++) callBackList[i] = tempList[i];
  delete [] tempList;// shan chu jiu hui tiao biao
  size += CALLBACKLIST_INCREMENT;// ji xia xin hui tiao biao de chi cun
  }
  file:// gou zao xin de shi jian ji lu bing jiang qi tian ru hui tiao biao zhong
  
   callBackList[lastpos] = EventRecord(event,pCBO,pCBF);
  lastpos++;
  }
  void CallBack::AddCallBack(char *event,CallBackStaticFunction pCBSF)
  {
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  for(int start=0;start<lastpos;start++)
  if(callBackList[start].IsEmpty()){
  callBackList[start] = EventRecord(event,pCBSF);
  break;
  }
  if(start < lastpos) return; file://a hole is found
  if(lastpos == size) file://event list is insufficient
  {
  EventRecord *tempList = callBackList;
  callBackList = new EventRecord[size + CALLBACKLIST_INCREMENT];
  if(!callBackList){
  cerr<<"CallBack: memory allocation error."<<endl;
  exit(1);
  }
  for(int i = 0; i < size; i++) callBackList[i] = tempList[i];
  delete [] tempList;
  size += CALLBACKLIST_INCREMENT;
  }
  callBackList[lastpos] = EventRecord(event,pCBSF);
  lastpos++;
  }
  file:// shan chu zhu ce zai zhi ding shi jian shang de cheng yuan han shu
  void CallBack::RemoveCallBack(char *event, CallBackFunction pCBF, CallBack *pCBO)
  {
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  EventRecord er(event,pCBO,pCBF);
  for(int i = 0; i < lastpos; i++)
  if(callBackList[i] == er) callBackList[i].Flush();
  }
  file:// shan chu zhu ce zai zhi ding shi jian shang de jing tai cheng yuan han shu huo pu tong han shu
  void CallBack::RemoveCallBack(char *event,CallBackStaticFunction pCBSF)
  {
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  EventRecord er(event,pCBSF);
  for(int i = 0; i < lastpos; i++)
  if(callBackList[i] == er) callBackList[i].Flush();
  }
  file:// shan chu zhu ce zai zhi ding shi jian shang de suo you hui tiao han shu
  void CallBack::RemoveCallBack(char *event)
  {
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  for(int i = 0; i < lastpos; i++)
  if(callBackList[i] == event) callBackList[i].Flush();
  }
  void CallBack::CallCallBack(char *event, CallData callData)
  {
  if( (event == NULL)?1:(strlen(event) == 0)) return;
  CallBack *pCBO;
  CallBackFunction pCBF;
  CallBackStaticFunction pCBSF;
  MoveFirst();
  while(!EndOfList())
  {
  file:// ru dang qian shi jian ji lu he zhi ding shi jian bu pi pei , zhuan ru xia yi tiao ji lu ji xu xun huan
  if(!(callBackList[curpos] == event))
  {
  MoveNext();
  continue;
  }
  file:// ru zhao dao pi pei ji lu
  pCBO = callBackList[curpos].pointerToCBO;
  file:// ru shi jian ji lu zhong hui tiao dui xiang zhi zhen wei kong , shuo ming gai ji lu zhong bao cun de shi jing tai han shu zhi zhen
  if(pCBO == NULL){
  pCBSF = callBackList[curpos].pointerToCBSF;
  pCBSF(callData);// tiao yong gai jing tai hui tiao han shu
  }
  else file:// ru shi jian ji lu zhong hui tiao dui xiang zhi zhen fei kong , shuo ming gai ji lu zhong bao cun de shi cheng yuan han shu zhi zhen
  {
  pCBF = callBackList[curpos].pointerToCBF;
  (pCBO->*pCBF)(callData);// tiao yong gai hui tiao dui xiang de cheng yuan han shu
  }
  MoveNext();
  }
  } geng duo nei rong qing kan C/C++ ji shu zhuan ti C/C++ jin jie ji shu wen dang xi tong an quan she zhi zhuan ti ,
  
   huo【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
   yong guo C++ jin xing guo mian xiang dui xiang cheng xu she ji de yong hu dou zhi dao , cheng xu zhong de dui xiang hen shao dan du cun zai 。 bu kao lv dui xiang jian de xiang hu zuo yong ji hu shi bu ke neng de 。 suo yi , biao shi dui xiang jian de guan xi huo jian li dui xiang jian de xiao xi lian jie shi mian xiang dui xiang cheng xu she ji de yi xiang chong yao ren wu 。 ben wen zhe chong cong C++ cheng xu she ji de jiao du , ti chu yi zhong jian li dui xiang jian xiao xi lian jie de shi yong fang fa 。 jia ru ni xiang ju ti le jie mian xiang dui xiang cheng xu she ji ji shu , qing shen yue you guan zhuan zhu 。    da jia dou zhi dao dui xiang shi shu ju he fang fa de feng zhuang ti 。 zai C++ zhong , ta men fen bie biao xian wei shu ju cheng yuan he cheng yuan han shu 。 cheng xu she ji zhe tong guo zhi xing dui xiang de ge zhong fang fa , lai gai bian dui xiang de zhuang tai ( ji gai bian dui xiang de shu xing shu ju )。 cong er shi gai dui xiang fa sheng mou xie “ shi jian ”。 dang yi dui xiang fa sheng mou shi jian shi , ta tong chang xu xiang qi ta xiang guan dui xiang fa song “ xiao xi ”, qing qiu ta men zuo chu yi xie chu li 。 zhe shi , fa sheng shi jian bing xiang qi ta dui xiang qing qiu chu li de dui xiang bei cheng wei “ shi jian dui xiang ”, er chu li shi jian de dui xiang bei cheng wei “ hui tiao dui xiang ”。 hui tiao dui xiang dui shi jian de chu li cheng wei “ hui tiao han shu ”。    zai C++ zhong , zhe yi guo cheng xiang dang yu : dang shi jian dui xiang fa sheng shi jian shi , tiao yong hui tiao dui xiang de mou xie cheng yuan han shu 。 tong chang de zuo fa shi hui tiao dui xiang xiang shi jian dui xiang chuan di dui xiang zhi zhen 。 dan zhe zhong fang fa bu tong yong 。 wei le jian shao cheng xu she ji de gong zuo liang , ben wen ti chu yi zhong jian li dui xiang jian xiao xi lian jie de xi tong fang fa 。 ta de si lu shi : jiang “ shi jian fa sheng → qing qiu chu li → zhi xing chu li ” zhe yi guo cheng chou xiang cheng yi ge “ hui tiao ”(CallBack) lei 。 tong guo ji xu , yong hu ke yi qing song huo qu jian li dui xiang jian xiao xi lian jie de ji zhi 。    yi 、 hui tiao lei de shu ju jie gou ji qi cheng yuan han shu    ben wen ti chu de CallBack lei zhi chi san zhong hui tiao han shu 。 ta men shi : hui tiao dui xiang zhong de cheng yuan han shu , shu yu hui tiao lei de jing tai cheng yuan han shu he pu tong de C han shu 。CallBackle lei zhong bao han yi hui tiao han shu biao callBackList。 ta yong yu ji lu shi jian ming cheng , zhi xiang hui tiao han shu ji hui tiao dui xiang de zhi zhen 。 gai biao de mei yi ge jie dian wei yi ge shi jian ji lu EventRecord。 mei ge shi jian ji lu bao han san ge yu : shi jian ming zhi zhen eventName, zhi xiang hui tiao dui xiang de zhi zhen pointerToCBO, zhi xiang hui tiao han shu de zhi zhen pointerToCBF huo pointerToCBSF( qi zhong ,pointerToCBF zhi xiang hui tiao dui xiang de cheng yuan han shu ,pointerToCBSF zhi xiang hui tiao lei de jing tai cheng yuan han shu huo pu tong han shu 。 ta men tong chu yu yi gong yong ti nei )。CallBack lei suo ti gong de hui tiao ji zhi shi zhe yang de : zai shi jian dui xiang shang zhu ce hui tiao dui xiang zhong de hui tiao han shu ; dang shi jian fa sheng shi , shi jian dui xiang zai qi hui tiao biao zhong jian suo bing zhi xing hui tiao han shu 。 cong er shi er zhe de xiao xi lian jie de yi jian li 。( guan yu gai lei de ju ti shi xian , qing shen yue wen hou suo fu de cheng xu qing dan ) hui tiao dui xiang    shi jian dui xiang    shi jian ming hui tiao dui xiang zhi zhen hui tiao han shu zhi zhen “event” pointerCBO pointerToCBF huo pointerTOCBSF - - - - - -    AddCallBack: zhu ce shi jian ming he zhi xiang hui tiao han shu , hui tiao dui xiang de zhi zhen    CallCallBack: zai hui tiao biao zhong , jian suo zhu ce zai zhi ding shi jian shang hui tiao han shu bing tiao yong ta men    shi jian fa sheng shi , tiao yong CallCallBack han shu    dui shi jian event jin xing chu li de cheng yuan han shu    cong CallBack lei ji xu de hui tiao biao callBackList, cheng yuan han shu AddCallBack he CallCallBack。    dang hui tiao han shu wei jing tai cheng yuan han shu huo pu tong C han shu shi , pointerToCBO wei NULL。    shi jian ming shi hui tiao biao callBackLis zhong de jian suo yao hai zi 。    hui tiao dui xiang zhong qi ta cheng yuan han shu    CallBack lei de cheng yuan han shu AddCallBack yong lai jiang hui tiao han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 ta you liang ge chong zai ban ben : void CallBack::AddCallBack(char *event,CallBackFunction cbf,CallBack *p); void CallBack::AddCallBack(char *event,CallBackStaticFunction cbsf);    qi zhong , di yi ge AddCallBack yong lai jiang mou hui tiao dui xiang de cheng yuan han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 di er ge AddCallBack yong lai jiang huo mou hui tiao lei de jing tai cheng yuan han shu zhu ce dao shi jian dui xiang de hui tiao biao zhong 。 zai shang shen shu biao zhong ,event shi zhi xiang shi jian ming zi fu chuan de zhi zhen ,p shi zhi xiang hui tiao dui xiang de zhi zhen ,cbf he cbsf fen bie shi zhi xiang cheng yuan han shu ji jing tai cheng yuan han shu ( huo pu tong han shu ) de zhi zhen 。 dang hui tiao han shu lai zi mou hui tiao dui xiang SomeObject shi , chuan di cheng yuan han shu zhi zhen ying cai yong ru xia ge shi : (CallBackFunction)&SomeObject::MemberFunctionName; chuan di SomeObject lei de mou jing tai cheng yuan han shu zhi zhen ying cai yong ge shi : (CallBackStaticFunction)& SomeObject::FunctionName; chuan di cheng xu zhong pu tong han shu zhi zhen shi , zhi xu chuan di han shu ming ji ke 。    CallBack lei de cheng yuan han shu void CallBack::CallCallBack(char *ename, CallData calldata = NULL) yong lai tiao yong zhu ce zai shi jian ename shang de suo you hui tiao han shu 。 qi zhong ,calldata wei shu ju zhi zhen (CallData shi ji shang jiu shi void*, xiang jian cheng xu qing dan )。 shi jian dui xiang ke tong guo ta xiang hui tiao dui xiang chuan di you yong de shu ju 。 gai cheng yuan han shu tong chang zai shi jian dui xiang de cheng yuan han shu zhong tiao yong , yin wei tong chang zhi you shi jian dui xiang de cheng yuan han shu cai neng gai bian dui xiang de nei bu shu ju , cong er shi mou xie shi jian fa sheng 。    cheng yuan han shu RemoveCallback yong lai shan chu zhu ce zai shi jian dui xiang shang de hui tiao han shu 。 ta de san ge chong zai ban ben yi ci wei : void CallBack::RemoveCallBack(char *event,CallBackFunction cbf,CallBack *p); void CallBack::RemoveCallBack(char *event,CallBackStaticFunction cbsf); void CallBack::RemoveCallBack(char *event);    qi zhong ,event,cbf,cbsf,p deng shen shu he cheng yuan han shu AddCallBack zhong ge shen shu yi yang 。 di yi ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang mou hui tiao dui xiang de yi ge cheng yuan han shu 。 di er ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang de mou pu tong han shu huo mou hui tiao lei de yi ge jing tai cheng yuan han shu 。 di san ge RemoveCallBack yong yu shan chu zhu ce zai shi jian event shang de quan bu hui tiao han shu 。    er 、CallBack lei de shi yong fang fa    shi yong CallBack lei , ke an yi xia bu zhou jin xing :    1. que ding cheng xu zhong na xie dui xiang jian cun zai guan xi , xu yao jian li xiao xi lian jie 。 bing que ding zai ge te ding xiao xi lian jie guan xi zhong , na ge dui xiang shi shi jian dui xiang , na ge dui xiang shi hui tiao dui xiang 。    2. shi jian dui xiang lei he hui tiao dui xiang lei dou bi xu cong CallBack lei ji xu , yi huo de hui tiao zhi chi 。    3. wei shi jian dui xiang zhu ce hui tiao shu ju 。 bao kuo : shi jian ming , hui tiao han shu ming , zhi xiang hui tiao dui xiang de zhi zhen 。    4. dang ni gan ai hao de shi jian fa sheng shi , zai shi jian dui xiang lei yin fa shi jian de cheng yuan han shu zhong tiao yong CallCallBack han shu 。    xia mian shi yi ge ju ti de li zi 。 tong guo ta ni hui dui Callback lei de shi yong fang fa you jin yi bu de le jie 。 file:// ce shi cheng xu wen jian :test.cpp #include"callback.h" file://“ yang sheng qi ” lei class Speaker:public CallBack {   private:    int volume;   public:    Speaker(int v): volume(v) {}    void IncreaseVolume(int v) file:// zeng jia yin liang cheng yuan han shu    {     volume += v;     if(volume >20){ file://“ yin liang da yu 20” shi jian fa sheng le      file:// tiao yong zhu ce zai liang shi jian shang de hui tiao han shu      CallCallBack(" yin liang gai bian le ");      CallCallBack(" yin liang da yu 20", &volume);     }    }   void DecreaseVolume(int v) file:// jiang di yin liang cheng yuan han shu   {    volume -= v;    if(volume < 5){ file://“ yin liang xiao yu 5” shi jian fa sheng le     file:// tiao yong zhu ce zai liang shi jian shang de hui tiao han shu     CallCallBack(" yin liang gai bian le ");     CallCallBack(" yin liang xiao yu 5", &volume);    }   } }; file://“ er duo ” lei class Ear : public CallBack {   public:    static void Response(CallData callData) file:// dui “ yin liang gai bian ” de fan ying    {     cout<<" yin liang gai bian le ."<   }    void HighVoiceResponse(CallData callData)// dui gao yin de fan ying    {     cout<<” wei ! tai chao le ! xian zai yin liang shi :"<<*((int *)callData)<   }    void LowVoiceResponse(CallData callData)// dui di yin de fan ying    {     cout<<" a ! wo ting bu qing le 。 xian zai yin liang shi :"<<*((int *)callData)<   } }; void main(void) {   Speaker s(10); file:// xian zai yin liang wei 10   Ear e;   file:// wei shi jian dui xiang s zhu ce hui tiao han shu   s.AddCallBack(" yin liang da yu 20”,(CallBackFunction)&Ear::HighVoiceResponse,&e);   s.AddCallBack(" yin liang xiao yu 5”,(CallBackFunction)&Ear::LowVoiceResponse,&e);   s.AddCallBack(" yin liang gai bian le ",(CallBackStaticFunction)&Ear::Response);   s.IncreaseVolume(12);// jiang yin liang zeng jia 12, xian zai yin liang wei 22   s.DecreaseVolume(20);// jiang yin liang jian shao 20, xian zai yin liang wei 2 }    yun xing jie guo :    yin liang gai bian le .    wei ! tai chao le ! xian zai yin liang shi :22    yin liang gai bian le .    a ! wo ting bu qing le 。 xian zai yin liang shi :2    zai shang li zhong , yang sheng qi dui xiang s wei shi jian dui xiang , er duo dui xiang e wei hui tiao dui xiang 。。s shang bei zhu ce le san ge shi jian :“ yin liang gai bian le ”,“ yin liang da yu 20”,“ yin liang xiao yu 5”。 hui tiao han shu fen bie wei :Ear::Response, Ear::HighVoiceResponse,Ear::LowVoiceResponse。 dang yang sheng qi s tong guo qi cheng yuan han shu IncreaseVolume he DecreaseVolume gai bian yin liang shi , hui tiao dui xiang e hui zi dong zuo chu fan ying 。 ke jian , tong guo shi yong CallBack lei , zai dui xiang jian jian li xiao xi lian jie yi bian wei yi xiang hen jian dan he mei li de gong zuo 。    you yu bi zhe shui ping you xian , gai lei de she ji bi you bu wan shan zhi chu 。 jia ru nin dui ta gan ai hao , bi zhe ke yu ge wei C++ wan jia gong tong tan tao zhe lei wen ti 。    lian xi fang shi :fei_xiang@263.net geng duo nei rong qing kan C/C++ ji shu zhuan ti C/C++ jin jie ji shu wen dang xi tong an quan she zhi zhuan ti , huo    fu : cheng xu qing dan ( ben cheng xu zai MS VC++5.0 he TC++3.0 shang yun bian yi tong guo ) file:// hui tiao lei de lei jie gou :callback.h #ifndef _CALLBACK_H #define _CALLBACK_H #include<stdlib.h> #include<string.h> #include<iostream.h> #define CALLBACKLIST_INIT_SIZE 10 #define CALLBACKLIST_INCREMENT 5 class CallBack; typedef void *CallData;// hui tiao shu ju zhi zhen lei xing ding yi typedef void (CallBack::*CallBackFunction)(CallData); file:// zhi xiang hui tiao cheng yuan han shu de zhi zhen typedef void (*CallBackStaticFunction)(CallData); file:// zhi xiang jing tai cheng yuan han shu huo pu tong han shu de zhi zhen lei xing ding yi class EventRecord{   private:    char *eventName; file:// hui tiao shi jian ming cheng    CallBack *pointerToCBO;// zhi xiang hui tiao dui xiang de zhi zhen    file:// zhi xiang cheng yuan han shu de zhi zhen he zhi xiang jing tai cheng yuan han shu ( huo pu tong han shu ) zhi zhen de gong yong ti    union{     CallBackFunction pointerToCBF;     CallBackStaticFunction pointerToCBSF;    };   public:    EventRecord(void); file:// shi jian ji lu lei de que sheng gou zao han shu    file:// gou zao bao han cheng yuan han shu de shi jian ji lu    EventRecord(char *ename,CallBack *pCBO,CallBackFunction pCBF);    file:// gou zao bao han jing tai cheng yuan han shu huo pu tong han shu de shi jian ji lu    EventRecord(char *ename,CallBackStaticFunction pCBSF);    ~EventRecord(void);// xi gou shi jian ji lu    void operator = (const EventRecord& er);// chong zai fu zhi yun suan fu    file:// pan ding dang qian shi jian ji lu de shi jian ming shi fou wei ename    int operator == (char *ename) const;    file:// pan ding dang qian shi jian ji lu shi fou he zhi ding shi jian ji lu xiang deng    int operator == (const EventRecord& er) const;    void Flush(void); file:// jiang dang qian shi jian ji lu qing kong    int IsEmpty(void) const;// pan ding shi jian ji lu shi fou wei kong ( ji shi jian ming shi fou wei kong )    friend class CallBack; file:// rang CallBack lei neng fang wen EventRecord de si you cheng yuan ; }; class CallBack {   private:    EventRecord *callBackList; file:// hui tiao shi jian biao    int curpos; file:// dang qian shi jian ji lu wei zhi    int lastpos; file:// hui tiao biao zhong zui hou yi kong xian wei zhi    int size; file:// hui tiao biao de da xiao    void MoveFirst(void) { curpos = 0; }// jiang dang qian ji lu zhi wei di yi tiao ji lu    void MoveNext(void) file:// jiang xia yi tiao ji lu zhi wei dang qian ji lu    {     if(curpos == lastpos) return;     curpos++;    }    file:// pan ding hui tiao biao shi fou bei bian li wan    int EndOfList(void) const { return curpos == lastpos; }     public:      CallBack(void);// gou zao han shu      CallBack(const CallBack& cb);// kao bei gou zao han shu      ~CallBack(void);// xi gou han shu    void operator = (const CallBack& cb);// chong zai fu zhi yun suan fu    file:// jiang hui tiao dui xiang de cheng yuan han shu 、 jing tai cheng yuan han shu ( huo pu tong han shu ) file:// zhu ce wei shi jian dui xiang de hui tiao han shu    void AddCallBack(char *event,CallBackFunction cbf,CallBack *p);    void AddCallBack(char *event,CallBackStaticFunction cbsf);    file:// shan chu zhu ce zai zhi ding shi jian shang de hui tiao han shu    void RemoveCallBack(char *event,CallBackFunction cbf,CallBack *p);    void RemoveCallBack(char *event,CallBackStaticFunction cbsf);    void RemoveCallBack(char *event);// shan chu mou shi jian de quan bu ji lu    file:// zhi xing zhu ce zai mou yi shi jian shang de suo you hui tiao han shu    void CallCallBack(char *event, CallData calldata = NULL);   };   #endif   file:// hui tiao lei de shi xian :callback.cpp   #include"callback.h"   file://EventRecord lei de shi xian   EventRecord::EventRecord(void)   {    eventName = NULL;    pointerToCBO = NULL;    file:// yin wei sizeof(CallBackFunction) > sizeof(CallBackStaticFunction)    pointerToCBF = NULL;   }   EventRecord::EventRecord(char *ename, CallBack *pCBO, CallBackFunction pCBF)   :pointerToCBO(pCBO), pointerToCBF(pCBF)   {    eventName = strdup(ename);   }   EventRecord::EventRecord(char *ename, CallBackStaticFunction pCBSF)   :pointerToCBO(NULL), pointerToCBSF(pCBSF)   {    eventName = strdup(ename);   }   EventRecord::~EventRecord(void)   {    if(eventName) delete eventName;   }   void EventRecord::operator = (const EventRecord& er)   {    if(er.eventName)     eventName = strdup(er.eventName);    else     eventName = NULL;     pointerToCBO = er.pointerToCBO;     pointerToCBF = er.pointerToCBF;   }   int EventRecord::operator == (char *ename) const   {    if((eventName == NULL)ename == NULL)     return eventName == ename;    else     return strcmp(eventName,ename) == 0;   }   int EventRecord::operator == (const EventRecord& er) const   {    return (er == eventName) /*er he eventname bu neng jiao huan wei zhi */      &&(pointerToCBO == er.pointerToCBO)      &&(pointerToCBO ?      (pointerToCBF == er.pointerToCBF):      (pointerToCBSF == er.pointerToCBSF));   }   void EventRecord::Flush(void)   {    if(eventName){     delete eventName;     eventName = NULL;    }    pointerToCBO = NULL;    pointerToCBF = NULL;   }   int EventRecord::IsEmpty(void) const   {    if(eventName == NULL)     return 1;    else     return 0;   }   file://Callback lei de shi xian   CallBack::CallBack(void)   {    file:// an chu shi chi cun wei hui tiao biao fen pei nei cun kong jian    callBackList = new EventRecord[CALLBACKLIST_INIT_SIZE];    if(!callBackList){     cerr<<"CallBack: memory allocation error."<<endl;     exit(1);    }    size = CALLBACKLIST_INIT_SIZE;    lastpos = 0;    curpos = 0;   }   CallBack::CallBack(const CallBack& cb): curpos(cb.curpos),lastpos(cb.lastpos),size(cb.size)   {    callBackList = new EventRecord[size];    if(!callBackList){     cerr<<"CallBack: memory allocation error."<<endl;     exit(1);    }    file:// yi yi fu zhi ge tiao shi jian ji lu    for(int i = 0; i < size; i++) callBackList[i] = cb.callBackList[i];   }   void CallBack::operator = (const CallBack& cb)   {    curpos = cb.curpos;    lastpos = cb.lastpos;    size = cb.size;    delete [] callBackList;// shan chu jiu de hui tiao biao    callBackList = new EventRecord[size];// chong xin fen pei nei cun kong jian    if(!callBackList){     cerr<<"CallBack: memory allocation error."<<endl;     exit(1);    }    file:// yi yi fu zhi ge tiao shi jian ji lu    for(int i = 0; i < size; i++) callBackList[i] = cb.callBackList[i];   }   CallBack::~CallBack(void)   {    delete [] callBackList;   }   void CallBack::AddCallBack(char *event, CallBackFunction pCBF, CallBack *pCBO)   {    file:// ru shi jian ming wei kong , tui chu    if( (event == NULL)?1:(strlen(event) == 0)) return;    file:// xun zhao yin shan chu shi jian ji lu er chan sheng de di yi ge kong xian wei zhi , bing tian xie xin shi jian ji lu    for(int start=0;start<lastpos;start++)     if(callBackList[start].IsEmpty()){      callBackList[start] = EventRecord(event,pCBO,pCBF);      break;     }     if(start < lastpos) return; file:// que shi cun zai kong xian wei zhi     file:// mei you kong xian wei zhi , zai hui tiao biao hou zhui jia xin ji lu     if(lastpos == size) file:// hui tiao biao yi man , xu “ shen chang ”     {      EventRecord *tempList = callBackList;// zan cun jiu hui tiao biao zhi zhen      file:// yi yi ding de bu chang “ shen chang ” hui tiao biao      callBackList = new EventRecord[size + CALLBACKLIST_INCREMENT];      if(!callBackList){       cerr<<"CallBack: memory allocation error."<<endl;       exit(1);      }      file:// fu zhi jiu hui tiao biao zhong de ji lu      for(int i = 0; i < size; i++) callBackList[i] = tempList[i];      delete [] tempList;// shan chu jiu hui tiao biao      size += CALLBACKLIST_INCREMENT;// ji xia xin hui tiao biao de chi cun     }     file:// gou zao xin de shi jian ji lu bing jiang qi tian ru hui tiao biao zhong     callBackList[lastpos] = EventRecord(event,pCBO,pCBF);     lastpos++;    }    void CallBack::AddCallBack(char *event,CallBackStaticFunction pCBSF)    {     if( (event == NULL)?1:(strlen(event) == 0)) return;     for(int start=0;start<lastpos;start++)      if(callBackList[start].IsEmpty()){       callBackList[start] = EventRecord(event,pCBSF);       break;      }     if(start < lastpos) return; file://a hole is found     if(lastpos == size) file://event list is insufficient     {      EventRecord *tempList = callBackList;      callBackList = new EventRecord[size + CALLBACKLIST_INCREMENT];      if(!callBackList){       cerr<<"CallBack: memory allocation error."<<endl;       exit(1);      }      for(int i = 0; i < size; i++) callBackList[i] = tempList[i];      delete [] tempList;      size += CALLBACKLIST_INCREMENT;     }    callBackList[lastpos] = EventRecord(event,pCBSF);    lastpos++;   }   file:// shan chu zhu ce zai zhi ding shi jian shang de cheng yuan han shu   void CallBack::RemoveCallBack(char *event, CallBackFunction pCBF, CallBack *pCBO)   {    if( (event == NULL)?1:(strlen(event) == 0)) return;    EventRecord er(event,pCBO,pCBF);    for(int i = 0; i < lastpos; i++)     if(callBackList[i] == er) callBackList[i].Flush();   }   file:// shan chu zhu ce zai zhi ding shi jian shang de jing tai cheng yuan han shu huo pu tong han shu   void CallBack::RemoveCallBack(char *event,CallBackStaticFunction pCBSF)   {    if( (event == NULL)?1:(strlen(event) == 0)) return;    EventRecord er(event,pCBSF);    for(int i = 0; i < lastpos; i++)     if(callBackList[i] == er) callBackList[i].Flush();   }   file:// shan chu zhu ce zai zhi ding shi jian shang de suo you hui tiao han shu   void CallBack::RemoveCallBack(char *event)   {    if( (event == NULL)?1:(strlen(event) == 0)) return;    for(int i = 0; i < lastpos; i++)     if(callBackList[i] == event) callBackList[i].Flush();   }   void CallBack::CallCallBack(char *event, CallData callData)   {    if( (event == NULL)?1:(strlen(event) == 0)) return;    CallBack *pCBO;    CallBackFunction pCBF;    CallBackStaticFunction pCBSF;    MoveFirst();    while(!EndOfList())    {     file:// ru dang qian shi jian ji lu he zhi ding shi jian bu pi pei , zhuan ru xia yi tiao ji lu ji xu xun huan     if(!(callBackList[curpos] == event))     {      MoveNext();      continue;     }     file:// ru zhao dao pi pei ji lu     pCBO = callBackList[curpos].pointerToCBO;     file:// ru shi jian ji lu zhong hui tiao dui xiang zhi zhen wei kong , shuo ming gai ji lu zhong bao cun de shi jing tai han shu zhi zhen     if(pCBO == NULL){      pCBSF = callBackList[curpos].pointerToCBSF;      pCBSF(callData);// tiao yong gai jing tai hui tiao han shu     }     else file:// ru shi jian ji lu zhong hui tiao dui xiang zhi zhen fei kong , shuo ming gai ji lu zhong bao cun de shi cheng yuan han shu zhi zhen     {      pCBF = callBackList[curpos].pointerToCBF;      (pCBO->*pCBF)(callData);// tiao yong gai hui tiao dui xiang de cheng yuan han shu     }     MoveNext();    }   } geng duo nei rong qing kan C/C++ ji shu zhuan ti C/C++ jin jie ji shu wen dang xi tong an quan she zhi zhuan ti , huo
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
赏心悦目的模特儿(9)
赏心悦目的模特儿(8)
赏心悦目的模特儿(7)
赏心悦目的模特儿(6)
周六一日游--绿野翠蜂场(一)
骆驼峰
下一站上环
杂乱的几张Danang
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有