Re: Enumeration mit 2er-Potenzen
Verfasst: 30.07.2013 16:23
@c4s
Du brauchst z.B. PB 5.20, damit es funktioniert.
Du brauchst z.B. PB 5.20, damit es funktioniert.
Code: Alles auswählen
Macro EnumFlag(Konstante)
CompilerIf #PB_Compiler_EnumerationValue > 0 : Konstante = (#PB_Compiler_EnumerationValue-1)<<1 : CompilerElse : Konstante = 1 : CompilerEndIf
EndMacro
Enumeration
EnumFlag(#a)
EnumFlag(#b)
EnumFlag(#c)
EnumFlag(#d)
EndEnumeration
Debug #a
Debug #b
Debug #c
Debug #d
Was? Gibt's das jetzt nativ? Wo? Wie? Ich finde nichts... Bin ich wieder zu blind oder zu blöd zum Suchen (oder beides)?CSHW89 hat geschrieben:Aber Fred hat zum Glück mein Wunsch zur 5.20 umgesetzt
Es ging um das Auswerten von Bool() zur Compilezeit. Soetwas hatte vor 5.20 nicht funktioniert:Regenduft hat geschrieben:CSHW89 hat geschrieben:
Aber Fred hat zum Glück mein Wunsch zur 5.20 umgesetzt
Was? Gibt's das jetzt nativ? Wo? Wie? Ich finde nichts... Bin ich wieder zu blind oder zu blöd zum Suchen (oder beides)?
Code: Alles auswählen
#const = Bool(#c1 = #c2)
Code: Alles auswählen
Macro enum2pow(_const_)
_const_ = (Bool(#PB_Compiler_EnumerationValue=1) + Bool(#PB_Compiler_EnumerationValue>1) * ((#PB_Compiler_EnumerationValue-1)<<1))
EndMacro
Code: Alles auswählen
;{ Flagging-Makros
Macro FlaggingQuote
"
EndMacro
Macro StartFlagging(EnumerationName, Bytes = 0)
CompilerIf Defined(StartFlagging_#EnumerationName, #PB_Constant)
CompilerError "Flagging-Name bereits vergeben: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
CompilerIf Bytes > 0
#FlagBytes_#EnumerationName = Bytes
#FlagBytes_#EnumerationName$ = FlaggingQuote#Bytes#FlaggingQuote
CompilerEndIf
#StartFlagging_#EnumerationName = #PB_Compiler_Line + 1
EndMacro
Macro DoFlagging(EnumerationName, FlagName)
CompilerIf Defined(StartFlagging_#EnumerationName, #PB_Constant) = 0
CompilerError "StartFlagging fehlt: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
CompilerIf Defined(StopFlagging_#EnumerationName, #PB_Constant)
CompilerError "Flagging bereits gestoppt: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
CompilerIf Defined(Flag_#EnumerationName#_#FlagName, #PB_Constant)
CompilerError "Flag existiert bereits: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
;===============================================================================================
#Flag_#EnumerationName#_#FlagName = 1 << ( #PB_Compiler_Line - #StartFlagging_#EnumerationName )
;===============================================================================================
CompilerIf Defined(FlagBytes_#EnumerationName, #PB_Constant)
CompilerIf #Flag_#EnumerationName#_#FlagName > 1 << ( #FlagBytes_#EnumerationName << 3 - 1)
CompilerError "Flagging auf "+#FlagBytes_#EnumerationName$+" Byte begrenzt"
CompilerEndIf
CompilerEndIf
EndMacro
Macro StopFlagging(EnumerationName)
CompilerIf Defined(StartFlagging_#EnumerationName, #PB_Constant) = 0
CompilerError "StartFlagging fehlt: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
CompilerIf #StartFlagging_#EnumerationName = #PB_Compiler_Line
CompilerError "leerer Flagging-Block: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
CompilerIf Defined(StopFlagging_#EnumerationName, #PB_Constant)
CompilerError "Flagging bereits gestoppt: "+FlaggingQuote#EnumerationName#FlaggingQuote
CompilerEndIf
#StopFlagging_#EnumerationName = #PB_Compiler_Line - #StartFlagging_#EnumerationName
EndMacro
;} Ende Flagging-Makros
StartFlagging(Foo)
DoFlagging(Foo, a)
DoFlagging(Foo, b)
DoFlagging(Foo, c)
DoFlagging(Foo, d)
StopFlagging(Foo)
Debug #Flag_Foo_a
Debug #Flag_Foo_b
Debug #Flag_Foo_c
Debug #Flag_Foo_d