fbList - Easy to use, fast, arbitrary index, type-agnostic, extensible, and sortable list

User projects written in or related to FreeBASIC.
Post Reply
Jattenalle
Posts: 66
Joined: Nov 17, 2023 14:41
Contact:

fbList - Easy to use, fast, arbitrary index, type-agnostic, extensible, and sortable list

Post by Jattenalle »

fbList 0.3 now available at http://www.jattegames.com/
fbList is an easy to use, fast, arbitrary index, type-agnostic, extensible, and sortable list library

Code: Select all

'// Typelist example
#include once "../fbList.bi"

'// TypeList's are where fbList really shines by enabling the creation of
'//  fast arbitrary strongly typed lists of any type, including user defined.

print "The TYPELIST <listname> HOLDS <listtype> macro allows the easy"
print " creation of lists containing any type, including user defined ones."

'// Create an array of numbers
dim as integer ScrambledNumbers(...) = {5, 1, 3, 4, 2}

'// Create a new list type named IntList that can hold integers
TypeList IntList Holds integer

'// Create a list off of our TYPELIST and fill it with the numbers we defined above
dim as IntList myList = ScrambledNumbers()


print "myList is "& myList.Length &" items long:"
myList.ForEach(i as integer)
	if i > 0 then
		print ", "& myList[i];
	else
		print "	"& myList[i];
	end if
next
print

myList += 99 '// += is shorthand to Insert a new element at the end of the list

print "	After +=, myList is "& myList.Length &" items long:"
print "		"& myList.CSV() '// .CSV returns a comma separated string of all elements in the list

myList.Remove(2) '// Remove the element at index 2

print "	After .Remove(2), myList is "& myList.Length &" items long:"
print "		"& myList.CSV() '// .CSV returns a comma separated string of all elements in the list

myList.Insert(3, 2) '// Insert the element 3 at index 2

print "	After .Insert(3,2), myList is "& myList.Length &" items long:"
print "		"& myList.CSV() '// .CSV returns a comma separated string of all elements in the list

print
print "Press any key to close the example!"
sleep
Additional examples can be found in the /examples/ directory.
Details:
  • Language: FreeBASIC
  • Library type: .bi header
  • Attribution: fbList is Copyright (c) 2023-2024 Johannes "Jattenalle" Pihl, all rights reserved
  • Sourcecode: Yes, zLib license
oyster
Posts: 278
Joined: Oct 11, 2005 10:46

Re: fbList - Easy to use, fast, arbitrary index, type-agnostic, extensible, and sortable list

Post by oyster »

nice lib with a real person friendly syntax
Post Reply