Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

WithPolyXML

 

template <class T>

class WithPolyXML : public WithFactory<T

T

Type of base class of polymorphic hierarchy.

This template class implements the base behaviour of polymorphic classes that needs to be streamed in XML format.

 

 

template <class T>

class PolyXMLArray : public Array<T

T

Type of base class of polymorphic hierarchy.

This template class implements the base behaviour of an XML-streamable polymorphic Array container.

 

 

template <class K, class T>

class PolyXMLArrayMap : public ArrayMap<K , T

T

Type of base class of polymorphic hierarchy.

This template class implements the base behaviour of an XML-streamable polymorphic ArrayMap container.

 

 

template <class K, class T>

class PolyXMLArrayMapOne : public ArrayMap<K , One<T> > 

T

Type of base class of polymorphic hierarchy.

This template class implements the base behaviour of an XML-streamable polymorphic ArrayMap container, where Value type is of type One<T>.

 

 

 

Basic usage

 

To implement the polymorphic XML behaviour in your base class, just derive from WithPolyXML template :

 

class MyBaseClass : public WithPolyXML<MyBaseClass>

{

        public:

            virtual void Xmlize(XmlIO xml);

};

Then you can derive your class hyerarchy from base, as usual :

 

class MyDerivedClass : public MyBaseClass

{

        public:

            virtual void Xmlize(XmlIO xml);

};

 

The Xmlize() virtual member function must be defined in each class in the hierarchy; its purpose is to XML-ize ONLY the direct members of the class. Because of that, in each derived class you must call AT FIRST the parent's class Xmlize() from inside it; here an example:

 

void MyBaseClass::Xmlize(XmlIO xml)

{

        xml

            ("FirstBaseMember", FirstBaseMember)

            ("SecondBaseMember", SecondBaseMember)

        ;

}

 

void MyDerivedClass::Xmlize(XmlIO xml)

{

        MyBaseClass::Xmlize(XmlIO xml);

        xml

            ("FirstDerivedMember", FirstDerivedMember)

            ("SecondDerivedMember", SeconDeriveddMember)

        ;

}

Don't forget to register your classes by REGISTERCLASS macro, see WithFactory help topic about it.

Then, you must declare the class container :

 

class MyXMLContainer : public PolyXMLArray<MyXMLContainer>

{

};

 

That's all. Now you can construct your classes, add them to container which behaviour is identical to Array's one, and stream the container in XML format :

 

Create classes and container :

MyBaseClass * baseClass = new MyBaseClass;

MyBaseClass * derivedClass = MyBaseClass::CreatePtr("MyDerivedClass");

MyXMLContainer myContainer;

myContainer.Add(baseClass);

myContainer.Add(derivedClass);

 

Stream container into a string :

String s = StoreAsXML(myContainer, "aTagName");

 

Reload container from a string :

myContainer.Clear();

bool  res = LoadFromXML(myContainer, s);

 

Store container into an xml file :

bool res = StoreAsXMLFile(myContainer, "aTagName", "a/file/path.xml");

 

Reload container from an xml file :

myContainer.Clear();

bool res = LoadFromXMLFile(myContainer, "a/file/path.xml")

 

Do you want to contribute?