Hot Door CORE Forum
structs and arrays in dictionaries - Printable Version

+- Hot Door CORE Forum (http://hotdoorcore.com/forum)
+-- Forum: All forums (http://hotdoorcore.com/forum/forumdisplay.php?fid=1)
+--- Forum: General discussion (http://hotdoorcore.com/forum/forumdisplay.php?fid=3)
+--- Thread: structs and arrays in dictionaries (/showthread.php?tid=173)



structs and arrays in dictionaries - Rick Johnson - 05-30-2018

I've been using document dictionaries to store document-specific settings and it works great! Now I need to store arrays of a struct (each struct containing angles, doubles, artboard rects, and artboard points), and I'm unsure how to best handle either arrays or structs. Perhaps the structs would be best handled as sub-dictionaries. It seems too easy to be true to simply pass an address of an array to IllustratorDictionary and expect it to be restored intact later. Any recommendations for storing arrays of structs in a document dictionary would be very much appreciated!


RE: structs and arrays in dictionaries - garrett - 05-31-2018

There's really no magical/easy way to turn a platform-specific array or object in memory into something persistent (via document data) that can later be properly restored to memory on any given platform.

In general, you'll have to fill out an Illustrator document dictionary with key/value pairs that represent members in a given object. If your object has subobjects then your Ai dictionary will have to utilize subdictionaries.

Again, in general, you'll have to loop over an array and store each item in an Illustrator document array. If your array stores objects then your Ai array will have to store Ai subdictionaries.

In either case, you'll have to read the data out of the Ai dictionary or array and construct the proper type of object or array in memory later on.

Either container type can store just about any primitive type. If you want to store something more complicated than a primitive in an Illustrator container type, I recommend using the hdi::core:TonguerefData hierarchy of classes. You can stringify the data in a PrefData-based object to a JSON string, and of course the aforementioned Illustrator container types can store strings. Later, when reading said strings, you can create a PrefData object from parsing the JSON string.


RE: structs and arrays in dictionaries - Rick Johnson - 05-31-2018

Thanks, Garrett, this is all I need to know.

I'll just store the angles I need as doubles to simplify things.

It's interesting that ai::Array and ai:Big Grinictionary are so similar, except that one identifies entries by an index and the other with a key.

Thanks!