锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产成人精品综合久久久,久久久久国产亚洲AV麻豆,久久精品国产亚洲77777http://www.shnenglu.com/kyee/articles/146913.htmlKyee YeKyee YeSun, 22 May 2011 04:00:00 GMThttp://www.shnenglu.com/kyee/articles/146913.htmlhttp://www.shnenglu.com/kyee/comments/146913.htmlhttp://www.shnenglu.com/kyee/articles/146913.html#Feedback0http://www.shnenglu.com/kyee/comments/commentRss/146913.htmlhttp://www.shnenglu.com/kyee/services/trackbacks/146913.html--------------------------------------------------------------------------------
鏍囬: B-tree鏌ユ壘鍑芥暟
浣滆? 鍙墮铏?br />鏃ユ湡: 2011.04.19
--------------------------------------------------------------------------------
鍦?B-tree 涓悳绱㈤敭鍊鹼紝緇撶偣鍐呭彲浠ヤ嬌鐢ㄤ簩鍒嗘煡鎵撅紝鑻ヨ鏌ユ壘鎸囧畾鑼冨洿鍐呮暟鎹笌鏌ユ壘閿?br />鐩告瘮鐩稿瑕佸鏉備竴鐐廣?/p>
鐜扮粰鍑烘煡鎵炬寚瀹氳寖鍥村唴絎竴欏瑰拰鏈鍚庝竴欏規(guī)暟鎹殑紺轟緥浠g爜錛?/p>
1 // B-tree 鐨勯」
2 typedef struct
3 {
4 long Key; // 閿?/span>
5 void* Link; // 瀛愮粨鐐規(guī)垨鏁版嵁
6 } TBTItem, *PBTItem;
7
8 // B-tree 鐨勭粨鐐?/span>
9 typedef struct
10 {
11 Byte Count; // 欏規(guī)暟[1..緇存暟]
12 bool IsLeaf; // 鏄惁涓哄彾瀛愮粨鐐?/span>
13 TBTItem Items[100]; // 欏瑰垪琛?鍋囪 B-tree 緇村害涓?nbsp;100)
14 } TBTNode, *PBTNode;
15
16 // 鏌ユ壘鑼冨洿鍐呯殑絎竴欏瑰茍榪斿洖搴忓彿(娉? AFrom < ATo)
17 TBTNode* FindFirstItem(TBTNode* ARoot, long AFrom, long ATo,
18 bool AIsInc, long& AIndex)
19 {
20 // 鍒濆鍖?/span>
21 bool boolRet = false;
22 TBTNode* pNode = ARoot;
23 TBTNode* pNext = NULL;
24 long intNext = 0;
25 long intBegin, intEnd, intMid, intKey;
26
27 // 寰幆鏌ユ壘灞?/span>
28 while (pNode != NULL)
29 {
30 // 鍒濆鍖?娉? pNode->Count >= 1)
31 intEnd = pNode->Count - 1;
32 intBegin = 0;
33
34 // 緇撶偣鍐呬簩鍒嗘煡鎵?/span>
35 while (intBegin <= intEnd)
36 {
37 intMid = (intBegin + intEnd) >> 1;
38 intKey = pNode->Items[intMid].Key;
39 if (intKey < AFrom)
40 intBegin = intMid + 1;
41 else
42 {
43 intEnd = intMid - 1;
44 if (intKey == AFrom)
45 {
46 intBegin = intMid;
47 break;
48 }
49 }
50 }
51
52 // 鍒ゆ柇鏄惁涓哄彾緇撶偣
53 AIndex = intBegin;
54 if (pNode->IsLeaf)
55 {
56 if (intKey != AFrom)
57 {
58 if (AIndex != pNode->Count)
59 {
60 boolRet = (pNode->Items[AIndex].Key <= ATo);
61 break;
62 }
63 }
64 else if (AIsInc)
65 {
66 boolRet = true;
67 break;
68 }
69 else if (AIndex < pNode->Count - 1)
70 {
71 AIndex++;
72 boolRet = (pNode->Items[AIndex].Key <= ATo);
73 break;
74 }
75
76 // 涓嬩竴緇撶偣欏?/span>
77 if (pNext == NULL)
78 break;
79 else
80 {
81 pNode = (TBTNode*)pNext->Item[intNext].Link;
82 pNext = NULL;
83 }
84 }
85 else
86 {
87 // 鏍℃绱㈠紩
88 if (AIndex == pNode->Count)
89 AIndex = pNode->Count - 1;
90 else if (intKey == AFrom)
91 {
92 if (AIndex < pNode->Count - 1)
93 {
94 intNext = AIndex + 1;
95 pNext = (pNode->Items[intNext].Key <= To) ? pNode : NULL;
96 }
97 }
98 else if (AIndex == 0)
99 pNext = NULL;
100 else
101 {
102 intNext = AIndex--;
103 pNext = (pNode->Items[intNext].Key <= To) ? pNode : NULL;
104 }
105
106 // 瀛愮粨鐐?/span>
107 pNode = (TBTNode*)pNode->Item[AIndex].Link;
108 }
109 }
110
111 // 榪斿洖緇撴灉
112 return boolRet ? pNode : NULL;
113 }
114
115 // 鏌ユ壘鑼冨洿鍐呯殑鏈鍚庝竴欏瑰茍榪斿洖搴忓彿(娉? AFrom < ATo)
116 TBTNode* FindLastItem(TBTNode* ARoot, long AFrom, long ATo,
117 bool AIsInc, long& AIndex)
118 {
119 // 鍒濆鍖?/span>
120 bool boolRet = false;
121 TBTNode* pNode = ARoot;
122 long intBegin, intEnd, intMid, intKey;
123
124 // 寰幆鏌ユ壘灞?/span>
125 while (pNode != NULL)
126 {
127 // 鍒濆鍖?娉? pNode->Count >= 1)
128 intEnd = pNode->Count - 1;
129 intBegin = 0;
130
131 // 緇撶偣鍐呬簩鍒嗘煡鎵?/span>
132 while (intBegin <= intEnd)
133 {
134 intMid = (intBegin + intEnd) >> 1;
135 intKey = pNode->Items[intMid].Key;
136 if (intKey < ATo)
137 intBegin = intMid + 1;
138 else
139 {
140 intEnd = intMid - 1;
141 if (intKey == ATo)
142 {
143 intBegin = intMid;
144 break;
145 }
146 }
147 }
148
149 // 鍒ゆ柇鏄惁涓哄彾緇撶偣
150 AIndex = intBegin;
151 if (pNode->IsLeaf)
152 {
153 if ((intKey == ATo) && AIsInc)
154 boolRet = true;
155 else if (AIndex > 0)
156 {
157 AIndex--;
158 boolRet = (pNode->Items[AIndex].Key >= AFrom);
159 }
160
161 break;
162 }
163 else
164 {
165 // 鏍℃绱㈠紩
166 if ((intKey == ATo) && AIsInc)
167 ;
168 else if (AIndex > 0)
169 AIndex--;
170 else
171 break;
172
173 // 瀛愮粨鐐?/span>
174 pNode = (TBTNode*)pNode->Item[AIndex].Link;
175 }
176 }
177
178 // 榪斿洖緇撴灉
179 return boolRet ? pNode : NULL;
180 }
181

]]>- 涓璇諱竴鍐欐儏鍐典笅錛屾棤閿佺幆褰㈤槦鍒楀浣曞疄鐜幫紵http://www.shnenglu.com/kyee/articles/146912.htmlKyee YeKyee YeSun, 22 May 2011 03:35:00 GMThttp://www.shnenglu.com/kyee/articles/146912.htmlhttp://www.shnenglu.com/kyee/comments/146912.htmlhttp://www.shnenglu.com/kyee/articles/146912.html#Feedback0http://www.shnenglu.com/kyee/comments/commentRss/146912.htmlhttp://www.shnenglu.com/kyee/services/trackbacks/146912.html--------------------------------------------------------------------------------
鏍囬: 涓璇諱竴鍐欐儏鍐典笅錛屾棤閿佺幆褰㈤槦鍒楀浣曞疄鐜幫紵
浣滆? 鍙墮铏?br />鏃ユ湡: 2009.03.09
--------------------------------------------------------------------------------
鏃犻攣鐜艦闃熷垪鐨勮璁″強紺轟緥錛岃鍐欓槦鍒楁渶澶х殑搴旂敤鏄細(xì)涓涓嚎紼嬫敹鍒頒簨浠舵垨娑堟伅鍚庣洿鎺?br />鍔犲叆鍒伴槦鍒楋紝鑰屽鐞嗙嚎紼嬭鍙栭槦鍒椾腑鐨勪簨浠舵垨娑堟伅錛屽茍鍔犱互澶勭悊銆傚湪榪欎釜妯″紡涓紝鏈変竴涓嚎
紼嬭礋璐e啓錛屽涓鐞嗙嚎紼嬭鑷繁鐨勯槦鍒楀茍澶勭悊銆傝櫧鐒剁湅璧鋒潵璞℃槸涓鍐欏璇伙紝鍏跺疄涓嶇劧錛岄拡瀵?br />鏌愪竴浜嬩歡闃熷垪鑰岃█錛屽彧鏈変竴涓嚎紼嬫槸鍐欎竴涓嚎紼嬫槸璇匯?/p>
鐜艦涓璇諱竴鍐欓槦鍒椾腑錛屼笉闇瑕佹媴蹇僽nsigned long婧㈠嚭闂錛屽洜涓烘孩鍑哄悗鑷姩鍥炲綊錛岀浉鍑?br />鍊艱繕浼?xì)淇濈暀銆?/p>
1 紺轟緥涓(娉細(xì)Max_Count 蹇呴』涓?nbsp;2 鐨勬寚鏁幫紝鍗籌細(xì)2, 4, 8, 16
)錛?br /> 2
3 // 闃熷垪灝哄
4 #define Max_Count 4096
5 #define Max_Mask 4095 // = Max_Count - 1
6
7 // 鍙橀噺
8 void* List[Max_Count];
9 unsigned long Push_Count;
10 unsigned long Pop_Count;
11
12 // 鍒濆鍖栭槦鍒?/span>
13 void InitQueue()
14 {
15 Push_Count = 0;
16 Pop_Count = 0;
17 memset(List, 0, sizeof(List));
18 }
19
20 // 鍔犲叆
21 bool Push(void* AData)
22 {
23 if (Push_Count - Pop_Count < Max_Count)
24 {
25 List[Push_Count & Max_Mask] = AData;
26 Push_Count++;
27 return true;
28 }
29 else
30 return false;
31 }
32
33 // 鍙栧嚭
34 void* Pop()
35 {
36 // 鍒濆鍖?/span>
37 void* result = NULL;
38
39 // 鍒ゆ柇鏄惁涓虹┖
40 if (Push_Count != Pop_Count)
41 {
42 result = List[Pop_Count & Max_Mask];
43 Pop_Count++;
44 }
45
46 // 榪斿洖緇撴灉
47 return result;
48 }
49
50 紺轟緥浜?娉細(xì)Max_Count >= 2)錛?br /> 51
52 // 闃熷垪灝哄
53 #define Max_Count 4096
54 #define High_Index 4095 // = Max_Count - 1
55
56 // 鍙橀噺
57 void* List[Max_Count];
58 unsigned long Push_Count;
59 unsigned long Push_Index;
60 unsigned long Pop_Count;
61 unsigned long Pop_Index;
62
63 // 鍒濆鍖栭槦鍒?/span>
64 void InitQueue()
65 {
66 Push_Count = 0;
67 Push_Index = 0;
68 Pop_Count = 0;
69 Pop_Index = 0;
70 memset(List, 0, sizeof(List));
71 }
72
73 // 鍔犲叆
74 bool Push(void* AData)
75 {
76 if (Push_Count - Pop_Count < Max_Count)
77 {
78 List[Push_Index] = AData;
79 Push_Count++;
80 if (Push_Index == High_Index)
81 Push_Index = 0;
82 else
83 Push_Index++;
84
85 return true;
86 }
87 else
88 return false;
89 }
90
91 // 鍙栧嚭
92 void* Pop()
93 {
94 // 鍒濆鍖?/span>
95 void* result = NULL;
96
97 // 鍒ゆ柇鏄惁涓虹┖
98 if (Push_Count != Pop_Count)
99 {
100 result = List[Pop_Index];
101 Pop_Count++;
102 if (Pop_Index == High_Index)
103 Pop_Index = 0;
104 else
105 Pop_Index++;
106 }
107
108 // 榪斿洖緇撴灉
109 return result;
110 }
111

]]> - 涓璇諱竴鍐欐儏鍐典笅錛屾棤閿侀槦鍒楀浣曞疄鐜幫紵http://www.shnenglu.com/kyee/articles/146911.htmlKyee YeKyee YeSun, 22 May 2011 03:31:00 GMThttp://www.shnenglu.com/kyee/articles/146911.htmlhttp://www.shnenglu.com/kyee/comments/146911.htmlhttp://www.shnenglu.com/kyee/articles/146911.html#Feedback0http://www.shnenglu.com/kyee/comments/commentRss/146911.htmlhttp://www.shnenglu.com/kyee/services/trackbacks/146911.html--------------------------------------------------------------------------------
鏍囬: 涓璇諱竴鍐欐儏鍐典笅錛屾棤閿侀槦鍒楀浣曞疄鐜幫紵
浣滆? 鍙墮铏?br />鏃ユ湡: 2009.03.09
--------------------------------------------------------------------------------
涓璇諱竴鍐欐儏鍐典笅錛屾棤閿侀槦鍒楀浣曞疄鐜幫紵鍏跺疄騫朵笉闅撅紝鍏堣璇翠竴璇諱竴鍐欐棤閿侀槦鍒楃殑瀹為檯搴?br />鐢ㄥ惂銆傝鍐欓槦鍒楁渶澶х殑搴旂敤鏄細(xì)涓涓嚎紼嬫敹鍒頒簨浠舵垨娑堟伅鍚庣洿鎺ュ姞鍏ュ埌闃熷垪錛岃屽鐞嗙嚎紼嬭
鍙栭槦鍒椾腑鐨勪簨浠舵垨娑堟伅錛屽茍鍔犱互澶勭悊銆傚湪榪欎釜妯″紡涓紝鏈変竴涓嚎紼嬭礋璐e啓錛屽涓鐞嗙嚎紼嬭
鑷繁鐨勯槦鍒楀茍澶勭悊銆傝櫧鐒剁湅璧鋒潵璞℃槸涓鍐欏璇伙紝鍏跺疄涓嶇劧錛岄拡瀵規(guī)煇涓浜嬩歡闃熷垪鑰岃█錛屽彧鏈変竴
涓嚎紼嬫槸鍐欎竴涓嚎紼嬫槸璇匯?/p>
姝ょず渚嬪彲浠ュ皝瑁呮垚涓涓猀ueue綾伙紝鍦↘YLib涓湁TKYQueue綾伙紝鍏跺疄鐜板師鐞嗙浉鍚屻備唬鐮佺ず渚?br />濡備笅錛?/p>
1 // 閾炬帴鏁版嵁欏圭粨鏋?/span>
2 typedef struct TLinkItem
3 {
4 void* Data;
5 TLinkItem* Next;
6 } *PLinkItem;
7
8 TLinkItem* FLinkHead; // 闃熷垪澶?/span>
9 TLinkItem* FLinkTail; // 闃熷垪灝?br />10
11 // 鍒濆鍖栭槦鍒?/span>
12 void InitQueue()
13 {
14 // 鍒嗛厤闃熷垪澶撮」
15 FLinkTail = NULL;
16 FLinkHead = new TLinkItem;
17
18 // 淇濊瘉 Head 鍜?nbsp;Tail 闈炵┖, 鏄竴涓嚎紼嬭涓涓嚎紼嬪啓鐨勫叧閿?
19 if (FLinkHead != NULL)
20 {
21 // 鍒濆鍖栭槦鍒楀ご
22 FLinkHead->Data = NULL;
23 FLinkHead->Next = NULL;
24 FLinkTail = FLinkHead;
25 }
26 else
27 throw;
28 }
29
30 // 鍔犲叆
31 bool Push(void* AData)
32 {
33 // 鍒濆鍖?/span>
34 bool result = false;
35 TLinkItem* pItem = new TLinkItem;
36
37 // 鍔犲叆闃熷垪
38 if (pItem != NULL)
39 {
40 // 鍐欏?/span>
41 pItem->Data = AData;
42 pItem->Next = NULL;
43
44 // 鍔犲埌鏈熬
45 FLinkTail->Next = pItem;
46 FLinkTail = pItem;
47
48 // 榪斿洖緇撴灉
49 result = true;
50 }
51
52 // 榪斿洖緇撴灉
53 return result;
54 }
55
56 // 鍙栧嚭
57 void* Pop()
58 {
59 // 鍒濆鍖?/span>
60 void* result = NULL;
61
62 // 璇誨彇欏?/span>
63 if (FLinkHead->Next != NULL)
64 {
65 // 鍙栧?/span>
66 TLinkItem* pItem = FLinkHead;
67 FLinkHead = FLinkHead->Next;
68 result = FLinkHead->Data;
69
70 // 閲婃斁欏?/span>
71 delete pItem;
72 }
73
74 // 榪斿洖緇撴灉
75 return result;
76 }
77

]]> - 闃熷垪鍜屼簨浠剁殑閰嶅悎浣跨敤紺轟緥http://www.shnenglu.com/kyee/articles/146906.htmlKyee YeKyee YeSun, 22 May 2011 03:08:00 GMThttp://www.shnenglu.com/kyee/articles/146906.htmlhttp://www.shnenglu.com/kyee/comments/146906.htmlhttp://www.shnenglu.com/kyee/articles/146906.html#Feedback0http://www.shnenglu.com/kyee/comments/commentRss/146906.htmlhttp://www.shnenglu.com/kyee/services/trackbacks/146906.html--------------------------------------------------------------------------------
鏍囬: 闃熷垪鍜屼簨浠剁殑閰嶅悎浣跨敤紺轟緥
浣滆? 鍙墮铏?br />鏃ユ湡: 2009.09.09
--------------------------------------------------------------------------------
涓涓嚎紼嬫敹鍒頒簨浠舵垨娑堟伅鍚庣洿鎺ュ姞鍏ュ埌闃熷垪錛岃屽鐞嗙嚎紼嬭鍙栭槦鍒椾腑鐨勪簨浠舵垨娑堟伅錛屽茍
鍔犱互澶勭悊銆傚湪榪欎釜妯″紡涓紝鏈変竴涓嚎紼嬭礋璐e啓錛屽涓鐞嗙嚎紼嬭鑷繁鐨勯槦鍒楀茍澶勭悊銆傝櫧鐒剁湅
璧鋒潵璞℃槸涓鍐欏璇伙紝鍏跺疄涓嶇劧錛岄拡瀵規(guī)煇涓浜嬩歡闃熷垪鑰岃█錛屽彧鏈変竴涓嚎紼嬫槸鍐欎竴涓嚎紼嬫槸璇匯?/p>
闃熷垪鍜屼簨浠剁殑閰嶅悎浣跨敤紺轟緥濡備笅錛?/p>
1 /* 鏂規(guī)硶涓: 鐙珛綰跨▼澶勭悊闃熷垪 */
2
3 // 綰跨▼鎵ц浣?/span>
4 void TDealThread::Execute()
5 {
6 // 鍒濆鍖?/span>
7 Longword dwNo;
8 Longword dwCount;
9 TItem* pItem;
10
11 // 綰跨▼寰幆浣?/span>
12 while (!Terminated())
13 {
14 // 絳夊緟浜嬩歡
15 FEvent->Wait(INFINITE);
16
17 // 寰幆澶勭悊浜嬩歡欏?/span>
18 dwCount = FQueue->Count();
19 for (dwNo = 0; !Terminated() && (dwNo < dwCount); dwNo++)
20 {
21 pItem = (TItem*)FQueue->Pop();
22 if (pItem != NULL)
23 {
24 // 澶勭悊浜嬩歡欏?br /> 25 // ???

26
27 // 閲婃斁欏?/span>
28 delete pItem;
29 }
30 }
31 }
32 }
33
34 // 娣誨姞浜嬩歡
35 bool TDealThread::AddEvent(const TItem& AItem)
36 {
37 // 鍒濆鍖?/span>
38 bool result = false;
39
40 // 鍒ゆ柇綰跨▼鏄惁鏈粓姝?/span>
41 if (!Terminated())
42 {
43 // 鍒濆鍖?/span>
44 TItem* pItem;
45
46 // 鏂板緩欏?/span>
47 pItem = new TItem;
48 *pItem = AItem;
49
50 // 鍔犲叆闃熷垪
51 if (FQueue->Push(pItem))
52 {
53 // 浜嬩歡緗綅
54 FEvent->Set();
55 result = true;
56 }
57 else
58 delete pItem;
59 }
60
61 // 榪斿洖緇撴灉
62 return result;
63 }
64
65 // 鍏抽棴綰跨▼
66 void TDealThread::Close()
67 {
68 // 緗粓姝㈡爣蹇?/span>
69 Terminate();
70 FEvent->Set();
71
72 // 鍞ら啋浼戠湢綰跨▼
73 if (!Finished() && Suspended())
74 Resume();
75 }
76
77 /* 鏂規(guī)硶浜? 澶栭儴綰跨▼澶勭悊 */
78
79 // 澶栭儴綰跨▼鍙栦簨浠?/span>
80 bool TOwnerObj::GetEvent(TItem& AItem, Longword ATimeout)
81 {
82 // 鍏堝彇闃熷垪欏?/span>
83 bool result = GetItem(AItem);
84
85 // 鍒ゆ柇鏄惁闇瑕佺瓑寰?/span>
86 if (!result && (ATimeout != 0))
87 {
88 // 鍒濆鍖?/span>
89 Longword dwBegin = GetTickCount();
90
91 // 寰幆絳夊緟浜嬩歡
92 while (GetTickCount() - dwBegin < ATimeout)
93 {
94 // 闃叉鍏跺畠澶氱嚎紼嬭鍙栨椂淇″彿鍙栦笉鍒? 50 姣絳夊緟
95 FEvent->Wait(50);
96
97 // 鍙栭槦鍒楅」
98 if (GetItem(AItem))
99 {
100 result = true;
101 break;
102 }
103 }
104 }
105
106 // 榪斿洖緇撴灉
107 return result;
108 }
109
110 // 娣誨姞浜嬩歡
111 bool TOwnerObj::AddEvent(const TItem& AItem)
112 {
113 // 鍒濆鍖?/span>
114 bool result = false;
115 TItem* pItem;
116
117 // 鏂板緩欏?/span>
118 pItem = new TItem;
119 *pItem = AItem;
120
121 // 鍔犲叆闃熷垪
122 if (FQueue->Push(pItem))
123 {
124 // 浜嬩歡緗綅
125 FEvent->Set();
126 result = true;
127 }
128 else
129 delete pItem;
130
131 // 榪斿洖緇撴灉
132 return result;
133 }
134
135 // 鍙栭槦鍒楅」
136 bool TOwnerObj::GetItem(TItem& AItem)
137 {
138 // 鍒濆鍖?/span>
139 TItem* pItem;
140 bool result = false;
141
142 // 鍒ゆ柇闃熷垪鏄惁闈炵┖
143 while (FQueue->Count() != 0)
144 {
145 pItem = (TItem*)FQueue->Pop();
146 if (pItem != NULL)
147 {
148 AItem = *pItem;
149 result = true;
150
151 // 閲婃斁欏?/span>
152 delete pItem;
153 break;
154 }
155 }
156
157 // 榪斿洖緇撴灉
158 return result;
159 }
160

]]> - 濡備綍浣跨敤綾葷殑鎴愬憳鏂規(guī)硶鎸囬拡錛?/title>http://www.shnenglu.com/kyee/articles/146905.htmlKyee YeKyee YeSun, 22 May 2011 03:01:00 GMThttp://www.shnenglu.com/kyee/articles/146905.htmlhttp://www.shnenglu.com/kyee/comments/146905.htmlhttp://www.shnenglu.com/kyee/articles/146905.html#Feedback0http://www.shnenglu.com/kyee/comments/commentRss/146905.htmlhttp://www.shnenglu.com/kyee/services/trackbacks/146905.html--------------------------------------------------------------------------------
鏍囬: 濡備綍浣跨敤綾葷殑鎴愬憳鏂規(guī)硶鎸囬拡錛?br />浣滆? 鍙墮铏?br />鏃ユ湡: 2009.03.22
--------------------------------------------------------------------------------
鍏跺疄錛岀被鏂規(guī)硶璋冪敤鍘熺悊寰堢畝鍗曪紝鑻ョ煡閬撳浣曚嬌鐢–璇█妯℃嫙綾誨疄鐜板氨鐭ラ亾鎬庝箞鍥炰簨浜嗭紝鍙?br />鏄繖涓伐浣滅敱緙栬瘧鍣ㄦ潵鍋氱艦浜嗐傝皟鐢ㄦ柟娉曚笌璋冪敤鍑芥暟鐨勫尯鍒槸鍦ㄨ皟鐢ㄦ柟娉曟椂錛岀紪璇戝櫒鎶婂綋鍓?br />瀵硅薄鐨勬寚閽堝綋鍋氱涓涓弬鏁頒紶鍏ワ紝鍏跺畠鍙傛暟鐨勪紶閫掍笌鍑芥暟娌℃湁鍖哄埆錛屼篃灝辮錛岃繖涓烘彁渚涘洖璋?br />浜嬩歡鐨勬柟娉曟寚閽堟彁渚涗竴鏉℃柟渚夸箣闂ㄣ傛柟娉曟寚閽堜笉鑳芥互鐢紝鐢ㄥソ瀹冨彲浠ヤ嬌浣犵殑瑙嗛噹鏇村姞寮闃旓紒
1 /* TObject - 鍩虹被 */
2
3 class TObject
4 {
5 };
6
7
8 /* TDemoA - A 綾?nbsp;*/
9
10 class TDemoA
11 {
12 public:
13 TDemoA();
14 virtual ~TDemoA();
15
16 void AF1(void* AParam);
17 void AF2(const char* AStr, long AValue);
18
19 // ???

20 };
21
22 /* TDemoB - B 綾?nbsp;*/
23
24 class TDemoB
25 {
26 public:
27 TDemoB();
28 virtual ~TDemoB();
29
30 void BF1(void* AParam);
31 void BF2(const char* AStr, long AValue);
32
33 // ???

34 };
35
36 /* TDemoC - C 綾?nbsp;*/
37
38 class TDemoC
39 {
40 public:
41 // TOnFunc1 浜嬩歡綾誨瀷
42 typedef void (TObject::*TDoFunc1)(void* AParam);
43 typedef struct
44 {
45 TDoFunc1 Method;
46 void* Object;
47 } TOnFunc1;
48
49 // TOnFunc2 浜嬩歡綾誨瀷
50 typedef void (TObject::*TDoFunc2)(const char* AStr, long AValue);
51 typedef struct
52 {
53 TDoFunc2 Method;
54 void* Object;
55 } TOnFunc2;
56
57 public:
58 TDemoC();
59 virtual ~TDemoC();
60
61 // Func1
62 void Func1(void* AParam)
63 {
64 if (OnFunc1.Method != NULL)
65 ((TObject*)OnFunc1.Object->*OnFunc1.Method)(AParam);
66 }
67
68 // Func2
69 void Func2(const char* AStr, long AValue)
70 {
71 if (OnFunc2.Method != NULL)
72 ((TObject*)OnFunc2.Object->*OnFunc2.Method)(AStr, AValue);
73 }
74
75 // 浜嬩歡
76 TOnFunc1 OnFunc1;
77 TOnFunc1 OnFunc2;
78 };
79
80
81 // 渚嬪瓙
82 TDemoA A;
83 TDemoB B;
84 TDemoC C;
85
86 int demo()
87 {
88 // ???

89
90 C.OnFunc1.Object = &B;
91 C.OnFunc1.Method = (TDemoC::TDoFunc1)&TDemoB::BF1;
92
93 C.OnFunc2.Object = &A;
94 C.OnFunc2.Method = (TDemoC::TDoFunc2)&TDemoA::AF2;
95
96 // 璋冪敤 C 鏂規(guī)硶
97 C.Func1(
); // <=> B.BF1(
);
98 C.Func2(
); // <=> A.AF2(
);
99
100 // ???

