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

PluginList.bi

Uploader:MitgliedThe_Muh
Datum/Zeit:26.11.2009 22:56:34

'##############################################################################################################
'Muh_Plugin_Manager | Dynamic Plugin-System written in FreeBASIC

'Copyright (c) 2009 The_Muh

'Hiermit wird unentgeltlich, jeder Person, die eine Kopie der Software
'und der zugehörigen Dokumentationen (die "Software") erhält, die
'Erlaubnis erteilt, uneingeschränkt zu benutzen, inklusive und ohne
'Ausnahme, dem Recht, sie zu verwenden, kopieren, ändern, fusionieren,
'verlegen, verbreiten, unterlizenzieren und/oder zu verkaufen, und
'Personen, die diese Software erhalten, diese Rechte zu geben, unter den
'folgenden Bedingungen:
'Der obige Urheberrechtsvermerk und dieser Erlaubnisvermerk sind in alle
'Kopien oder Teilkopien der Software beizulegen.

'DIE SOFTWARE WIRD OHNE JEDE AUSDRÜCKLICHE ODER IMPLIZIERTE GARANTIE
'BEREITGESTELLT, EINSCHLIESSLICH DER GARANTIE ZUR BENUTZUNG FÜR DEN
'VORGESEHENEN ODER EINEM BESTIMMTEN ZWECK SOWIE JEGLICHER RECHTSVERLETZUNG,
'JEDOCH NICHT DARAUF BESCHRÄNKT. IN KEINEM FALL SIND DIE AUTOREN ODER
'COPYRIGHTINHABER FÜR JEGLICHEN SCHADEN ODER SONSTIGE ANSPRÜCHE HAFTBAR
'ZU MACHEN, OB INFOLGE DER ERFÜLLUNG EINES VERTRAGES, EINES DELIKTES
'ODER ANDERS IM ZUSAMMENHANG MIT DER SOFTWARE ODER SONSTIGER VERWENDUNG
'DER SOFTWARE ENTSTANDEN.

Declare Sub zero_pointer()

Sub zero_pointer()
    ? "ERROR! ZERO-Pointer detected"
End Sub

type _pli_CB_type as pli_CB_type 'Funktionen / Subs die das Hauptprogramm im Plugin nutzen darf
type _main_CB_type as main_CB_type 'Funktionen / Subs die das Hauptprogramm im Plugin nutzen darf

Type Plugin_Type
    Private:
        cb_pli                      As _pli_CB_type ptr
    Public:
        cb_pli_size                 as uinteger  = 0
        V_InUse                     as UByte
        V_Name                      as String
        V_Handler                   as Any Ptr

        Declare Property call_pli_cb   () As _pli_CB_type Ptr
        Declare Property set_pli_cb   (subname as integer, Byval target As Any Ptr)
        Declare Constructor (size as integer = 0)
        Declare Destructor ()
End Type

Constructor.plugin_type(size as integer)
    this.cb_pli_size = size
    this.cb_pli = callocate(size* sizeof(sub))
    for i as integer = 0 to size -1
        cast(integer ptr, this.cb_pli)[i] = 0
        this.cb_pli_size = size
    next
    ? "Constructor: Plugin_type // Size = " & size
end constructor

destructor.plugin_type()
    deallocate(this.cb_pli)
end destructor


Property Plugin_Type.call_pli_cb() As _pli_CB_type Ptr
    for i as integer = 0 to this.cb_pli_size -1
        if cast(integer ptr, this.cb_pli)[i] = 0 then
             cast(sub ptr, this.cb_pli)[i] = @zero_pointer
        end if
    next
    Return Cast(Any Ptr, This.cb_pli)
End Property

Property Plugin_Type.set_pli_cb(subname as integer, Byval target As Any Ptr)
    if this.cb_pli_size < subname then
        dim old_count as integer = this.cb_pli_size
        this.cb_pli_size = subname +1
        dim new_cb_pli as _pli_CB_type ptr
        new_cb_pli = callocate(subname, sizeof(sub))
        for i as integer = old_count +1 to subname
            cast(sub ptr, new_cb_pli)[i] = cast(sub ptr, this.cb_pli)[i]
            if cast(sub ptr, new_cb_pli)[i] = 0 then
                cast(sub ptr, new_cb_pli)[i] = @zero_pointer
            end if
        next
        this.cb_pli = new_cb_pli
    end if
    cast(sub ptr, this.cb_pli)[subname] = target
End Property


Type PL_int
    V_Next          as PL_int Ptr
    V_Prev          as PL_int Ptr
    V_index         as integer
    V_Data          as Plugin_Type ptr

    Declare function call_pli_cb    () As _pli_CB_type Ptr
    Declare sub set_pli_cb          (subname as integer, Byval target As Any Ptr)
    Declare Constructor (size as integer)
    Declare Destructor ()
