Page 2 of 2

Posted: Wed Nov 06, 2002 12:06 pm
by BackupUser
Restored from previous forum. Originally posted by Froggerprogger.

Wouldn't it be useful to use something like "structures in arrays in a list?"
For Example something like:

Code: Select all

Structure car ;Define structure cars  typ.s
  speed.l
  color.s
EndStructure

Structure child ;Define structure child with array inside
  name.s
  age.l
  hobbys.s[10]
EndStructure

Structure person ;Define Struture person with Arrays AND Structures in structures inside
  name.s
  age.s
  car.car
  parents.s[2]
  children.child[10]
EndStructure

Global date1.person ;defines a Variable of type person
date1\car\typ = "Ford" ;struct. in struct.
date1\parents[1] = "Mum" ;array in struct.
date1\children[1]\name = "Mary" ;struct. in array in struct.
date1\children[1]\age = 25
date1\children[1]\hobbys[1] = "hangin' around" ;array in array in struct
date1\children[2]\name = "Joana"
date1\children[2]\age = 35

Dim alldates.person(10) ;defines an array of type person
alldates(1)\children[2]\name = "Johanna" ;struct. in array in array

;______________ And here the favourite ::
NewList alldataLIST.person() ;defines a list of type person
AddElement(alldataLIST())
alldataLIST()\children[2]\name ="Jeans" ; --> struct. in a array in a list (!)
?
You can do ALL with Lists but Lists in Lists.
(is this grammatically correct?)

Purebasic - what a nice name for a girl-friend

Posted: Wed Nov 06, 2002 1:20 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

@Froggerprogger:

I know this possibillity but the problem is that you have to "pre-define" the dimension depth. That need a heavy amount of memory and you are limited to the depth. That is what I want to obmit.

Anyway, thanks for answer. :)

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Thu Nov 07, 2002 4:27 pm
by BackupUser
Restored from previous forum. Originally posted by webmatze.

Is there a way to make a copy of a LinkedList?

I have a LinkedList and want to put all the values in another LinkedList!

Registered Purebasic User.
Using Windows XP on an AMD System...

Posted: Thu Nov 07, 2002 8:49 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.

One way could be to copy each element from one list to the other in a While/ Wend loop. But possible there is a "CopyMem" Methode.
Try the SizeOf() command.

Mike

Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
System: Windows 2000 Server, 512 MB Ram, GeForce4200 TI 128 MB DDR, Hercules Theater 6.1 DTS Sound

Posted: Thu Nov 07, 2002 10:27 pm
by BackupUser
Restored from previous forum. Originally posted by freak.

Well, the Problem is, that you don't know, where in Memory your Data is, as it is allocated dinamically. You only know, where the current Element is. So you could do something like this

Code: Select all

Structure ListStruct
  value.l
  whatever.b
  somedata.l
EndStructure

NewList OldList.ListStruct()
NewList NewList.ListStruct()

; now fill OldList with some Elements.

; copy routine follows...

ClearList(NewList())  ; clear new List
ResetList(OldList())  ; reset old List to start

While NextElement(OldList())  ; loop through Elements
  AddElement(NewList())  ; add Element to new List
  CopyMemory(@OldList(), @NewList(), SizeOf(ListStruct))
     ; copy the whole data from the current Element of OldList to NewList
Wend

; now NewList has the Same Elements as OldList.

--------
Hope this explains it a bit. But I don't know, if this works with Strings in the Structure, as i don't think they are stored in the List's memory. (just as it is with Structures)

Timo

--------------------------------
Programming today is a race between software engineers striving to build bigger and
better idiot-proof programs and the universe trying to produce bigger and better idiots.

...So far, the universe is winning.

Posted: Fri Nov 08, 2002 9:58 pm
by BackupUser
Restored from previous forum. Originally posted by webmatze.

Thanks for you help!
I'm working on a XML parser and I wanted to store XML tags in Linked Lists but now I did it in another way!
Btw, I finished a working version of this parser. If you are interested I will release the code.

