This information concerns XmlCppClassGenerator versions 1.1 and before, please refer to XmlFileContent for documentation on the current version.
Table of contents:
Nota bene: The structure of the XML class description files is completely described by the XML schema file XmlCppClassGenerator.xsd file. In case there is an inconsistency between the aforementioned file and this page, the truth is always contained in the XML schema file.
This package uses a class description written in a XML file to generate header and implementation files. In this page are presented the structure of the XML file. In order to prevent errors when the C++ files are generated, the XML file is validated against the XML schema with xmllint, and any error will be reported and the execution stopped.
Any XML class description file you define should look like the following example:
<?xml version="1.0" encoding="UTF-8"?>
<classes xmlns="http://www.w3schools.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com !XmlCppClassGenerator.xsd">
<classes>
Note that the encoding is UTF-8, this cannot be changed unless the Translations.xml file is changed as well and the default python encoding is set accordingly (I had a hard time setting python's encoding to UTF-8).
In the classes root element can be as many class or struct element nodes as wanted.
class element nodeAn example of class is given here below:
<class>
<name> ExampleClass </name>
<author> George C. Clark </author>
<date> 27th November 2011 </date>
<comments> true </comments>
<inherits access="public"> std::string </inherits>
<inherits access="protected" virtual="true"> std::vector< double > </inherits>
<headerInclude> string </headerInclude>
<headerInclude> vector </headerInclude>
<implementationInclude> iostream </implementationInclude>
<headerUsedNamespace> std </headerUsedNamespace>
<implementationUsedNamespace> std </implementationNamespace>
<public>
<constructor>
<argument type="unsigned" const="true" ref="true" default="0"> nbr </argument>
</constructor>
<copyConstructor> true </copyConstructor>
<affectationOperator> true </affectationOperator>
<comparisonOperator> true </comparisonOperator>
<method>
<return type="bool"/>
<name> isGreaterThan </name>
<argument type="unsigned" const="true" ptr="true" ref="true"> testNbr </argument>
</method>
<member type="std::string" static="true" value=""Hello World!"" stdGet="false" stdSet="false">
StupidMessage
</member>
</public>
<protected>
<member type="int" stdGet="true" stdSet="true" ptrGet="true" ptrSet="true"> AnotherCounter </member>
</protected>
<private/>
</class>
The presented example illustrates many features of the structure.
name, author are mandatory (and self-explanatory). date is the creation date, used in the comments, and is mandatory as well. comments element is not mandatory, and its default value is true, i.e. doxyygen comments will be generated unless the element is present and set to false. inherits element(s) are optional, and defines the class's parents (in order of appearance). The inherits element has two optional attributes: access which set the access specifier can take the public (default), protected and private values, and virtual which defines whether the inheritance is virtual or not can take either the false (default) or true values. Please note that '<' and '>' characters cannot appear in any xml valid element, they must be replaced by '<' and '>' respectively! headerInclude element(s) defines which #include should be added in the header file, these elements have an optional attribute local which alters the rendering of the #include statement in the output files: false (the default) uses #include <foo> (as usually done for system headers), whilst true uses #include "foo.hpp" (as usually done for user headers). The implementationHeader optional element has the same behaviour (and the same optional attribute) for the class implementation file. headerUsedNamespace and implementationUsedNamespace define the using namespace statements used either in the header or in the implementation file. There can be any number of these elements. public element is mandatory, and must at least contain one constructor element. It can contain as many method and member children nodes. constructor element can contain as many argument as wanted. argument element as one mandatory attribute type which is the type of the given argument (int, double, etc.) and four optional ones: const which set on/off the constness of the argument (default is false), ref which tells if the argument is passed by value (false, default) or by reference (true), ptr which tells whether the argument is a pointer (true) or not (default), and default which can be used to set a default value for the argument. The value of the element is the argument name. copyConstructor contains only one data value which can be either true or false (default). When set to true a copy constructor will be automatically added to the list of constructors, and its body will be written as well. There can be at most one copyConstructorelement. If by chance it is present in several places (e.g. in public and in private), only the first occurrence will be taken into account. affectationOperator contains only one boolean data field too, with default value set to false. When set to true it triggers the addition of the affectation operator: MyClass& operator=( const MyClass & myClass );
The body of the method is also automatically generated from the list of non static members. If by chance it is present in several places (e.g. in public and in private), only the first occurrence will be taken into account.
comparisonOperator contains as well only one boolean data field, with default value false. It triggers the addition of a comparison method: bool operator==( const MyClass & myClass ) const;
Again the method body is generated automatically. If by chance it is present in several places (e.g. in public and in private), only the first occurrence will be taken into account.
A method has mandatory return and name elements, defining
the return type and the method name. It can have as many argument elements as desired, and has an optional const element, which sets the const switch of the method (a const method cannot modify the calling instance members), which default value is false. Other boolean optional elements are static, virtual and pureVirtual, all of them having false as default value, and indicate if the method is static, virtual or pure virtual.
The return element has as one mandatory attribute type which is the type of the returned variable (int, void, etc.) and four optional ones: const which set on/off the constness of the returned value (default is false), ref which tells if the returned value is passed by value (false, default) or by reference (true), and ptr which tells whether the returned value is a pointer (true) or not (default).
member element element as one mandatory attribute type which is the type of the given member (int, double, etc.) and nine optional ones: const which set on/off the constness of the member (default is false), ref which tells if the member is a value (false, default) or a reference (true), ptr which tells whether the member is a pointer (true) or not (default), static which indicates if the member is static (true) or not (false, default), value which sets the value of the member when it is static. stdGet, stdSet, both having a default value set to true control the production of standard get and set methods, ptrGet and ptrSet control the production of pointer get and set methods (see [AutomatedBehaviour#Automatic_methods Automatic methods]). The protected and private elements are optional and can contain again any number of constructor, method, and member elements.
In order to create a structure instead of a class, the class element node name has to be replaced by struct. The contents of such an element node is almost identical to the one describing a class. The two differences are :
destructor, which goes just before the public element node, and contains a boolean value. If this element node is not present, it is assumed that no destructor is wanted. Here below is given an example: <struct>
<!-- ... -->
<implementationUsedNamespace> std </implementationUsedNamespace>
<destructor> true </destructor>
<public>
<!-- At least one child element... -->
</public>
<!-- ... -->
</struct>
If the described object is a template, then the contents of the template< ... > coming before the object declaration must be determined. For each element present in the template< ... > line, a template element node must be added to the object description, between comments and inherits. The template element contains a value which is the alias used for the type, and a keyword attribute setting the used keyword. For instance, to get template< typename T >, the following line must be written
<template keyword="typename"> T
</template>
whilst getting template< class MyClass > requires
<template keyword="class"> MyClass </template>
In the same way, a method (or constructor) of an object can be a template. In this case the method (or constructor) element first child is a template element, using the same syntax as here above.