锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产午夜精品久久久久九九,国产精品免费福利久久,婷婷五月深深久久精品http://www.shnenglu.com/zhuweisky/archive/2005/09/14/269.htmlzhuweiskyzhuweiskyWed, 14 Sep 2005 13:32:00 GMThttp://www.shnenglu.com/zhuweisky/archive/2005/09/14/269.htmlhttp://www.shnenglu.com/zhuweisky/comments/269.htmlhttp://www.shnenglu.com/zhuweisky/archive/2005/09/14/269.html#Feedback13http://www.shnenglu.com/zhuweisky/comments/commentRss/269.htmlhttp://www.shnenglu.com/zhuweisky/services/trackbacks/269.html闃呰鍏ㄦ枃

zhuweisky 2005-09-14 21:32 鍙戣〃璇勮
]]>
C++ 浜嬩歡鏈哄埗瀹炵幇http://www.shnenglu.com/zhuweisky/archive/2005/09/11/193.htmlzhuweiskyzhuweiskySun, 11 Sep 2005 12:15:00 GMThttp://www.shnenglu.com/zhuweisky/archive/2005/09/11/193.htmlhttp://www.shnenglu.com/zhuweisky/comments/193.htmlhttp://www.shnenglu.com/zhuweisky/archive/2005/09/11/193.html#Feedback5http://www.shnenglu.com/zhuweisky/comments/commentRss/193.htmlhttp://www.shnenglu.com/zhuweisky/services/trackbacks/193.html   浜嬩歡鏄潰鍚戠粍浠跺紑鍙戠殑蹇呰鐗規т箣涓錛屼絾C++涓嶇洿鎺ユ敮鎸佷簨浠訛紝娌″叧緋伙紝鎴戣嚜宸卞疄鐜頒簡涓涓紝鎰熻寰堝ソ鐢紝鍒嗕韓緇欏ぇ瀹訛紒
   鏈寮濮嬫墦綆楃敤鍑芥暟鎸囬拡妯℃嫙浜嬩歡錛屼絾鐢變簬C++涓垚鍛樺嚱鏁版寚閽堜笉鑳藉拰void*鐩鎬簰寮鴻漿錛岃屼笖 typedef涓笉鑳藉惈鏈夋ā鏉匡紝鎵浠ユ墠涓嶅緱宸蹭互鎺ュ彛緇ф壙瀹炵幇銆傝繖鏍鋒晥鏋滀篃涓嶉敊 錛氾級

涓. 鍏堢湅鐪嬩簨浠舵帴鍙e畾涔夊拰瀹炵幇
#ifndef IEVENT_H
#define IEVENT_H


/*
 浠ヤ笅鍚勫熀紜璁炬柦鏄湪C++涓簨浠舵満鍒剁殑瀹屾暣瀹炵幇錛屼簨浠舵槸闈㈠悜緇勪歡寮鍙戠殑蹇呰鐗規т箣涓銆?BR>  
 鍒?nbsp;浣?nbsp;鑰咃細sky
 鏃?nbsp;   闂達細2005.06.22 
 淇鏃墮棿錛?005.06.22
*/

#include 
"../Collection/SafeArrayList.h"
template
<class SenderType ,class ParaType> class EventPublisher ;

class
 NullType
{
};

// IEventHandler  鏄簨浠跺鐞嗗彞鏌勶紝棰勫畾浜嬩歡鐨勭被浠庢鎺ュ彛緇ф壙浠ュ疄鐜頒簨浠跺鐞嗗嚱鏁?/SPAN>

template<class SenderType ,class ParaType>
interface IEventHandler
{

public
:
 
virtual ~
IEventHandler(){}
private
:
 
virtual void HandleEvent(SenderType sender ,ParaType para)  = 0
 ;
 friend 
class EventPublisher<SenderType ,ParaType>
 ;
};

// IEvent 浜嬩歡棰勫畾鏂歸氳繃姝ゆ帴鍙i瀹氫簨浠?/SPAN>

template<class SenderType ,class ParaType>
interface IEvent
{
public
:

 
virtual ~
IEvent(){}
 
virtual void Register  (IEventHandler<SenderType ,ParaType>* handler) = 0
 ;  
 
virtual void UnRegister(IEventHandler<SenderType ,ParaType>* handler) = 0
 ;
};

// IEventActivator 浜嬩歡鍙戝竷鏂歸氳繃姝ゆ帴鍙hЕ鍙戜簨浠?/SPAN>

