'Object' equivalent for basic types?

BlitzMax Forums/BlitzMax Beginners Area/'Object' equivalent for basic types?

impixi(Posted 2007) [#1]
I'd like to write a function that runs different code based on a passed array parameter's type. NON-working example:


SuperStrict

Local ByteMap:Byte[5,15]

Local IntMap:Int[5,15]

ProcessArray ByteMap
ProcessArray IntMap

End

Function ProcessArray(arr:Object[,] Var)
	
	If Not arr Then Return
	
	If Byte[,](arr) Then Print "Bytes"
	If Int[,](arr) Then Print "Ints"
	If Long[,](arr) Then Print "Longs"
	If Float[,](arr) Then Print "Floats"
	If Double[,](arr) Then Print "Doubles"
	
EndFunction



Is there a way to do this?


A functional Object-based equivalent would be:


SuperStrict

Local ByteMap:TByte[5,15]
ByteMap[0,0] = New TByte

Local IntMap:TInt[5,15]
IntMap[0,0] = New TInt

ProcessArray ByteMap
ProcessArray IntMap

End

Function ProcessArray(arr:Object[,] Var)
	
	If Not arr Then Return
	
	If TByte(arr[0,0]) Then Print "Bytes"
	If TInt(arr[0,0]) Then Print "Ints"
	If TLong(arr[0,0]) Then Print "Longs"
	If TFloat(arr[0,0]) Then Print "Floats"
	If TDouble(arr[0,0]) Then Print "Doubles"
	
EndFunction


Type TByte
	Field f:Byte
EndType

Type TInt
	Field f:Int
EndType

Type TLong
	Field f:Long
EndType

Type TFloat
	Field f:Float
EndType

Type TDouble
	Field f:Double
EndType 


Basically, I want a generic function that handles all types rather than writing a function for every type: ProcessByteArray, ProcessIntArray, ProcessDoubleArray, etc.


MGE(Posted 2007) [#2]
well if you're going to do an IF check anyway in the function....

"If TByte(arr[0,0]) Then Print "Bytes""

Then just pass another param telling you the type of array and process the IF on that param. ;)


Brucey(Posted 2007) [#3]
There is a reflection module in development at BRL that might be able to do the things you are after.

Well, it's the sort of thing a reflection module *should* be able to do.. :-)


Czar Flavius(Posted 2007) [#4]
If you are using normal Ints etc I don't think these are counted as objects, which might be why the first example does not work.


Who was John Galt?(Posted 2007) [#5]
Try 'if byte[][]' arr'. No Max here to try it on, just a guess.