/
clsQueue.cls
202 lines (143 loc) · 4.33 KB
/
clsQueue.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "clsQueue"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' clsQueue.cls
' Copyright (C) 2008 Eric Evans
Option Explicit
Private Const MAX_PRIORITY_LEVEL = 100
Private m_QueueObjs() As clsQueueObj
Private m_ObjCount As Long
Private m_LastUser As String
Private m_LastObjID As Double
Private Sub Class_Initialize()
m_LastObjID = 1
Clear
End Sub
Private Sub Class_Terminate()
Clear
End Sub
Public Sub Push(ByVal obj As clsQueueObj)
On Error GoTo ERROR_HANDLER
Dim Index As Long
Dim i As Long
Index = m_ObjCount
If (m_ObjCount >= 1) Then
For i = 0 To m_ObjCount - 1
If (obj.Priority < m_QueueObjs(i).Priority) Then
Index = i
Exit For
End If
Next i
ReDim Preserve m_QueueObjs(0 To m_ObjCount)
End If
If (Index < m_ObjCount) Then
For i = m_ObjCount To Index + 1 Step -1
Set m_QueueObjs(i) = m_QueueObjs(i - 1)
Next i
End If
obj.ID = m_LastObjID
Set m_QueueObjs(Index) = obj
m_ObjCount = (m_ObjCount + 1)
m_LastObjID = (m_LastObjID + 1)
RunInAll "Event_MessageQueued", obj.ID, obj.Message, obj.Tag
Exit Sub
ERROR_HANDLER:
' overflow - likely due to message id size
If (Err.Number = 6) Then
m_LastObjID = 0
Resume Next
End If
Call frmChat.AddChat(vbRed, "Error: " & Err.Description & " in clsQueue.Push().")
Exit Sub
End Sub
Public Function Pop() As clsQueueObj
Set Pop = New clsQueueObj
Set Pop = m_QueueObjs(0)
RemoveItem 0
End Function ' end function Pop
Public Function Peek() As clsQueueObj
Set Peek = New clsQueueObj
Set Peek = m_QueueObjs(0)
End Function ' end function Peek
Public Function Item(ByVal Index As Long) As clsQueueObj
If ((Index < 0) Or (Index > m_ObjCount - 1)) Then
Set Item = New clsQueueObj
Exit Function
End If
Set Item = m_QueueObjs(Index)
End Function
Public Function ItemByID(ByVal i As Double) As clsQueueObj
Dim j As Long
For j = 0 To m_ObjCount - 1
If (m_QueueObjs(j).ID = i) Then
Set ItemByID = m_QueueObjs(j)
Exit Function
End If
Next j
Set ItemByID = New clsQueueObj
End Function
Public Property Get Count() As Long
Count = m_ObjCount
End Property
Public Function RemoveLines(ByVal Match As String) As Integer
Dim curQueueObj As clsQueueObj
Dim i As Long
Dim found As Long
Do
Set curQueueObj = m_QueueObjs(i)
If (PrepareCheck(curQueueObj.Message) Like PrepareCheck(Match)) Then
RemoveItem i
found = (found + 1)
i = 0
Else
i = (i + 1)
End If
Loop While (i < Count())
RemoveLines = found
End Function
Public Sub RemoveItem(ByVal Index As Long)
Dim i As Long
If ((Index < 0) Or (Index > m_ObjCount - 1)) Then
Exit Sub
End If
If (m_ObjCount > 1) Then
For i = Index To ((m_ObjCount - 1) - 1)
Set m_QueueObjs(i) = m_QueueObjs(i + 1)
Next i
ReDim Preserve m_QueueObjs(0 To m_ObjCount - 1)
m_ObjCount = (m_ObjCount - 1)
Else
Clear
End If
End Sub
Public Sub RemoveItemByID(ByVal i As Double)
Dim j As Long
For j = 0 To m_ObjCount - 1
If (m_QueueObjs(j).ID = i) Then
RemoveItem j
Exit Sub
End If
Next j
End Sub
Public Sub Clear()
Dim i As Long
For i = 0 To m_ObjCount - 1
Set m_QueueObjs(i) = Nothing
Next i
ReDim m_QueueObjs(0)
Set m_QueueObjs(0) = New clsQueueObj
m_ObjCount = 0
KillTimer 0&, QueueTimerID
QueueTimerID = 0
g_BNCSQueue.ClearQueue
End Sub