'data table demo
'
'
===================
class FixedTable10k
===================
'
% TableSize  10000 'bytes
% RecordSize 100   'bytes
% FieldSize  10    'bytes
% offset    -109   '1-record-field 
'
bstring ft 'Fixed Table storage
'
method constructor()
====================
  ft=space(TableSize)
end method
'
method destructor()
===================
  ft=""
end method
'
method load(string f="t.dat")
=============================
  ft=getfile(f)
end method
'
method save(string f="t.dat")
=============================
  putfile(f,ft)
end method
'
method pad(string s) as string
==============================
  int le=len(s)
  if le=10
    return s
  else
    return left(s+space(FieldSize),FieldSize)
  endif
end method
'
method get(int y,x) as string
=============================
  return mid(ft, y*RecordSize+x*FieldSize+offset,FieldSize)
end method
'
method put(int y,x, string s)
=============================
  mid(ft, y*RecordSize+x*fieldSize+offset)=pad(s)
end method
'
method show(int y=0,x=0)
========================
  if y=0
    print ""
    exit method
  endif
  if x=0
    'whole record
    print mid(ft,y*RecordSize+FieldSize+offset,RecordSize)
  else
    'field
    print get(y,x)
  endif
end method
'
end class 'FixedTable10k
'
'TESTS
'=====
new FixedTable10k t()
t.put(2,3,"Hello")
t.put(2,4,"world")
'print t.get(2,3)
't.show(2)
't.show(2,4)
't.show(2,3)
t.save()
del t
new FixedTable10k u
u.load()
u.show(2)
u.put(2,3, ucase(u.get(2,3)) )
u.show(2)
del u
