In order to further expose the new information, provided by "array.bi" in the upcoming
release version of: FBC 1.08.0 (currently still DEV status) I've written "arrayinfo.bi", in
order to 'get at the goods' in a comparatively simple way.
It contains currently only a Sub (ArrayInfo()) styled alike ScreenInfo() and, the for most
'match deciding' Function (ArrayType()) which returns: either static or dynamic (array).
The difference is:
ArrayInfo (Sub): spills everything contained in "array.bi" but since all arguments are
optional, the user decides which information is wanted/needed ...
ArrayType (Function): returns only 'is static' or 'is dynamic' (as Boolean).
Common to both is:
the Macro SetTypeArrayInfo(data-type) used to initialize the 'private overloaded'
versions of Sub/Function. (all common FB data-types, except ZString!)
All of them are called by the 'built-in' initializer and later discarded by FBC if not called.
Important NOTE:
If a user wants to employ a array of UDT, a explicit macro call is mandatory before
using above mentioned goodies (only the user knows her/his UDT's).
If "array.bi" is not loaded by user, "arrayinfo.bi" does so automatically (this means that
only a single
#Include statement is needed in the users code).
arrayinfo.bi:
Code: Select all
' arrayinfo.bi -- (c) 2019-09-05, MrSwiss
' extended with ArrayType() -- 2019-11-05
#Ifndef __FBC_INT_ARRAY_BI__ ' if NOT loaded yet ...
#Include "fbc-int/array.bi" ' load it now (otherwise nothing happens)
#EndIf ' __FBC_INT_ARRAY_BI__
#Ifndef __FBC_INT_ARRAYINFO_BI__
#Define __FBC_INT_ARRAYINFO_BI__ ' prevent multiple inclusion
#If __FB_LANG__ = "fb"
namespace FBC ' compatibility with array.bi
#EndIf
#Macro SetTypeArrayInfo(DataType) ' define datatype for overloaded procedures
Private Sub ArrayInfo OverLoad( _ ' get array header information
a() As DataType, _ ' _in_ mandatory: array as defined by macro
ByRef pidx As Any Ptr = 0, _ ' _out_ opt. pointer to lowest index (0, 0, ...)
ByRef pbase As Any Ptr = 0, _ ' _out_ opt. pointer to allocated memory
ByRef t_mem As UInteger = 0, _ ' _out_ opt. total memory (in Bytes)
ByRef e_len As UInteger = 0, _ ' _out_ opt. element size (dito)
ByRef dims_ As UInteger = 0, _ ' _out_ opt. number of dimensions
ByRef flag_ As UInteger = 0, _ ' _out_ opt. flags (all as one)
ByRef padim As FBARRAYDIM Ptr = 0 _ ' _out_ opt. pointer to internal type array
)
Dim As FBARRAY Ptr pa = _
ArrayDescriptorPtr(a()) ' get array descriptor ptr (pa)
pidx = pa->index_ptr ' see array.bi for explanation
pbase = pa->base_ptr
t_mem = pa->size
e_len = pa->element_len
dims_ = pa->dimensions
flag_ = pa->flags
padim = @(pa->dimTb(0))
End Sub
Private Function ArrayType OverLoad( _ ' dynamic or static array?
a() As DataType _ ' _in_ mandatory: array as defined by macro
) As Boolean ' FALSE = dynamic | TRUE = static
Dim As FBARRAY Ptr pa = _
ArrayDescriptorPtr(a()) ' get array descriptor ptr (pa)
If (pa->flags And FBARRAY_FLAGS_FIXED_LEN) Then _
Return TRUE ' 1 = static array (fix-len)
Return FALSE ' 0 = dynamic array (var-len)
End Function
#EndMacro
' initialize Arrayinfo with all common data types defined in FB (no ZString!)
' for UDT's you'll still have to make a explicit call to SetTypeArrayInfo(UDT)
SetTypeArrayInfo(Byte) ' 1 byte size (8 bit) ' integer types
SetTypeArrayInfo(UByte) ' 1 byte size (8 bit)
SetTypeArrayInfo(Boolean) ' 1 byte size (8 bit)
SetTypeArrayInfo(Short) ' 2 byte size (16 bit)
SetTypeArrayInfo(UShort) ' 2 byte size (16 bit)
SetTypeArrayInfo(Long) ' 4 byte size (32 bit)
SetTypeArrayInfo(ULong) ' 4 byte size (32 bit)
SetTypeArrayInfo(Integer) ' ptr size (32 or 64 bit)
SetTypeArrayInfo(UInteger) ' ptr size (32 or 64 bit)
SetTypeArrayInfo(LongInt) ' 8 byte size (64 bit)
SetTypeArrayInfo(ULongInt) ' 8 byte size (64 bit)
SetTypeArrayInfo(Single) ' 4 byte size (32 bit) ' float types
SetTypeArrayInfo(Double) ' 8 byte size (64 bit)
SetTypeArrayInfo(String) ' 3 x ptr size (32 or 64 bit) string header
' end initializer
#If __FB_LANG__ = "fb"
end namespace
#EndIf
#EndIf ' __FBC_INT_ARRAYINFO_BI__
' ----- EOF -----