101
102 C.OnFunc1.Object = &A;
103 C.OnFunc1.Method = (TDemoC::TDoFunc1)&TDemoA::AF1;
104
105 C.OnFunc2.Object = &B;
106 C.OnFunc2.Method = (TDemoC::TDoFunc2)&TDemoB::BF2;
107
108 // 璋冪敤 C 鏂規(guī)硶
109 C.Func1(
); // <=> A.AF1(
);
110 C.Func2(
); // <=> B.BF2(
);
111
112 // ???

113
114 }
115
116 /* TKYFmtMemEvent - 鏍煎紡鍖栧唴瀛橀」浜嬩歡綾?nbsp;*/
117
118 class TKYFmtMemEvent
119 {
120 public:
121 // TOnFormat 浜嬩歡綾誨瀷
122 typedef void (TObject::*TDoFormat)(void* AItem, Word ASize);
123 typedef struct
124 {
125 TDoFormat Method;
126 void* Object;
127 } TOnFormat;
128
129 public:
130 TKYFmtMemEvent() { Clear(); }
131 ~TKYFmtMemEvent() { Clear(); }
132
133 // 娓呴櫎
134 void Clear();
135
136 // 鎵ц OnInitialize 浜嬩歡
137 void DoInitialize(void* AItem, Word ASize)
138 {
139 if (OnInitialize.Method != NULL)
140 ((TObject*)OnInitialize.Object->*OnInitialize.Method)(AItem, ASize);
141 }
142
143 // 鎵ц OnFinalize 浜嬩歡
144 void DoFinalize(void* AItem, Word ASize)
145 {
146 if (OnFinalize.Method != NULL)
147 ((TObject*)OnFinalize.Object->*OnFinalize.Method)(AItem, ASize);
148 }
149
150 // 浜嬩歡
151 TOnFormat OnInitialize;
152 TOnFormat OnFinalize;
153
154 protected:
155 private:
156 };
157
158 // 渚嬪瓙錛氬浣曡緗簨浠舵柟娉曟寚閽?/span>
159 void TDemo::SetEvent()
160 {
161 FDemo.OnInitialize.Object = this;
162 FDemo.OnInitialize.Method = (TKYFmtMemEvent::TDoFormat)&TDemo::DoFormat;
163
164 // ???

165 }
166
167 // FDemo 鐨?nbsp;OnInitialize 浜嬩歡鏂規(guī)硶
168 void TDemo::DoFormat(void* AItem, Word ASize)
169 {
170 // ???

171 }
172
鍥炶皟浜嬩歡鐨勬柟娉曟寚閽堥渶瑕丆++緙栬瘧鍣ㄦ敮鎸侊紝鑷沖皯VC鐨勪笉鍚岀増鏈強GCC緙栬瘧鍣ㄩ兘鏀寔銆?br />鍦╒C6鍜孷C2003涓緗柟娉曟寚閽堢浉瀵硅緝瀹芥澗錛孷C2005涔嬪悗灝卞緢涓ユ牸浜嗭紝濡備笅錛?br />FDemo.OnInitialize.Method = (TKYFmtMemEvent::TDoFormat)&TDemo::DoFormat;
榪欒浠g爜閮借涓嶅悓鐗堟湰VC緙栬瘧鍣ㄦ敮鎸侊紝浣嗗涓嬩唬鐮佸氨鍙兘琚玍C6銆乂C2003鏀寔錛?br />FDemo.OnInitialize.Method = (TKYFmtMemEvent::TDoFormat)DoFormat;
鍏跺疄錛岀被鏂規(guī)硶璋冪敤鍘熺悊寰堢畝鍗曪紝鑻ョ煡閬撳浣曚嬌鐢–璇█妯℃嫙綾誨疄鐜板氨鐭ラ亾鎬庝箞鍥炰簨浜嗭紝鍙?br />鏄繖涓伐浣滅敱緙栬瘧鍣ㄦ潵鍋氱艦浜嗐備笉榪囦笉鏄粈涔堟柟娉曢兘鍙互璋冪敤鐨勶紝濡傦細(xì)闈欐佹柟娉曞氨鍙兘褰撳仛
鍑芥暟鎸囬拡鏉ョ敤錛岃岄噸杞芥柟娉曘佽櫄鏂規(guī)硶絳夌瓑鏄笉鍙潬鐨勶紝鎵浠ユ渶濂戒嬌鐢ㄦ櫘閫氱殑綾繪柟娉曟寚閽堛?/p>
璋冪敤鏂規(guī)硶涓庤皟鐢ㄥ嚱鏁扮殑鍖哄埆鏄湪璋冪敤鏂規(guī)硶鏃訛紝緙栬瘧鍣ㄦ妸褰撳墠瀵硅薄鐨勬寚閽堝綋鍋氱涓涓弬鏁頒紶
鍏ワ紝鍏跺畠鍙傛暟鐨勪紶閫掍笌鍑芥暟娌℃湁鍖哄埆錛屼篃灝辮錛岃繖涓烘彁渚涘洖璋冧簨浠剁殑鏂規(guī)硶鎸囬拡鎻愪緵涓鏉℃柟渚夸箣闂ㄣ?/p>
鏂規(guī)硶鎸囬拡涓嶈兘婊ョ敤錛岀敤濂藉畠鍙互浣夸綘鐨勮閲庢洿鍔犲紑闃旓紒

]]>
精品蜜臀久久久久99网站|
成人精品一区二区久久久|
国内精品久久久久久久久电影网
|
精品乱码久久久久久夜夜嗨|
草草久久久无码国产专区|
国产91久久精品一区二区|
久久九九有精品国产23百花影院|
2021久久国自产拍精品|
国产三级观看久久|
久久男人AV资源网站|
国产精品久久久久久久app|
日韩精品久久久久久久电影蜜臀
|
久久综合久久自在自线精品自|
亚洲中文字幕久久精品无码APP|
精品久久久噜噜噜久久久|
精品久久人妻av中文字幕|
久久精品国产免费一区|
久久久久亚洲AV成人网人人软件|
久久久久久久97|
AV无码久久久久不卡网站下载|
久久久久这里只有精品|
久久午夜免费视频|
久久精品中文无码资源站|
国产精品久久久99|
久久久久久曰本AV免费免费|
国产精品18久久久久久vr|
91久久精品国产免费直播|
色妞色综合久久夜夜|
中文字幕亚洲综合久久2|
一本一道久久a久久精品综合
|
久久亚洲中文字幕精品一区四|
亚洲欧美日韩中文久久|
国产成人久久777777|
亚洲欧美日韩中文久久|
久久久精品久久久久特色影视|
久久天天躁狠狠躁夜夜网站|
久久免费视频一区|
久久亚洲欧美日本精品|
亚洲国产欧美国产综合久久|
国内精品久久久久久久coent|
亚洲女久久久噜噜噜熟女|