#include "../array.bi"
type testing_type
'' 3 dynamic arrays, with 0 - 9
integer_array as dynamicArray(integer) = 10
double_array as dynamicArray(double) = 10
string_array as dynamicArray(string) = 10
end type
dim as testing_type this_is_only_a_test
'' put crap in them
for i as integer = 0 to 9
this_is_only_a_test.string_array.data(i) = str( 10 - i )
this_is_only_a_test.integer_array.data(i) = 10 - i
this_is_only_a_test.double_array.data(i) = 10 - i
next
'' print em
print "Strings:"
print this_is_only_a_test.string_array
print
print "Integers:"
print this_is_only_a_test.integer_array
print
print "Doubles:"
print this_is_only_a_test.double_array
print
'' resize them, 0 - 19
this_is_only_a_test.string_array.redim(20)
this_is_only_a_test.integer_array.redim(20)
this_is_only_a_test.double_array.redim(20)
'' put crap in them
for i as integer = 10 to 19
this_is_only_a_test.string_array.data(i) = str( 10 - i )
this_is_only_a_test.integer_array.data(i) = 10 - i
this_is_only_a_test.double_array.data(i) = 10 - i
next
'' print em
print "Strings:"
print this_is_only_a_test.string_array
print
print "Integers:"
print this_is_only_a_test.integer_array
print
print "Doubles:"
print this_is_only_a_test.double_array
print
Yeah, there's a cast to string, so you can print arrays like a normal variable.
Last edited by cha0s on Jan 17, 2007 4:11, edited 2 times in total.
-Added copy ctors, to make 'var = dynamic_array' safe.
-Fixed CAST to return a pointer of type, instead of ANY.
-Iterated in dtor, if strings, to free string mem.
-Changed 'exit sub' to 'exit constructor' (You'll now need a pretty recent CVS to compile it...)
-The library now does not contain any information about itself's location anymore, due to preprocessor directives.
Last edited by cha0s on Jan 17, 2007 4:13, edited 2 times in total.
For a moment i was like.. what the.. since when FB supports templates (the "type dynamicArray( __TYPE__ ) part"), great trick :).
Btw, with data being stored in objects, you should never use #libpath or #inclib with absolute paths, for example, libarray.a includes: "D:\prg\fb\cha0s\chi\dynarray".
D:/FreeBASIC/Other/dynarray/tests/../array.bi(167) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( byte )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(167) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( byte )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(168) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( short )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(168) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( short )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(169) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( integer )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(169) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( integer )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(170) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( longint )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(170) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( longint )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(171) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( single )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(171) error 14: Expected identifier, found 'data' in 'DECLARE_DYNAMIC_ARRAY( single )'
D:/FreeBASIC/Other/dynarray/tests/../array.bi(171) error 124: Too many errors, exiting
attacke wrote:im afraid to do that... everytime i do it feels like a new programming language... everythin i have gets 100+ errors...
I'm like that but my situation's the opposite. When I update I'm afraid to use older versions because I tend to code cleanly with the newest features available. Oh wait nvr mind,
-lang deprecated
You should think about using it. Or -lang qb at least
Could it be possible to have a default property for a class/type? Something like "declare property foo default (parameters)" ? That way, you could make the data property default, so you could do array(index) instead of array.data(index) .