Buchempfehlung
Visual Basic 6 Kochbuch
Visual Basic 6 Kochbuch
Viele praktische Tipps zum Programmieren mit Visual Basic 6, die sich oft auch auf FB übertragen lassen. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Collection.bi

Uploader:MitgliedOneCypher
Datum/Zeit:13.10.2009 10:58:44
Hinweis: Dieser Quelltext ist Bestandteil des Projekts GuiPtr, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.

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

type Item
    CollectionPtr as Collection Ptr
    ItemPtr as any ptr ptr
    i as integer
    declare constructor overload ( byref _ItemPtr as any ptr, _Collection as Collection ptr)
    declare constructor overload ( byref _ItemPtr as any ptr, _Collection as Collection)
    declare function NextItem() as integer
    declare operator cast() as integer
end type

operator Item.Cast() as integer
    Return NextItem
end operator

function Item.NextItem() as integer
    dim as integer _false
    dim as integer _true
    _false = (1 = 0)
    _true = (1 <> 0)
    if i < CollectionPtr->Count then
        i = i + 1
        *ItemPtr = CollectionPtr->Item(i)
        return _false
    else
        i = 0
        return _true
    end if
end function

constructor Item overload( byref _ItemPtr as any ptr, _Collection as Collection ptr)
    ItemPtr = @_ItemPtr
    CollectionPtr = _Collection
end constructor

constructor Item overload( byref _ItemPtr as any ptr, _Collection as Collection )
    ItemPtr = @_ItemPtr
    CollectionPtr = @_Collection
end constructor

#define ForEach(Collection_Item) scope:dim CollectionItems123456 as item = item(Collection_Item,
#define in(ObjectCollection) ObjectCollection):Do until CollectionItems123456
#define NextOne loop: end scope