Version 2 (modified by smerkli, 12 years ago) (diff) |
---|
HowTo: XML Loading
TracNav(TracNav/TOC_Development)?
To make a new class XML-loadable, you have to do three things:
1. Derive from BaseObject
First the new class has to derive directly or indirectly from BaseObject? (indirectly: deriving from another class following the same rule):
MyClass.h file:
#include "core/BaseObject.h" class MyClass : public BaseObject { public: MyClass(); virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); ... }; or #include "OtherClass.h" class MyClass : public OtherClass // If OtherClass is a BaseObject too { ... };
2. Create a Factory
Additionally you have to create a Factory? for the new class. Use the CreateFactory? macro outside a function in a source file:
MyClass.cc file:
#include "MyClass.h" CreateFactory(MyClass); // Constructor: MyClass::MyClass() { RegisterObject(MyClass); } ...
3. XMLPort
At last you have to implement the XMLPort function for the new class:
void MyClass::XMLPort(Element& xmlelement, XMLPort::Mode mode) { SUPER(MyClass, XMLPort, xmlelement, mode); XMLPortParam(SomeClass, ...); XMLPortParam(SomeClass, ...); XMLPortParam(SomeClass, ...); ... XMLPortObject(SomeClass, ...); ... }
Read the related page to learn more about XMLPort and how to load parameters and subobjects: