Enumeration (enum) types

BlitzMax Forums/BlitzMax Programming/Enumeration (enum) types

Scaremonger(Posted 2007) [#1]
The inclusion of arrays addition in Blitzmax 1.26 has given us the ability to simulate Enumeration..

Try this:
Const SYM_A% = 1
Const SYM_B% = 2
Const SYM_C% = 3
Const SYM_D% = 4
Const SYM_E% = 5
Const SYM_F% = 6

Local symbol:TEnum = New TEnum

Local a%[] = [SYM_F,SYM_E,SYM_D]
Local b%[] = [SYM_A,SYM_B,SYM_C]

symbol.value = SYM_D
If Symbol.in( a+b ) Then DebugLog "Yes it's found"

showSymbols( a+b )

'########################################
Function showSymbols( list%[] )
	For Local item% = EachIn list
		DebugLog item
	Next
End Function

'########################################
Type TEnum
	Field value%

	'----------------------------------------
	Method in( list%[] )
		For Local item% = EachIn list
			If value=item Then Return True
		Next
	Return False
	End Method
End Type



FlameDuck(Posted 2007) [#2]
Not typesafe, so not technically an enumerator.


Scaremonger(Posted 2007) [#3]
True, but it simulates the functionality quite well.


H&K(Posted 2007) [#4]
We can already simulate Enumeration, by simply typing the numbers in.


Brucey(Posted 2007) [#5]
We can already simulate Enumeration, by simply typing the numbers in.

Heh... that's how I simulate key-presses ;-)


Scaremonger(Posted 2007) [#6]
We can simulate constants like that too :)


H&K(Posted 2007) [#7]
It just seems to compicated for me. I know I was glib, but apart from the speed of not having to type = XX, I cannot see how your replacement would be of use to me. (Cos I would forget how it worked and introduce error where none were before)

Fair enough well done, and it is and example of array addition I suppose. Just not very useful. (The not very useful bit is my opinon, if anyone does find it useful, then obviously it is useful)