Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/howto/XMLPort


Ignore:
Timestamp:
Oct 11, 2008, 12:28:44 AM (16 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/howto/XMLPort

    v1 v1  
     1= HowTo: XML Loading =
     2[[TracNav(TracNav/TOC_Development)]]
     3
     4To make a new class XML-loadable, you have to do three things:
     5
     6== 1. Derive from !BaseObject ==
     7First the new class has to derive directly or indirectly from [wiki:BaseObject] (indirectly: deriving from another class following the same rule):
     8
     9MyClass.h file:
     10{{{
     11#include "core/BaseObject.h"
     12
     13class MyClass : public BaseObject
     14{
     15    public:
     16        MyClass();
     17        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     18
     19        ...
     20};
     21
     22or
     23
     24#include "OtherClass.h"
     25
     26class MyClass : public OtherClass // If OtherClass is a BaseObject too
     27{
     28    ...
     29};
     30}}}
     31
     32== 2. Create a Factory ==
     33Additionally you have to create a [wiki:Factory] for the new class. Use the [wiki:CoreIncludes CreateFactory] macro outside a function in a source file:
     34
     35MyClass.cc file:
     36{{{
     37#include "MyClass.h"
     38
     39CreateFactory(MyClass);
     40
     41// Constructor:
     42MyClass::MyClass()
     43{
     44    RegisterObject(MyClass);
     45}
     46
     47...
     48}}}
     49
     50== 3. XMLPort ==
     51At last you have to implement the [wiki:XMLPort] function for the new clss:
     52{{{
     53void MyClass::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     54{
     55    SUPER(MyClass, XMLPort, xmlelement, mode);
     56
     57    XMLPortParam(SomeClass, ...);
     58    XMLPortParam(SomeClass, ...);
     59    XMLPortParam(SomeClass, ...);
     60    ...
     61
     62    XMLPortObject(SomeClass, ...);
     63    ...
     64}
     65}}}
     66Read the related page to learn more about XMLPort and how to load parameters and subobjects:
     67 * [wiki:XMLPort]