Menu

XmlFileContent

Anonymous

Navigate through the wiki

Table of contents:

  • The XML class description file
  • XML header and root element
  • The class element node
  • Concerning templates

The XML class description file

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.

Back on top

XML header and root element

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.

Back on top

The class element node

An 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> 
     <parent> std::string </parent> 
   </inherits>  
   <inherits> 
    <access> protected </access> 
    <virtual/> 
    <parent> std::vector&lt; double &gt; </parent> 
   </inherits> 
   <include> 
     <file> string </file> 
     <header> true </header> 
   </include> 
   <include> 
     <file> vector </file> 
     <header/> 
   </include> 
   <include> 
     <file> iostream </file> 
   </include> 
   <usedNamesapce> 
     <namespace> std </namespace>  
     <header/> 
   </usedNamesapce> 
   <usedNamesapce> 
     <namespace> std </namespace> 
   </implementationNamespace> 
   <public> 
     <constructor> 
       <argument> 
         <type> unsigned </type> 
    <const> true </true> 
    <ref> true </ref> 
    <default> 0 </default> 
    <name> nbr </name> 
      </argument> 
     </constructor> 
     <copyConstructor> true </copyConstructor> 
     <affectationOperator/>     <comparisonOperator>     <destructor/>     <method> 
       <return>         <type> bool </type> 
       </return> 
       <name> isGreaterThan </name> 
       <argument> 
       <type> unsigned </type> 
       <const> true </const> 
       <ptr> true </ptr> 
       <ref> true </ref> 
       <name> testNbr </name> 
       </argument> 
     </method> 
       <member> 
       <type> std::string </type> 
       <static> true </static> 
       <value> &quot;Hello World!&quot; </value> 
       <stdGet> false </stdGet> 
       <stdSet> false </stdSet> 
       <name> StupidMessage </name> 
     </member> 
   </public> 
   <protected> 
     <member 
     <type> int </type> 
     <stdGet> true </stdGet> 
     <stdSet> true </stdSet> 
     <ptrGet> true <ptrGet> 
     <ptrSet> true </ptrSet> 
     <name> AnotherCounter </name> 
     </member> 
   </protected> 
   <private/> 
 </class>

The presented example illustrates many features of the structure.

  • The class name, author are mandatory (and self-explanatory).
  • The date is the creation date, used in the comments, and is mandatory as well.
  • The 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. An empty present element will result in the comments to be produced.
  • The inherits element(s) are optional, and defines the class's parents (in order of appearance). The parent object is specified in the mandatory parent child node. The inherits element has two optional child nodes: 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 '&lt;' and '&gt;' respectively! If a virtual child node is present and empty, then the inheritance relation is virtual.
  • The optional include element(s) has a mandatory child node file which defines which #include should be added in the produces files. It also has two optional child nodes: 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) and header which default is false performs the inclusion in the implementation file. In case those elements are present and empty, the true value is used.
  • The optional usedNamesapce element defines the using namespace statements used. The namespace name is set in the mandatory child node namespace. The optional child node header (default value is false) allows to use the namespace either in the header or the implementation file. There can be any number of these elements.
  • The public element is mandatory, and must at least contain one child node. ment. It can contain as many constructor, method and member children nodes.
  • A constructor element can contain as many argument as wanted.
  • An argument element as two mandatory children type, which is the type of the given argument (int, double, etc.) and name which indicates the argument variable name. Four optional childrens are: 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 optional element 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.
  • The optional element 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.

  • The optional element 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 destructor empty child node can be added too, which triggers the addition of a virtual destructor to the object. Once more if such a child node is present in multiple places, only the first occurence will be taken into account. If the object is a class and no destructor was manually added, a public one will automatically be added to the class definition. The destructor child node must appears just after the constructor ones (or first if no constructor nodes are present).
  • 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 child node 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).

  • A member element element as two mandatory child nodes type which is the type of the given member (int, double, etc.) and name which is the member name. The member name has to start with a capital letter. There are ten optional child nodes:

    • 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.

There are switches allowing to generate automatic methods:

  • 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 Automatic methods).
  • refGet controls the addition of the getter by reference, which allows to modify the instance.
  • 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 identical to the one describing a class.

For most of the optional child nodes containing a boolean value, the element node can be let empty, in which case the value is assumed to be opposite to the default value, e.g. <const> true </const> for an argument can be replaced by <const/>.

Back on top

Concerning templates

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 two child nodes, which are identifier (the alias used for the type), and a keyword setting the used keyword. For instance, to get template< typename T>, the following line must be written:

 <template> 
   <identifier> T </identifier> 
   <keyword> typename </keyword> 
 </template>

whilst getting template< class MyClass > requires

 <template> 
   <identifier> MyClass </identifier> 
   <keyword> class </keyword> 
 </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.

Back on top


Related

Wiki: Home
Wiki: MainPage
Wiki: WikiMap
Wiki: XmlFileContent
Wiki: XmlFileContent1dot1AndBefore

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.