Registered Purebasic User.
Using Windows XP on an AMD System...

Posted: Sat Nov 09, 2002 9:49 am
by BackupUser
Restored from previous forum. Originally posted by fweil.

webmatze, you should post this XML parser on the tricks'n tips if it is of an acceptable size or on the ressource site for competing (!)

Rgrds

Francois Weil
14, rue Douer
F64100 Bayonne

Posted: Wed Nov 20, 2002 8:51 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by Pupil

why not use pointers in your structure to another structure, something like this:

Code: Select all

structure StreetType
  name.s
  nr.w
  *parent
  *child
endstructure

structure DataBaseType
  name.s
  etc.l
  *street
endstructure

newlist streets.StreetType()
newlist database.DataBaseType()

; ok now add an entry
addelement(database())
addelement(streets())
database()\name = "Vain"
database()\street = @streets()
*ptr.StreetType = @streets()
street()\name = "somewhere"
; he lives on another address too so..
addelement(street())
street()\name = "somewhere else"
*ptr\child = @street()

; now you can access this structure like this
resetlist(database())
while nextelement(database())
  *ptr = database()\*street
  if *ptr ; we have a street
    debug *ptr\name
    while *ptr\child
      *ptr = *ptr\child
      debug *ptr\name
    wend
  endif
wend
well something like that, i haven't tested because i'm at work at the moment, but the logic should be ok...
Pupil, I get an error "A variable in a structure needs a declared type"??? I'd love to learn more about the way you think, pointer stuff I know nothing about, need a guru to refer to :)

Fangles woz ear orright den?

Posted: Wed Nov 20, 2002 2:16 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.

>Pupil, I get an error "A variable in a structure needs a declared
>type"??? I'd love to learn more about the way you think, pointer
>stuff I know nothing about, need a guru to refer to :)

This was quite some time ago, what was i thinking? -beats me :wink:
You could probably get the example to work by inserting .l after the *pointer(in structure) variables, but i discovered (when using this technique in an actual application) that droping the '*' characters makes the source more readable (at least i think it does):
'var1\*child'
versus
'var1\child'

so change the structures to something like this:

Code: Select all

Structure ExampleStruct
  name.s
  var1.l
  child.l ; pointer to a child object
  parent.l ; pointer to a parent object
EndStructure
The way i'm doing things here is just mimicing how the LinkedList library works and how Linked lists work in general.

If something is unclear please say so and i'll try to explain it a little better...

Posted: Fri Nov 29, 2002 7:08 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
Originally posted by Pupil

>Pupil, I get an error "A variable in a structure needs a declared
>type"??? I'd love to learn more about the way you think, pointer
>stuff I know nothing about, need a guru to refer to :)

This was quite some time ago, what was i thinking? -beats me :wink:
You could probably get the example to work by inserting .l after the *pointer(in structure) variables, but i discovered (when using this technique in an actual application) that droping the '*' characters makes the source more readable (at least i think it does):
'var1\*child'
versus
'var1\child'

so change the structures to something like this:

Code: Select all

Structure ExampleStruct
  name.s
  var1.l
  child.l ; pointer to a child object
  parent.l ; pointer to a parent object
EndStructure
The way i'm doing things here is just mimicing how the LinkedList library works and how Linked lists work in general.

If something is unclear please say so and i'll try to explain it a little better...
I changed it but I don't understand working with pointers so I can't fix any errors. Working with linked list I can normally handle.

for this line, I get the error "street()\name = "somewhere" is Not an array, function or linked list"

Fangles woz ear orright den?

Posted: Fri Nov 29, 2002 10:25 am
by BackupUser
Restored from previous forum. Originally posted by Pupil.

> for this line, I get the error "street()\name = "somewhere" is Not an array, function or linked list"

Upps, sorry :wink: that's a typo, should really be 'streets()\name = "somewhere"' because streets() is the linked list variable name. If you need more help just post here or mail me. Pointers may seem a bit abstract at first, but it's really very logical when you grasp it, so don't give up, it's a very powerfull tool when handled correctly..