Page 1 of 2

[Implemented] Enumeration

Posted: Sat Jul 20, 2013 12:38 pm
by User_Russian
Occasionally constants are used as flags and each flag must conform to a particular bit in the variable.
Now Enumeration does not support this method of enumeration constants.
Perhaps you need to add a new method for parameter Step.

Code: Select all

Enumeration 1 Step #PB_Enumeration_Bits
  #Flag_1 ; Will be 1
  #Flag_2 ; Will be 2
  #Flag_3 ; Will be 4
  #Flag_4 ; Will be 8
EndEnumeration

Re: Enumeration

Posted: Sat Jul 20, 2013 12:56 pm
by uwekel
+1

Re: Enumeration

Posted: Sat Jul 20, 2013 1:00 pm
by PB
> Enumeration does not support this method of enumeration constants

Code: Select all

Macro NextBit
  (#PB_Compiler_EnumerationValue-1)*2
EndMacro

Enumeration 1
  #Flag1
  #Flag2=NextBit
  #Flag3=NextBit
  #Flag4=NextBit
  #Flag5=NextBit
EndEnumeration

Debug #Flag1 ; 1
Debug #Flag2 ; 2
Debug #Flag3 ; 4
Debug #Flag4 ; 8
Debug #Flag5 ; 16

Re: Enumeration

Posted: Sat Jul 20, 2013 5:21 pm
by davido
+1

See this: Step value to the power of X - http://www.purebasic.fr/english/viewtop ... =3&t=23821

Re: Enumeration

Posted: Sat Jul 20, 2013 6:21 pm
by luis

Re: Enumeration

Posted: Sat Jul 20, 2013 7:09 pm
by Demivec

Re: Enumeration

Posted: Sat Jul 20, 2013 7:36 pm
by rsts
PB wrote:> Enumeration does not support this method of enumeration constants

Code: Select all

Macro NextBit
  (#PB_Compiler_EnumerationValue-1)*2
EndMacro
PB wrote:The more you post workarounds, the less likely it'll be done natively. ;)
:)

Re: Enumeration

Posted: Sat Jul 20, 2013 10:50 pm
by CSHW89

Re: Enumeration

Posted: Sun Jul 21, 2013 1:46 am
by skywalk
For positive and negative series... :wink:

Code: Select all

Macro HASH
  #
EndMacro
Macro ENUM_RESET(n=0)
  Enumeration n
  EndEnumeration
EndMacro
Macro ENUM_x2(n, Name, negative=0)
  ; Create enumeration constant/flag for later use.
  ; Positive (0,1,2,4,...) or Negative (0,-1,-2,-4,...) series.
  ; Enumerations support Long, Not Quad.
  CompilerIf #PB_Compiler_EnumerationValue = 0
    Enumeration #PB_Compiler_EnumerationValue
      HASH#Name#n
  CompilerElseIf #PB_Compiler_EnumerationValue = 1
    CompilerIf negative
      Enumeration #PB_Compiler_EnumerationValue Step -1
        HASH#Name#n = -#PB_Compiler_EnumerationValue
    CompilerElse
      Enumeration #PB_Compiler_EnumerationValue
        HASH#Name#n
    CompilerEndIf
  CompilerElse    ; #PB_Compiler_EnumerationValue >= 2
    CompilerIf negative
      Enumeration #PB_Compiler_EnumerationValue Step -1
        HASH#Name#n = (#PB_Compiler_EnumerationValue + 1) * 2
    CompilerElse
      Enumeration #PB_Compiler_EnumerationValue Step 1
        HASH#Name#n = (#PB_Compiler_EnumerationValue - 1) * 2
    CompilerEndIf
  CompilerEndIf
  EndEnumeration
EndMacro
Debug "-- Positive Constants/Flags --"
ENUM_RESET(0)
ENUM_x2(0,BIT)    : Debug "#bit0 = " + #bit0
ENUM_x2(1,BIT)    : Debug "#bit1 = " + #bit1
ENUM_x2(2,BIT)    : Debug "#bit2 = " + #bit2
ENUM_x2(3,BIT)    : Debug "#bit3 = " + #bit3
ENUM_x2(4,BIT)    : Debug "#bit4 = " + #bit4
ENUM_x2(5,BIT)    : Debug "#bit5 = " + #bit5
ENUM_x2(6,BIT)    : Debug "#bit6 = " + #bit6
ENUM_x2(7,BIT)    : Debug "#bit7 = " + #bit7
Debug "-- Negative Constants/Flags --"
ENUM_RESET(0)
ENUM_x2(0,BITn,1) : Debug "#bitn0 = " + #bitn0
ENUM_x2(1,BITn,1) : Debug "#bitn1 = " + #bitn1
ENUM_x2(2,BITn,1) : Debug "#bitn2 = " + #bitn2
ENUM_x2(3,BITn,1) : Debug "#bitn3 = " + #bitn3
ENUM_x2(4,BITn,1) : Debug "#bitn4 = " + #bitn4
ENUM_x2(5,BITn,1) : Debug "#bitn5 = " + #bitn5
ENUM_x2(6,BITn,1) : Debug "#bitn6 = " + #bitn6
ENUM_x2(7,BITn,1) : Debug "#bitn7 = " + #bitn7

Re: Enumeration

Posted: Sun Jul 21, 2013 1:51 am
by skywalk
That code is broken with the addition of Bool(). :!:

Re: Enumeration

Posted: Sun Jul 21, 2013 4:51 am
by PB
> The more you post workarounds, the less likely it'll be done natively.

That's right. And my point there still stands. This request doesn't need
a native solution, as shown. It's quick and simple to do it yourself. Are
we programmers or not?

Re: Enumeration

Posted: Sun Jul 21, 2013 5:08 am
by rsts
If it still stands, why did you post a work around? :)

Re: Enumeration

Posted: Sun Jul 21, 2013 5:21 am
by PB
To show that such simple requests can be done by the "programmer".

Re: Enumeration

Posted: Sun Jul 21, 2013 7:05 am
by rsts
You've confused me. :)

If you like workarounds why did you complain about the same one in this post?
http://www.purebasic.fr/english/viewtop ... =3&t=23821
PB wrote:The more you post workarounds, the less likely it'll be done natively. ;)

Re: Enumeration

Posted: Sun Jul 21, 2013 7:38 am
by Tenaja
PB wrote:To show that such simple requests can be done by the "programmer".
That can be a slippery slope... afterall, if you take that literally, why is Fred making any updates???