Yet another linked list in PB (OOP)
Posted: Tue Mar 09, 2010 6:11 pm
Yes, I can hear you yawning already !
Anyway, here it is. PB4.41.
; Yet another linked list implementation for PureBasic (OOP)
; You can store the returned object pointer in a structure, in a array, and so on.
; The LinkedList_Create() procedure instantiate the object and requires the size of the data to be allocated
; plus an optional pointer to procedure. Inside this procedure you write the code to safely free the
; structured data type used for your data, and that code will be executed by the object every time it need
;to deallocate an item. Sound complicated but it's really easy, and great to avoid leakage problems.
; See the example code.
; The SortItems() method too uses a pointer to procedure to perform the logic needed for the sort.
; This way you can easily specify a complex sort, for example ascending for a field, and inside that ordering
; descending for another field. You can create multiple procedures for multiple sorting schemes.
; Again see the example code.
Download from here.
If you find any bug please let me know.
Bye!
Anyway, here it is. PB4.41.
; Yet another linked list implementation for PureBasic (OOP)
; You can store the returned object pointer in a structure, in a array, and so on.
; The LinkedList_Create() procedure instantiate the object and requires the size of the data to be allocated
; plus an optional pointer to procedure. Inside this procedure you write the code to safely free the
; structured data type used for your data, and that code will be executed by the object every time it need
;to deallocate an item. Sound complicated but it's really easy, and great to avoid leakage problems.
; See the example code.
; The SortItems() method too uses a pointer to procedure to perform the logic needed for the sort.
; This way you can easily specify a complex sort, for example ascending for a field, and inside that ordering
; descending for another field. You can create multiple procedures for multiple sorting schemes.
; Again see the example code.
Code: Select all
; -------------------------------------------------------------------
; // DEFINE OBJECT INTERFACE
; -------------------------------------------------------------------
Interface LinkedList
; clear the list and free the object
Destroy()
; select *item as the current list item and return its address back
SelectItem.i(*item)
; delete the current item, select the previous one (if any) or the next one (if any) and return its address
DeleteItem()
; insert a new item before the current one (or add it to an empty list) and return its address
InsertItem.i()
; add a new item after the current one (if any) and return its address
AddItem.i()
; return the pointer to the current item
CurrentItem.i()
; go to the first list item (if any) and return its address
FirstItem.i()
; go to the last list item (if any) and return its address
LastItem.i()
; return the number of the items in the list
CountItems.i()
; go to the next item (if any) and return its address
NextItem.i()
; go to the previous item (if any) and return its address
PreviousItem.i()
; clear the list contents
Clear()
; sort the list items according to the external callback rules
SortItems(*fpCompare)
EndInterface
If you find any bug please let me know.
Bye!