Abstract type: Difference between revisions

m (Tweak irregular header markup)
Line 2,303:
<pre>
 
'ABSTRACT TYPETYPES FOR CONTAINING THINGSEXAMPLE
'PARTICLES
 
type position {}
macro ContainerClass(name,body)
type angle {}
type name##Type body
type velocity {}
class name
type mass {}
'
type counter {}
string buffer
'
method constructor(sys n=1)
buffer=nuls n*sizeof name##Type
end method
'
method destructor()
buffer=""
end method
'
method GetMembers(sys i,n) as name##Type
sys le=len buffer
sys en=(n+i)*sizeof name##type
if le<en
buffer+=nuls en-le 'auto expand
end if
return i+strptr buffer
end method
'
end macro
 
type particle
position p
angle a
velocity v
mass m
end macrotype
 
class particles
'CREATE CLASS
particle*q
 
counter c
ContainerClass Vector3dArray, {double x,y,z}
method constructor(sys n=1(){}
'...
method destructor (){}
method action (){}
end class
 
 
'CREATE OBJECT
 
new Vector3dArray v(100)
 
 
'OBTAIN POINTER AND FILL CHUNK
 
let pv=v.GetMembers(50,3) 'offset, quantity
pv<=1,2,3, 10,20,30, 100,200,300
'...
 
'TEST
 
print pv[3].y
 
del v
 
</pre>
54

edits