59 lines
1.3 KiB
Plaintext
59 lines
1.3 KiB
Plaintext
'============
|
|
class History
|
|
'============
|
|
|
|
indexbase 0
|
|
|
|
string buf
|
|
sys ii,ld,pb
|
|
|
|
method constructor(sys n=1000, l=sizeof sys) {buf=nuls n*l : pb=strptr buf : ld=l : ii=0}
|
|
method destructor () {clear}
|
|
'
|
|
method setup(sys n=1000, l=sizeof sys) {buf=nuls n*l : pb=strptr buf : ld=l : ii=0}
|
|
method clear() {buf="" : pb=0 : ld=0 : ii=0}
|
|
method max (sys i) {if i>ii{ii=i}}
|
|
method count() as sys {return ii}
|
|
method size () as sys {return ld}
|
|
'
|
|
method get (any*p,i) {copy @p, pb+i*ld,ld } 'out
|
|
method add (any*p) {copy pb+ii*ld,@p,ld : ii++} 'in
|
|
method put (any*p,sys i) {copy pb+i*ld,@p,ld : max i} 'in
|
|
'
|
|
end class
|
|
|
|
'====
|
|
'TEST
|
|
'====
|
|
|
|
'this works for fixed length types
|
|
|
|
'it will not work for types containing
|
|
'volatile pointers. eg: string members
|
|
|
|
type vector double x,y,z
|
|
|
|
vector v
|
|
|
|
new History hv(1000,sizeof v) 'give number of records and variable size
|
|
|
|
sys i
|
|
for i=0 to 9
|
|
v<=i,i*10,i*100 'assign new values to vector
|
|
hv.add v 'add to history
|
|
next
|
|
|
|
string tab=chr(9) : cr=chr(13)+chr(10)
|
|
string pr="Data History of v" cr cr
|
|
pr+="n" tab "x" tab "y" tab "z" cr
|
|
vector sv
|
|
'
|
|
for i=hv.count()-1 to 0 step -1
|
|
hv.get sv,i
|
|
pr+=i tab sv.x tab sv.y tab sv.z cr
|
|
next
|
|
|
|
print pr 'result '9,90,900 : 8,80,800 ...
|
|
|
|
del hv
|