[Implemented] Enumeration

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User_Russian
Addict
Addict
Posts: 1518
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

[Implemented] Enumeration

Post 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
uwekel
Enthusiast
Enthusiast
Posts: 740
Joined: Sat Dec 03, 2011 5:54 pm
Location: Oldenburg (Germany)

Re: Enumeration

Post by uwekel »

+1
PB 5.70 LTS (x64) - Debian Testing, Gnome 3.30.2
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Enumeration

Post 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
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: Enumeration

Post by davido »

+1

See this: Step value to the power of X - http://www.purebasic.fr/english/viewtop ... =3&t=23821
DE AA EB
User avatar
luis
Addict
Addict
Posts: 3893
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Enumeration

Post by luis »

"Have you tried turning it off and on again ?"
A little PureBasic review
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Enumeration

Post by Demivec »

Last edited by Demivec on Sat Jul 20, 2013 11:19 pm, edited 1 time in total.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Enumeration

Post 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. ;)
:)
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: Enumeration

Post by CSHW89 »

Image Image Image
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Enumeration

Post 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
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
skywalk
Addict
Addict
Posts: 4211
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Enumeration

Post by skywalk »

That code is broken with the addition of Bool(). :!:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Enumeration

Post 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?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Enumeration

Post by rsts »

If it still stands, why did you post a work around? :)
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: Enumeration

Post by PB »

To show that such simple requests can be done by the "programmer".
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: Enumeration

Post 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. ;)
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Enumeration

Post 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???
Post Reply