[Implemented] Enumeration enhancements

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Enumeration enhancements

Post by jassing »

If I understand, I asked a similar question.. here's the solution that was presented....

Code: Select all

Macro POW2
 (#PB_Compiler_EnumerationValue - 1) << 1
EndMacro

Enumeration 
 #ONE   = 1
 #TWO   = POW2
 #THREE = POW2
 #FOUR  = POW2
 #FIVE  = POW2
 #SIX   = POW2
EndEnumeration

Debug #ONE
Debug #TWO
Debug #THREE
Debug #FOUR
Debug #FIVE
Debug #SIX
User avatar
Michael Vogel
Addict
Addict
Posts: 2797
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Enumeration enhancements

Post by Michael Vogel »

Jassing, seems that you've read this thread like I did :wink:
Demivec has posted the same solution as well, and I didn't find it...

I was posting one additional version which does not need an initial value (who ever will like this), and here are some of my (confusing) variants for different jobs...

Code: Select all

CompilerIf #PB_Compiler_Version>500
	Macro Boolean(Expression)
		Bool((Expression))
	EndMacro
CompilerElse
	Macro Boolean(Expression)
		((Expression) Or #False)
	EndMacro
CompilerEndIf

Macro BinaryEnumeration
	;((#PB_Compiler_EnumerationValue-Boolean(#PB_Compiler_EnumerationValue>1))<<Boolean(#PB_Compiler_EnumerationValue>1)); [<=PB5: 0,1,2,4,8,...]
	;((#PB_Compiler_EnumerationValue-1)<<1+((#PB_Compiler_EnumerationValue-2)&$8000000+(~-#PB_Compiler_EnumerationValue)&$8000000)>>27); [>PB5: 0,1,2,4,8,...]
	(#PB_Compiler_EnumerationValue<<1-2+3*(((#PB_Compiler_EnumerationValue-1)&$8000000)>>27)); [>PB5: 1,2,4,8,16,...]
EndMacro

Enumeration
	#ONE   = BinaryEnumeration
	#TWO   = BinaryEnumeration
	#THREE = BinaryEnumeration
	#FOUR  = BinaryEnumeration
	#FIVE  = BinaryEnumeration
	#SIX   = BinaryEnumeration
EndEnumeration

Debug #ONE
Debug #TWO
Debug #THREE
Debug #FOUR
Debug #FIVE
Debug #SIX
Post Reply