template<class SenderType ,class ParaType>
interface IEventActivator
{
public
:

 
virtual ~
IEventActivator(){}
 
virtual void Invoke(SenderType sender ,ParaType para) = 0
;
 
virtual int  HandlerCount() = 0
;
 
virtual IEventHandler<SenderType ,ParaType>* GetHandler(int index) = 0
;
};

//
 IEventPublisher 浜嬩歡鍙戝竷鏂瑰彂甯冧簨浠剁浉褰撲簬灝辨槸鍙戝竷涓涓狪EventPublisher媧劇敓綾葷殑瀵硅薄
// 涓嶈繃浠呬粎灝嗚瀵硅薄鐨処Event鎺ュ彛鍙戝竷鍗沖彲銆?/SPAN>

template<class SenderType ,class ParaType>
interface IEventPublisher : public IEvent<SenderType ,ParaType> ,public IEventActivator<SenderType ,ParaType> 
{
};

// EventPublisher鏄疘EventPublisher鐨勯粯璁ゅ疄鐜?/SPAN>

template<class SenderType ,class ParaType>
class EventPublisher :public IEventPublisher<SenderType ,ParaType>
{
private:
 SafeArrayList
< IEventHandler<SenderType ,ParaType> >
 handerList ;
 IEventHandler
<SenderType ,ParaType>*
 innerHandler ;

public
:
 
void Register(IEventHandler<SenderType ,ParaType>*
 handler) 
 {
  
this->
handerList.Add(handler) ;
 }

 
void UnRegister(IEventHandler<SenderType ,ParaType>*
 handler)
 {
  
this->
handerList.Remove(handler) ;
 }

 
void
 Invoke(SenderType sender ,ParaType para)
 {
  
int count = this->
handerList.Count() ;
  
for(int i=0 ;i<count ;i++
)
  {
   IEventHandler
<SenderType ,ParaType>* handler = this->
handerList.GetElement(i) ;
   handler
->
HandleEvent(sender ,para) ;
  }
 } 

 
int
  HandlerCount()
 {
  
return this->
handerList.Count() ;
 }

 IEventHandler
<SenderType ,ParaType>* GetHandler(int
 index)
 {
  
return this->
handerList.GetElement(index) ;
 }
};

#endif
    涓婇潰鐨勫疄鐜版槸嫻呮樉鏄撴噦鐨勶紝鍏抽敭鏄娉ㄦ剰IEventPublisher鐨勫弻閲嶈韓浠斤紞錛?浜嬩歡鍙戝竷鏂規渶濂藉彂甯僆Event鎸囬拡緇欏閮紝鑰岃鎸囬拡瀹為檯鎸囧悜鐨勬槸涓涓狤ventPublisher瀵硅薄錛岃繖鏄負浜嗛伩鍏嶅閮ㄧ洿鎺ヨ皟鐢↖EventActivator鎺ュ彛鐨勬柟娉曘?BR>
浜? 涓涓畾鏃跺櫒綾籘imer錛屾紨紺哄浣曞彂甯冧簨浠躲傛兂蹇呭ぇ瀹墮兘鐭ラ亾瀹氭椂鍣ㄧ殑鐢ㄩ斾簡鍝︼紝榪欎釜Timer灝卞儚C#涓殑Timer綾諱竴鏍楓?BR>
#ifndef TIMER_H
#define TIMER_H

/*
 Timer 瀹氭椂鍣?姣忕粡榪囦竴孌墊寚瀹氭椂闂村氨瑙﹀彂浜嬩歡
 
 鍒?nbsp;浣?nbsp;鑰咃細sky
 鏃?nbsp;   闂達細2005.06.22 
 淇鏃墮棿錛?005.06.22
*/
#include 
"IEvent.h"
#include 
"Thread.h"

void TimerThreadStart(void* para) ;

class
 Timer
{
private
:
 
int
 spanInMillSecs ;
 
volatile bool
 isStop ;
 
volatile bool
 timerThreadDone ;
 
public
:
 friend 
void TimerThreadStart(void*
 para) ;
 IEvent
<Timer* ,NullType>*
 TimerTicked ;

 Timer(
int
 span_InMillSecs) 
 {
  
this->isStop = true
 ;
  
this->timerThreadDone = true
 ;
  
this->spanInMillSecs =
 span_InMillSecs ;
  
this->TimerTicked = new EventPublisher<Timer* ,NullType>
 ;
 }
 
 
~
Timer()
 {
  
this->
Stop() ;
  delete 
this->
TimerTicked ;
 } 

 
void
 Start()
 {
  
if(! this->
isStop)
  {
   
return
 ;
  }

  
this->isStop = false
 ;
  Thread thread ;
  thread.Start(TimerThreadStart ,
this
) ;
  
//
unsigned int  dwThreadId ;
  
//HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0 , (unsigned int (_stdcall*)(void*))&TimerThreadStart , this, 0, &dwThreadId);   

  
 }

 
void
 Stop()
 {
  
ifthis->
isStop)
  {
   
return
 ;
  }
  
  
this->isStop = true
 ;

  
//絳夊緟宸ヤ綔綰跨▼閫鍑?/SPAN>

  while(! this->timerThreadDone)
  {
   Sleep(
200
) ;
  }
 }

