Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [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

nemoredsList

Uploader:RedakteurMOD
Datum/Zeit:16.11.2013 19:13:17

'nemoreds list example - how to override mdType methods

#Define nemoredsList(E) nemoredsList##E
#Macro nemoredsListDeclare(E)

#Include Once "md/util/mdList.bi"
mdListDeclare(E)

#Ifndef nemoredsList##E

Type nemoredsList##E Extends mdList##E
    Public:
    Declare Constructor ()
    Declare Constructor (element As E)
    Declare Constructor (l As mdCollection##E)
    Declare Destructor ()

    Declare Function toString() As String 'we want to override this method - we need to copy the ctors, dtors and operators, because FB doesn't inherit everything so far

    Declare Operator Cast() As Integer
    Declare Operator Cast() As String
    Declare Operator Let(c As mdCollection##E)
End Type

Constructor nemoredsList##E ()

End Constructor

Constructor nemoredsList##E (element As E)
    This.add(element)
End Constructor

Constructor nemoredsList##E (l As mdCollection##E)
    This.addAll(l)
End Constructor

Destructor nemoredsList##E ()
    Dim As mdBasicNode##E Ptr currentNode = @This.node, nextNode
    While currentNode->nex <> NULL
        nextNode = currentNode->nex->nex
        Delete currentNode->nex
        currentNode->nex = nextNode
    Wend
End Destructor

Function nemoredsList##E.toString() As String
    Dim As String ret = "ListStart"
    Dim As mdBasicNode##E Ptr currentNode = @This.node
    While currentNode->nex <> NULL
        ret &= Str(currentNode->nex->value)
        currentNode = currentNode->nex
        If currentNode->nex <> NULL Then
            ret &= "Separator"
        EndIf
    Wend
    ret &= "ListEnd"
    Return ret
End Function

Operator nemoredsList##E.Cast() As Integer
    Return This.hashCode()
End Operator

Operator nemoredsList##E.Cast() As String
    Return This.toString()
End Operator

Operator nemoredsList##E.Let(c As mdCollection##E)
    This.clear()
    This.addAll(c)
End Operator

#EndIf

#EndMacro

'################################################

nemoredsListDeclare(Long)

Print "Old mdList:"

Dim As mdList(Long) oList
oList.add(1)
oList.add(2)
oList.add(3)

For i As Integer = 0 To oList.size() - 1
    Print oList.get(i)
Next
Print oList 'original toString method


Print "----------"
Print "New nemoredsList:"

Dim As nemoredsList(Long) nList
nList.add(1)
nList.add(2)
nList.add(3)

For i As Integer = 0 To nList.size() - 1
    Print nList.get(i)
Next
Print nList 'custom toString method

Sleep