1 { Copyright (C) 2005 Bas Steendijk and Peter Green
\r
2 For conditions of distribution and use, see copyright notice in zlib_license.txt
\r
3 which is included in the package
\r
4 ----------------------------------------------------------------------------- }
\r
12 uses blinklist,pgtypes;
\r
18 tfifo=class(tobject)
\r
20 l:tlinklist; {add to}
\r
21 getl:tlinklist; {remove from}
\r
26 procedure add(data:pointer;len:integer);
\r
27 function get(var resultptr:pointer;len:integer):integer;
\r
28 procedure del(len:integer);
\r
30 destructor destroy; override;
\r
50 procedure tfifo.add;
\r
55 if len <= 0 then exit;
\r
57 while len > 0 do begin
\r
59 if ofs = pagesize then begin
\r
60 p := tplinklist.create;
\r
61 if getl = nil then getl := p;
\r
62 getmem(tplinklist(p).p,pagesize);
\r
67 a := pagesize - ofs;
\r
68 if len < a then a := len;
\r
69 move(data^,pointer(taddrint(tplinklist(p).p)+ofs)^,a);
\r
70 inc(taddrint(data),a);
\r
81 if len > size then len := size;
\r
82 if len <= 0 then begin
\r
88 resultptr := pointer(taddrint(tplinklist(p).p)+getofs);
\r
89 result := pagesize-getofs;
\r
90 if result > len then result := len;
\r
93 procedure tfifo.del;
\r
98 if len <= 0 then exit;
\r
100 if len > size then len := size;
\r
103 if len = 0 then exit;
\r
105 while len > 0 do begin
\r
106 a := pagesize-getofs;
\r
107 if a > len then a := len;
\r
110 if getofs = pagesize then begin
\r
112 freemem(tplinklist(p).p);
\r
122 if size = 0 then begin
\r
123 if assigned(l) then begin
\r
125 freemem(tplinklist(p).p);
\r
136 constructor tfifo.create;
\r
142 destructor tfifo.destroy;
\r