Menu

ExamplesOutput

Anonymous Johan Luisier

Navigate through the wiki

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::string class, 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> <parent> std::string </parent>
    </inherits>
    <include>
      <file> string </file>
      <header/> 
    </include> 
    <include> 
      <file> iostream </file>
    </include>
    <usedNamespace>
      <namespace> std </namespace>
    </usedNamespace>
    <public>
      <constructor>
    <argument>
      <type> std::string </type>
      <const/>
      <ref/>
      <default> &amp;quot;&amp;quot; </default>
      <name> str </name>
    </argument>
      </constructor>
      <method>
    <return> 
      <type> bool </type>
    </return>
    <name> isPalindrome </name>
    <const> true </const>
      </method>
      <method>
    <template> 
      <keyword> typename </keyword>
      <identifier> T </identifier>
    </template>
    <return>
      <type> void </type>
    </return>
    <name> concatenate </name>
    <argument>
      <name> t </name>
      <ref/>
      <const/>
      <type> T </type>
    </argument>
    <throw> std::exception </throw>
      </method>
    </public>
  </class>
</classes>
 The produced header file:
 #ifndef DEMONSTRATIONCLASS_HPP
 #define DEMONSTRATIONCLASS_HPP

// Created with XmlCppClassGenerator version 2.0 beta. 

#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:

// Created with XmlCppClassGenerator version 2.0 beta.

#include "DemonstrationClass.hpp"

#include &lt;iostream&gt;

using namespace std; 

DemonstrationClass::DemonstrationClass( const string&amp; 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>
    <identifier> Key </identifier>
    <keyword> typename </keyword>
  </template>
  <template>
    <keyword> typename </keyword>
    <identifier> Value </identifier>
  </template>
  <inherits>
    <parent> std::unary_function&amp;lt; std::pair&amp;lt; Key, Value &amp;gt;, Value &amp;gt; </parent>
  </inherits>
  <include>
    <file> functional </file>
    <header/>
    <local> false </local>
  </include>
  <public>
    <method>
      <return>
    <type> Value </type>
      </return>
      <name> operator() </name>
      <argument>
    <type> std::pair&amp;lt; Key, Value &amp;gt; </type>
    <const> true </const>
    <ref/>
    <name> myPair </name>
      </argument>
    </method>
  </public>
</struct>
</classes>

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

#ifndef DEMONSTRATIONSTRUCTURE_HPP
#define DEMONSTRATIONSTRUCTURE_HPP

// Created with XmlCppClassGenerator version 2.0 beta.

#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: ExamplesOutput1dot1AndBefore
Wiki: Home
Wiki: MainPage
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.