fb:porticula NoPaste
Collection.bi
Uploader: | OneCypher |
Datum/Zeit: | 20.09.2009 16:59:34 |
Hinweis: Dieser Quelltext ist Bestandteil des Projekts GuiPtr, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.
Warnung: Es steht bereits eine neuere Version des Quelltexts zur Verfügung. Die hier vorliegende alte Version könnte Fehler enthalten, die in der neuen Version vielleicht ausgebessert wurden.
'Dies hier ist eine simple, verkettete liste, ähnlich dem Datentyp "Collection"
'Dieser wird von der GuiPtr.bi gebraucht!
Type ItemContainer
V_PTR as any ptr
Next_IC as ItemContainer ptr
end type
type Collection
public:
declare function Add(v_ptr as any ptr) as any ptr
declare sub Remove(index as long)
declare function Count() as long
declare property Item(index as long) as any ptr
declare property Item(index as long, v as any ptr)
private:
FirstItem as ItemContainer ptr
LastItem as ItemContainer ptr
end type
function Collection.add(v_ptr as any ptr) as any ptr
if FirstItem = 0 then
FirstItem = new ItemContainer
LastItem = FirstItem
else
LastItem->next_IC = new ItemContainer
LastItem = LastItem->next_IC
end if
LastItem->v_ptr = v_ptr
return v_ptr
end function
sub Collection.Remove(index as long)
dim ic as ItemContainer ptr = FirstItem
dim IC_Tmp as ItemContainer ptr
if index = 1 and ic <> 0 then
IC_Tmp = FirstItem
FirstItem = FirstItem->Next_IC
delete IC_Tmp
else
for i as long = 1 to index
if ic = 0 then exit for
if i = index then
'delete ic->v_ptr
IC_Tmp->next_IC = ic->next_IC
delete ic
exit for
end if
IC_Tmp = ic
ic = ic->next_IC
next
end if
end sub
function Collection.Count() as long
dim ic as ItemContainer ptr = FirstItem
dim c as long
while ic <> 0
c += 1
ic = ic->Next_IC
wend
return c
end function
property Collection.Item(index as long) as any ptr
dim ic as ItemContainer ptr = FirstItem
dim c as long
while ic <> 0
c += 1
if c = index then return ic->v_ptr
ic = ic->Next_IC
wend
end property
property Collection.Item(index as long, v as any ptr)
dim ic as ItemContainer ptr = FirstItem
dim c as long
while ic <> 0
c += 1
if c = index then
ic->v_ptr = v
exit while
end if
ic = ic->Next_IC
wend
end property