private

 
void
 WorkerThread()
 {
  
this->timerThreadDone = false
 ;

  
while(! this->
isStop)
  {  
   Sleep(
this->
spanInMillSecs) ;

   
if(this->
isStop)
   {
    
break
 ;
   }
   
   NullType nullObj ;
   ((EventPublisher
<Timer* ,NullType>*)this->TimerTicked)->Invoke(this
 ,nullObj) ;
  }

  
this->timerThreadDone = true
 ;
 }
};

void TimerThreadStart(void*
 para)
{
    Timer
* timer = (Timer*
)para ;
    timer
->
WorkerThread() ;
}
#endif

    涓婇潰鐨勭ず渚嬫竻鏅板湴璇存槑浜嗗浣曞彂甯冧竴涓簨浠訛紝濡備綍鍦ㄩ傚綋鐨勬椂鍊欒Е鍙戜簨浠訛紝鎺ヤ笅鏉ョ湅鐪嬪浣曢瀹氫簨浠躲?BR>
涓? 棰勫畾浜嬩歡渚嬪瓙

class TimerEventExample  :public IEventHandler<Timer* ,NullType> ,CriticalSection
{
private
:
 Timer
*
 timer ;
 
public
:
 TimerEventExample(
int
 checkSpan) 
 {  
  
this->timer = new
 Timer(checkSpan) ;
  
this->timer->TimerTicked->Register(this
) ;
 }

 
~
TimerEventExample()
 {
  delete 
this->
timer ;
 } 

private
:
 
//澶勭悊瀹氭椂浜嬩歡

 void HandleEvent(Timer* sender ,NullType para)
 {
  cout
<<"Time ticked !"<<
endl ;
 }
};

    鍒拌繖閲岋紝宸茬粡灝咰++涓殑浜嬩歡鏈哄埗鐨勫疄鐜板強浣跨敤璁叉竻妤氫簡銆侰#鎻愪緵浜嗗緢澶氫究鍒╃殑鍩虹璁炬柦鏉ユ敮鎸佺粍浠跺紑鍙戯紝鑰屽湪C++涓紝榪欎簺鍩虹璁炬柦闇瑕佽嚜宸卞姩鎵嬫潵鏋勫緩錛屽湪鎷ユ湁浜嗚繖浜涜鏂戒箣鍚庯紝鐩鎬俊浣跨敤C++榪涜緇勪歡寮鍙戜細杞繪澗涓鐐廣?BR>



zhuweisky 2005-09-11 20:15 鍙戣〃璇勮
]]>
国产—久久香蕉国产线看观看 | 精品国产综合区久久久久久| 久久se精品一区二区| 久久青草国产精品一区| 久久久久婷婷| 久久久久久亚洲精品成人| 色综合久久综精品| 人人妻久久人人澡人人爽人人精品| 久久久精品国产免大香伊| 麻豆AV一区二区三区久久 | 亚洲?V乱码久久精品蜜桃| 久久久久亚洲精品无码蜜桃| 国产精品一区二区久久精品无码| 亚洲精品无码久久千人斩| 精品久久久无码中文字幕天天 | 久久久人妻精品无码一区 | 国产精品伦理久久久久久| 99久久综合国产精品免费| 情人伊人久久综合亚洲| 日产精品久久久一区二区| 久久久久国产一区二区| 国产成人无码精品久久久免费| 亚洲国产欧洲综合997久久| 伊人热热久久原色播放www| 狠狠精品久久久无码中文字幕| 国产精品久久影院| 麻豆一区二区99久久久久| 亚洲精品美女久久777777| 欧美精品九九99久久在观看| 国产免费久久精品99久久| 国内精品久久久久久野外| 久久久久人妻精品一区| 亚洲AV无码成人网站久久精品大| 一级a性色生活片久久无| 一本大道久久东京热无码AV| 久久中文字幕视频、最近更新| 伊人丁香狠狠色综合久久| 人人狠狠综合久久亚洲婷婷| 久久久91精品国产一区二区三区| 久久九九亚洲精品| 中文字幕一区二区三区久久网站|