End Type

Constructor.PL_int(size as integer)
    this.V_Data = new Plugin_Type(size)
end constructor

destructor.PL_int()
    delete(this.v_data)
end destructor


function pl_int.call_pli_cb() As _pli_CB_type Ptr
    return this.v_data->call_pli_cb
end function

sub pl_int.set_pli_cb(subname as integer, Byval target As Any Ptr)
    this.v_data->set_pli_cb(subname) = target
end sub

Type PluginList
    private:
        cb_pli_size         as integer

    public:
        PLmutex             as any ptr
        PLPtr               as PL_int Ptr

        Declare Function    item        (V_Index as UInteger) as Plugin_Type ptr
        Declare Sub         add     overload(item as plugin_type)
        declare function    add     () as integer
        declare sub         del     (V_index as integer)

        Declare Function    Count           () as UInteger
        Declare Sub         Clear           ()

        declare constructor (cb_pli_size as integer)
        declare destructor  ()
End Type

constructor.pluginlist(cb_pli_size as integer)
    this.cb_pli_size = cb_pli_size
    this.PLmutex = mutexcreate
end constructor

destructor.pluginlist
    mutexdestroy(this.plmutex)
end destructor

function PluginList.item(V_Index as UInteger) as Plugin_Type ptr
    If V_Index = 0 Then
        return 0
    else
        Dim Current as UInteger
        Dim TPtr as PL_INT Ptr = this.plptr
        Do Until TPtr = 0
            Current += 1
            If Current = V_Index Then Exit Do
            TPtr = TPtr->V_Next
        Loop
        return TPtr->v_data
    end if
end function

sub PluginList.add(item_data as plugin_type)
    If this.plptr = 0 Then 'Falls die Liste leer ist: Anlegen!
        this.PLPtr = new pl_int(this.cb_pli_size)
        this.PLPtr->v_next = 0
        *this.PLPtr->v_data = item_data
    Else
        Dim Element As pl_int PTR
        Dim new_item As pl_int PTR
        this.PLPtr = new pl_int(this.cb_pli_size)
        *(new_item->v_data) = item_data

        new_item->v_next = 0
        Element = this.PLPtr
        Do
            If Element->v_next = 0 Then 'Listenende
                ' erreicht!
                new_item->v_prev = element
                Element->v_next = new_item
                Exit Do
            Else
                Element = Element->v_next 'Zum Nächsten
            End If
        Loop
    End If
end sub

function PluginList.add() as integer
    dim item_data as plugin_type ptr = new plugin_type(this.cb_pli_size)
    dim c as integer = 0
    If this.plptr = 0 Then 'Falls die Liste leer ist: Anlegen!
        this.PLPtr = new pl_int(this.cb_pli_size)
        this.PLPtr->v_next = 0
        this.PLPtr->v_data = item_data
        C = 1
    Else
        Dim Element As pl_int PTR
        Dim new_item As pl_int PTR
        dim c as integer = 0
        new_item = new pl_int(this.cb_pli_size)
        new_item->v_data = item_data

        new_item->v_next = 0
        Element = this.PLPtr
        Do
            C +=1
            If Element->v_next = 0 Then 'Listenende
                ' erreicht!
                new_item->v_prev = element
                Element->v_next = new_item
                Exit Do
            Else
                Element = Element->v_next 'Zum Nächsten

            End If
        Loop
    End If
    Return this.count
end function

sub PluginList.del(V_index as integer)
    Dim Current as UInteger
    Dim TPtr as PL_INT Ptr = this.plptr
    Do Until TPtr = 0
        Current += 1
        If Current = V_Index Then Exit Do
        TPtr = TPtr->V_Next
    Loop
    If TPtr = 0 Then Exit Sub
    With *TPtr
        If .V_Next <> 0 Then .V_Next->V_Prev = .V_Prev
        If .V_Prev <> 0 Then
            .V_Prev->V_Next = .V_Next
        else
            if current = 1 then
                this.plptr = .V_next
            else
                ? "Maeh"
            end if
        end if
    End With
end sub

function PluginList.count() as Uinteger
    If this.PLptr = 0 Then Return 0
    Dim C as UInteger
    Dim TPtr as PL_INT Ptr = this.PLptr
    Do Until TPtr = 0
        C += 1
        TPtr = TPtr->V_Next
    Loop
    Return C
end function

Public Sub PL_Destroy(V_LL as PluginList)
    MutexLock(V_LL.PLMutex)
    If V_LL.PLPtr = 0 Then MutexUnLock(V_LL.PLMutex): Exit Sub
    Delete(V_LL.PLPtr)
    V_LL.PLPtr = 0
    MutexUnLock(V_LL.PLMutex)
end sub