Structure Output

Just.Jake's picture

I've been working on a little patch for a few days now, and I'm almost done. I've got all my internal figuring done. All I need to do is output a Structure. I have 2 issues:

  • I need to create a structure that contains an unknown quantity of other structures, as I make one structure per visible window
  • I want to include an image in each substructure

I've seen native QC patches output structures that seem to be arrays, rather than dictionaries, as they don't have the key:value or key:object format. Instead, they have [indexnumber]:object, or somesuch. My substructures, I know exactly how many items they'll have, and a dictionary, and its key:object format makes sense for them. The substructures contain my image object, which is a subclass of NSObject that conforms to <QCOutputImage>.

My questions:

  • how do I get the value of a key:value pair in a dictionary, and return null/nil if the dictionary does not have that key?
  • how do I create this array-like structure?
  • how do I create an indeterminent number of dictionaries in the array-structure that each contain the keys image: PID:, and optionally, if that data is availible from the first request, the keys name:, workspace: and truewindow:?

I can handle the data gathering.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

tobyspark's picture
you coding a plug-in or making a macro patch?

if you're coding a plug-in, you can declare your output to be of type NSArray instead of NSDictionary. Not properly documented that, but certainly helps. You could check the source of my SPK-StringToImageStructure plugin to get an idea of using dictionaries and arrays in the output.

if you're making a macro patch... good luck to you =]


cwright's picture

you can iterate of a dictionary's keys or values array ([myDict keys] or [myDict values] I believe) to see what's inside. Alternatively, you can just query the dict for the object with a given key, and it'll return nil if it's not found (i.e. [myDict objectForKey:@"foo"] will return nil if no key foo exists).

creating an array-like structure is done with the initWithArray method (not quite sure how it's exported in the official API, but toby addressed this anyway I think)

variable numbers of substructures isn't a problem at all (gltools, kineme3d, and opencv all handle variable-length structures without any magic or handwaving) -- simply add all the dictionaries/arrays you want to export into a parent dictionary/array, and use the parent array/dictionary to create the QCStructure object.