Skip to content

Commit d4e1367

Browse files
ADD: update libs
1 parent 74c7e62 commit d4e1367

File tree

2 files changed

+457
-29
lines changed

2 files changed

+457
-29
lines changed

src/ufifo.pas

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* uFifo.pas 23.09.2005 *)
33
(* *)
4-
(* Version : 0.04 *)
4+
(* Version : 0.05 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -28,6 +28,7 @@
2828
(* Bugfix Verlust von Daten beim Push *)
2929
(* 0.03 - property count *)
3030
(* 0.04 - TFifo thread Safe gemacht *)
31+
(* 0.05 - TBufferedFifo.BufferSize *)
3132
(* *)
3233
(******************************************************************************)
3334

@@ -62,6 +63,9 @@
6263
fCount: integer;
6364
cs: TCriticalSection;
6465
public
66+
Type
67+
TComparefunction = Function(Const a, b: T): Boolean Of Object;
68+
6569
Property Count: integer read fCount; // Anzahl der Aktuell enthaltenen Elemente
6670
// Initialisieren
6771
Constructor create;
@@ -77,6 +81,8 @@
7781
Function Top: T;
7882
// Gibt True zurück wenn Leer
7983
Function isempty: Boolean;
84+
// Zum Prüfen ob die queue einen eintrag aElement hat
85+
Function ContainsElement(Const aElement: T; CompareFunction: TComparefunction): Boolean;
8086
End;
8187

8288
FifoException = Class(Exception);
@@ -97,8 +103,10 @@
97103
fCount: integer;
98104
fHead: integer;
99105
fTail: integer;
106+
Function getBufferSize: integer;
100107
public
101108
Property Count: integer read fCount; // Anzahl der Aktuell enthaltenen Elemente
109+
Property BufferSize: integer read getBufferSize;
102110
// Initialisieren
103111
Constructor create; overload; // Ruft Create(16) auf.
104112
Constructor create(InitialBufferSize: integer); overload;
@@ -230,6 +238,29 @@
230238
Result := Not assigned(Front);
231239
End;
232240

241+
Function TFifo.ContainsElement(Const aElement: T;
242+
CompareFunction: TComparefunction): Boolean;
243+
Var
244+
p: PGenQ;
245+
Begin
246+
result := false;
247+
cs.Acquire;
248+
Try
249+
p := front;
250+
While assigned(p) Do Begin
251+
result := CompareFunction(aElement, p^.Value);
252+
If result Then Begin
253+
p := Nil;
254+
End
255+
Else Begin
256+
p := p^.Next;
257+
End;
258+
End;
259+
Finally
260+
cs.Release;
261+
End;
262+
End;
263+
233264
{ TBufferedFifo }
234265

235266
Constructor TBufferedFifo.create;
@@ -243,18 +274,22 @@
243274
If InitialBufferSize <= 2 Then Begin
244275
Raise BufferedFifoException.Create('Invalid InitialBufferSize, has to be > 2');
245276
End;
246-
fHead := 0;
247-
fTail := 0;
248-
fCount := 0;
249277
setlength(fBuffer, InitialBufferSize);
278+
Clear();
250279
End;
251280

252281
Destructor TBufferedFifo.Destroy;
253282
Begin
254283
setlength(fbuffer, 0);
284+
fbuffer := Nil;
255285
Inherited Destroy;
256286
End;
257287

288+
Function TBufferedFifo.getBufferSize: integer;
289+
Begin
290+
result := length(fBuffer);
291+
End;
292+
258293
Procedure TBufferedFifo.Clear;
259294
Begin
260295
// Die Indexe werden gelöscht, der Puffer bleibt Allokiert => die Query ist Leer ;)
@@ -317,7 +352,3 @@
317352

318353
End.
319354

320-
321-
322-
323-

0 commit comments

Comments
 (0)