Menu

ExamplesOutput1dot1AndBefore

Anonymous Johan Luisier

Navigate through the wiki

This information concerns XmlCppClassGenerator versions 1.1 and before, please refer to ExamplesOutput for documentation on the current version.

On this page are shown examples of XML files and the resulting output. Similar examples are provided in the Examples directory when the code is checked out.

NB: the header and implementation examples shown here are as close as possible to the produced files, some minor changes may be possible (eol and spaces are not always correctly rendered by the code environment).

  • Class example
  • Structure example

Class example

The showed class is an enhanced version of the std::stringclass, in the sense that is provides a method which checks if the string is a palindrome, and a template function allows to concatenate a substring of any type. First the input XML file:

<?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">
    <class>
        <name> DemonstrationClass </name>
        <author> George C Clark </author>
        <date> 21 February 2012 </date>
        <comments> true </comments>
        <inherits> std::string </inherits>
        <headerInclude> string </headerInclude>
        <implementationInclude> iostream </implementationInclude>
        <implementationUsedNamespace> std </implementationUsedNamespace>
        <public>
            <constructor>
                <argument type="std::string" const="true" ref="true" default="&amp;quot;&amp;quot;"> str </argument>
            </constructor>
            <method>
                <return type="bool"/>
                <name> isPalindrome </name>
            </method>
            <method>
                <template keyword="typename"> T </template>
                <return type="void"/>
                <name> concatenate </name>
                <argument type="T" const="true" ref="true"> t </argument>
                <const> true </const>
            </method>
        </public>
    </class>
</classes>

The produced header file:

#ifndef DEMONSTRATIONCLASS_HPP
#define DEMONSTRATIONCLASS_HPP

#include <string>

/**
 * @author George C Clark
 * @date 21 February 2012
 */
class DemonstrationClass : public std::string
{
public:
    /** Constructor
     *
     *
     * @param[in] str
     */
    DemonstrationClass( const std::string& str = "" );
    /** Destructor
     *
     *
     */
    virtual ~DemonstrationClass();
    /**
     *
     *
     */
    bool isPalindrome() const;
    /**
     *
     *
     * @param[in] t
     */
     template< typename T >
     void concatenate( const T& t );
}; 

template< typename T >
void DemonstrationClass::concatenate( const T& t )
{ } 

#endif // DEMONSTRATIONCLASS_HPP 

and the implementation file:

#include "DemonstrationClass.hpp"

#include <iostream>

using namespace std;

DemonstrationClass::DemonstrationClass( const string str )
    : string( ),
{ }

DemonstrationClass::~DemonstrationClass()
{ }

bool DemonstrationClass::isPalindrome() const
{ }

Back on top

Structure example

The presented structure is a template which can be used to extract the list of values from a keyed container (i.e. a std::map for instance). It is designed to be used in std::for_each or std::transform loops. The XML file:

<?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">
    <struct>
        <name> DemonstrationStructure </name>
        <author> George C Clark </author>
        <date> 21 February 2012 </date>
        <comments> true </comments>
        <template keyword="typename"> Key </template>
        <template keyword="typename"> Value </template>
        <inherits> std::unary_function&lt; std::pair&lt; Key, Value &gt;, Value &gt; </inherits>
        <headerInclude> functional </headerInclude>
        <public>
            <method>
                <return type="Value"/>
                <name> operator() </name>
                <argument type="std::pair&lt; Key, Value &gt;" const="true" ref="true"> myPair </argument>
            </method>
        </public>
    </struct>
</classes>

Since the structure is a template, only the header file is produced:

#ifndef DEMONSTRATIONSTRUCTURE_HPP
#define DEMONSTRATIONSTRUCTURE_HPP

#include <functional>

/**
 * @author George C Clark
 * @date 21 February 2012
 */
template< typename Key, typename Value >
struct DemonstrationStructure : public std::unary_function< std::pair< Key, Value >, Value >
{
public:
    /**
     *
     *
     * @param[in] myPair
     */
    Value operator()( const std::pair< Key, Value >& myPair );
}; 

template< typename Key, typename Value >
Value DemonstrationStructure< Key, Value >::operator()( const std::pair< Key, Value >& myPair )
{ } 

#endif // DEMONSTRATIONSTRUCTURE_HPP 

Back on top


Related

Wiki: ExamplesOutput
Wiki: WikiMap

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.