Java has the Serializable class http://java.sun.com/developer/technicalArticles/Programming/serialization/ It lets you say:
class MyClass implements Serializable...
Which lets you do stuff like this:
MyClass x, y;
ObjectOutputStream oos = new ObjectOutputStream(file);
oos.writeObject(x);
ObjectInputStream ois = new ObjectInputStream(file);
y = (MyClass) ois.readObject();
Java handles saving all the member data to a file, and loading it back into your object.
ofxXmlSettings has something in this direction⌠but I propose:
1 ofxXmlSettings becomes part of the core as âofXmlâ (and incorporates code from elsewhere on the forum for using xml attributes).
2 We add a small class, ofSerializable:
class ofSerializable {
virtual TiXmlDocument saveXml() = 0;
virtual ofSerializable loadXml(TiXmlDocument& tree) = 0;
}
3 We add to ofXml:
class ofXml {
...
void addValue(ofSerializable& object, string tagName);
ofSerializable getValue(stringTagName);
}
So that objects like ofRect, ofPoint and ofColor can be loaded and saved from xml files more directly simply by implementing saveXml() and loadXml(), so we donât keep writing stuff like:
ofRectangle rect;
xml.setValue("rect:x", rect.x);
xml.setValue("rect:y", rect.y);
xml.setValue("rect:w", rect.w);
xml.setValue("rect:h", rect.h);
...
ofRectangle rect;
xml.getValue("rect:x", rect.x);
xml.getValue("rect:y", rect.y);
xml.getValue("rect:w", rect.w);
xml.getValue("rect:h", rect.h);
And instead can write:
ofRectangle rect;
xml.setValue("rect", rect);
...
ofRectangle rect;
xml.getValue("rect", rect);
This also provides a good framework for other classes that want to abstract away functionality for loading and saving their data.