Results 1 to 5 of 5

Thread: A way to get datatype-pattern?

  1. #1
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170

    A way to get datatype-pattern?

    To make it short- is there a way to store/retrieve the pattern/structure of a datatype?

    example:
    ' have two different types:
    Type t_A
     X as Byte
     Y as Long
    End Type
    
    Type t_B
      E as Ext
      D as Double
    End Type
    
    ' have some other type which can be a pointer to stored data of either type t_A or t_B
    Type t_foo
      theSubtype as ' unknown Type-Info
      ptrSubType as Dword
    End Type
    
    Dim foo(2) as t_foo
    
    foo(1).theSubtype = t_A  
    foo(1).ptrSubtype = Heap_Alloc(SizeOf(t_A)
    foo(2).theSubtype = t_B
     foo(2).ptrSubtype = Heap_Alloc(SizeOf(t_B)
    
    '...call a sub/function which is part of some other, multiple usable .tBasicU
    ' to not too complicate it, this sub "knows" expression "foo" in this example
     
    Sub InsideSub(Byval Index as Long) 
    ' where index is foo's(Index)
      
    Local data as foo(Index).theSubtype at foo(Index).ptrSubtype
    
    
    End Sub
    
    Now how can I replace/fill ".theSubtype" ? Is there a pointer or whatever to the type-defines/structures?

    Can I use
    thinBasic_VariableGetInfo()
    'or
    thinBasic_VariableGetInfoPtr()
    'or
    thinBasic_VariableGetInfoEx()
    
    onto some dummy-variable of t_A or t_B
    and how would that work to Dim As ... ?

    Edit: other thought
    ' have two different types:
    Type t_A
     X As Byte
     Y As Long
    End Type
     
    Type t_B
      E As Ext
      D As Double
    End Type
     
    ' have some other type which can be a pointer to stored data of either type t_A or t_B
    Type t_foo
      theSubtype As Long
      ptrSubType As DWord
    End Type
     
    Dim foo(2) As t_foo
    
    ' some empty dummy-array just borrow the name:
    Dim bType(2) As Byte
    
    Alias t_A As bType(1)
    Alias t_B As bType(2)
    
    ' ---------------------------------------------------
    ' but no work: Alias only works on keywords...
    ' --------------------------------------------------- 
    
    foo(1).theSubtype = 1
    foo(1).ptrSubtype = HEAP_Alloc(SizeOf(bType(foo(1).theSubtype))) 
    ' ...
      
    Sub InsideSub(ByVal Index As Long)
    ' where index is foo's(Index)
       
    Local data As bType(foo(Index).theSubtype) At foo(Index).ptrSubtype 
     
    End Sub
    
    Last edited by ReneMiner; 14-06-2013 at 11:49.
    I think there are missing some Forum-sections as beta-testing and support

  2. #2
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    Quite complex.
    Let me some time to understand it better about current possibilities and future development.

    If you were dealing with base data type like LONG, STRING, DWORD, EXT, ... not complex to develop something.
    But in this examples you are dealing with user data types so all info must be catched at runtime.
    ... thinking.
    Last edited by ErosOlmi; 16-06-2013 at 11:45.
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  3. #3
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    maybe is possible to think into a direction if there would be some TypeOf()-Function if there were a pointer to the storage-space (like SizeOf) of the UDT-pattern

    Type t_A
      Fish as Fin  ' don't care what's in here
      Bread as Dough
    End Type
    
    Type t_Foo
      P_Type as Dword  
      P_Ptr    as Dword
    End Type
    
    Dim foo() as t_Foo
    '...
    foo(1).P_Type = TypeOf(t_A)
    
    ' if this not possible, make some local dummy as UDT_ElementByte would need
    ' to read TypeOf from a variable:
    
    Local dummy as t_A
    
    foo(1).P_Type = TypeOf(dummy)
    
    '...
    Local data As foo(1).P_Type At foo(1).P_Ptr
    
    but would that work already or need an additional clause as
    Local data As UDT_Signature(foo(1).P_Type) At foo(1).P_Ptr
    
    Last edited by ReneMiner; 16-06-2013 at 15:19.
    I think there are missing some Forum-sections as beta-testing and support

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10
    TypeOf is something I like
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic MVPs
    Join Date
    Oct 2012
    Location
    Germany
    Age
    54
    Posts
    1,529
    Rep Power
    170
    Dig it out again because of "new idea"


    Since you already accepted UDT_ListElements-function as realizeable - we won't need a TypeOf()-function for UDTs now - maybe later.
    So TypeOf should just return for any variable the usual vartypes or simple "it's Union/Udt" so one knows there are still elements to seperate.
    It would be a great start and if this works the other stuff results from that base.

    Type t_type1
      A as Long
    End Type
    
    Type t_type2
      T1 as t_Type1
      B as Double
    End Type
    Dim foo as t_type2
    
    so if TypeOf(foo.T1) returns "Is_UDT", I could seperate the elements using UDT_ListElements and thereafter check typeOf for each single element until I reach the "usual" vartypes. I think this would not be too much effort - in comparison how often this will be used - this method will be enough for the start. If we got the skeleton once the built-on-top-of-this stuff will follow through simple evolution

    Edit: but has to "understand strings" - because thinBasic_VariableGetInfoEx does not respond to the subsets- so i could write
    string x() = UDT_ListElements(T1) 
    'or
    Dim x() as String
    Long numElements = UDT_ListElements(T1, X)
    ...TypeOf("foo."+ x(1)) ...
    
    Last edited by ReneMiner; 07-07-2013 at 18:44.
    I think there are missing some Forum-sections as beta-testing and support

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •