Loading and saving documents


#1

Hey
I’m trying to learn how to load and save data using external files with Juce, but I’m having a bit of trouble getting started.
I’ve been reading through the Juce documentation, Juce forums, and looking through the source code of the Jucer app trying to figure it all out.
From what I understand so far, the FileBasedDocument class is what I should be using right?

In the application I’m building, I have a Juce OwnedArray which stores 48 instances of my own class, which in turn holds 9 int variables.
I would like to implement a system that enables the values of these 48 objects to be saved into an user-defined external file, which can then be loaded back into the application.

Can anyone please point me in the right direction to how I should implement this?
Thanks.


#2

Take a look at making a ‘toXML’ method for your class.

In your document, when save is triggered, make an XML instance, then go through each yourClass instance, and add the XML you get from it to the main XML.

Then output the resulting XML as a document.

That’s about the easiest, and you get an easy to handle document as a side benefit.

Bruce


#3

Cheers Bruce; once I figured it out using XML did the trick.
I abandoned the FileBasedDocument class in the end and used the FileChooser class to handle the load/save dialog boxes.