How to determine if variable is a valid Structure?

Just starting out? Need help? Post your questions and find answers here.
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

How to determine if variable is a valid Structure?

Post by skywalk »

I already use a Map of known structures, but curious if there is another way to pass the variable contents to the Defined compiler function?

Code: Select all

Define.s myVar$ = "RECT"
NewMap mapSTRUCT.i()
mapSTRUCT("RECT") = 1
Debug Defined(RECT, #PB_Structure)
Debug mapSTRUCT(myVar$)               ; 1
Debug Defined(myVar$, #PB_Structure)  ; 0
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: How to determine if variable is a valid Structure?

Post by mk-soft »

You can check with Defined
#PB_Constant
#PB_Variable
#PB_Array
#PB_List
#PB_Map
#PB_Structure
#PB_Interface
#PB_Procedure
#PB_Function
#PB_OSFunction
#PB_Label
#PB_Prototype
#PB_Module
#PB_Enumeration

Code: Select all

Define.s myVar$ = "RECT"
NewMap mapSTRUCT.i()
mapSTRUCT("RECT") = 1
Debug Defined(RECT, #PB_Structure)
Debug mapSTRUCT(myVar$)               ; 1
Debug Defined(myVar$, #PB_Structure)  ; 0

Debug Defined(myVar$, #PB_Variable)   ; 1
Debug Defined(mapSTRUCT, #PB_Map)     ; 1
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to determine if variable is a valid Structure?

Post by skywalk »

Yes, I know Defined(), but I'm trying to trick it with the contents of my string variable.
Defined("RECT", #PB_Structure) = 0
I am parsing C headers and need to keep valid Struct's when encountered.
Now I must use a pre-filled mapSTRUCT().
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: How to determine if variable is a valid Structure?

Post by Demivec »

skywalk wrote:I already use a Map of known structures, but curious if there is another way to pass the variable contents to the Defined compiler function?

Code: Select all

Define.s myVar$ = "RECT"
NewMap mapSTRUCT.i()
mapSTRUCT("RECT") = 1
Debug Defined(RECT, #PB_Structure)
Debug mapSTRUCT(myVar$)               ; 1
Debug Defined(myVar$, #PB_Structure)  ; 0
I would say no. 'Defined' is a compiler function and so isn't of any use based on changeable data at runtime (such as your string contents).
skywalk wrote:I am parsing C headers and need to keep valid Struct's when encountered.
Now I must use a pre-filled mapSTRUCT().
Constructing a collection of the valid parsed Structures would seem to be the only viable solution.
User avatar
skywalk
Addict
Addict
Posts: 4004
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: How to determine if variable is a valid Structure?

Post by skywalk »

Thanks Demivec, I was making sure no other way to access the known resident Structures.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Post Reply