Options
Structures within structures
Hi, can someone link me to a resource that can explain this? I can post more detail as to what's confusing me but if there's a good link I can just check that out to start.
Thanks
Answers
Maybe not the most useful but...
Cool thanks
If you go too big and too deep nesting structures you might not enjoying watching them in debug. If you try to mimic deep jason or xml nests debug can really suck.
I believe there is (or used to be) a hard limit on structure depth, like 5 deep or something like that? I've gone past it.
I'm still lost. Any other links available?
Since I ended up copying and pasting some code anyway, I'll post a simplified version of the structures I use to store room and device data...
(***********************************************************)
(* DATA TYPE DEFINITIONS GO BELOW *)
(***********************************************************)
structure deviceip {
char name[32]
char ipaddr[20]
integer ipport
integer iptype
dev devid
}
structure displaysettings {
char name[32]
integer type
dev devid
dev vdvdevid
integer commtype
deviceip ipcomm[1] //THIS IS PUTTING THE STRUCTURE ABOVE INTO THIS STRUCTURE
char sercomm[64]
integer pwr
integer vmute
integer feed
integer follows
integer status
integer swtid //VGA Switch ID
char vport[16] //VGA Port Number
integer chan
integer amute
integer vol
integer volset
integer tmp
integer ipconnect
integer ipdone
integer init
char text[32]
char buffout[1024] //holds buffer of integer commands as string data for fifo operations
char buffin[512]
char lastacmd[512]
integer lastcmd
}
structure audchans {
char name[20]
integer unit
integer id
integer chan
integer val
integer mute
integer volset
}
structure audiodata {
char name[32]
integer type
integer init
char sernum[16]
audchans ch[30] //THIS PUTS THE AUDIOCHANNELS ABOVE INTO THIS STRUCTURE
}
structure inputs {
char name[32]
integer swtid //VGA Switch ID
char vport[16] //HDMI Switch Video Port (nornally Aud and Vid)
char aport[16] //HDMI Switch Audio Port (Use separate Aud/Vid for oddball stuff)
integer follows
}
//THIS IS THE MAIN, TOP-LEVEL STRUCTURE:
structure room {
char name[32]
char dbid[12]
integer status
displaysettings d[21] //PUTS DISPLAY STRUCTURE (WITH IP SUB_STRUCTURE) IN THIS STRUCTURE
audiodata audio[1] //PUTS AUDIO DATA STRUCTURE & SUB_STRUCTURES INTO THIS STRUCTURE
inputs in[16] //PUTS INPUT DATA STRUCTURE INTO THIS STRUCTURE
helpdata help[1]
}
...then all I have to do to define the whole structure and sub-structure
(***********************************************************)
(* VARIABLE DEFINITIONS GO BELOW *)
(***********************************************************)
DEFINE_VARIABLE
persistent room rm[2] //THIS DEFINES TWO ROOMS with all the data cells of the sub-structures underneath them
Then to get to any cell in the structure:
stored_volume = rm[this_rm].d[this_device].a[1].ch[this_ch].val
...hope that helps if you're still struggling with building and using structures.
This is not true, we write nested structures to XML all the time. In some cases up to 5 levels.
I use variable to string and string to variable to pass updated structures, a single level, from modules back to the main all the time and use variable to xml to store data on the flash that are 3 levels deep. I've never noticed corrupted data but to be honest I haven't looked for it either.
Thanks everyone I figured it out.