<?xml version="1.0"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <xsl:import href="keyval-common.xsl" />

  <xsl:output method="text" indent="no"/>

  <xsl:preserve-space elements="*"/>

<xsl:template match="keyval">

  <xsl:text>/*----------------------------------------------------------------
 * AUTOMATICALLY GENERATED FROM XML - DO NOT EDIT!
 * 
 * (c) 2003 - Vaisala */
//----------------------------------------------------------------
#ifndef __</xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>_Config_hh
#define __</xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>_Config_hh

#ifndef __nobj_Lookup_hh
#include &#60;nobj/Lookup.hh&#62;
#endif

///
namespace </xsl:text>
  <xsl:value-of select="(@namespace)"/>
  <xsl:text> {
  using nlib::Handle;
  using nlib::Lookup;

  /** Class which loads the configuration assocatiated with the
   *  {@link &#60;a href="../</xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>.man.html"&#62;</xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>&#60;/a&#62;} application.
   *
   * &#60;p&#62;This class is automatically generated from a XML document
   * which defines the configuration entries used by the application.&#60;/p&#62; */

  class </xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>Config : public Lookup {

  public:

    /** Constructor for the </xsl:text>
  <xsl:value-of select="(@class)"/>
  <xsl:text>Config class.
     * 
     * &#60;p&#62;This constructor initializes the object with the default
     * values as defined in the source XML document.&#60;/p&#62; */

    </xsl:text>
    <xsl:value-of select="(@class)"/>
    <xsl:text>Config();

    /** Attempts to load the values from a configuration.
     * 
     * &#60;p&#62;This method will load values from the Lookup object
     * referenced in the Handle passed and return true if everything appears
     * to be OK.&#60;/p&#62;
     *
     * @param cfg A Handle to a Lookup object.
     *
     * @return true if we successfully loaded values, false if not. */

    bool loadConfig(const nlib::Handle&amp; h);

    /** Attempt to lookup a value from our "dictionary" associated with a
     * particular key.
     * 
     * &#60;p&#62;This method makes this class usable as a standard
     * Lookup object. It will will return {@link Lookup#MISSING} until the
     * {@link #loadConfig} method is invoked and returns true.&#60;/p&#62;
     *
     * @return OK (0) if found, otherwise error {@link Lookup#MISSING} or
     * {@link Lookup#INVALID}. */

    int parseString(const std::string&amp; key, std::string&amp; val) const;

    /** Was the last attempt to load a configuration successful?
     * 
     * &#60;p&#62;This method will return false until the {@link #loadConfig}
     * method is invoked and returns true.&#60;/p&#62;
     *
     * @return true once a valid configuration has been loaded. */

    bool isOk() const {
      return _Ok;
    }
</xsl:text>

  <xsl:apply-templates/>
  <xsl:text>

  private:

    /** Handle to the configuration loaded. */
    nlib::Handle _Cfg;

    /** False initially, turns true once a configuration has be loaded. */
    bool _Ok;

  };

} // namespace </xsl:text>
  <xsl:value-of select="(@namespace)"/>
  <xsl:text>

#endif
</xsl:text>

</xsl:template>


<xsl:template match="keyval/*">

  <xsl:text>
  public:
    /** </xsl:text>
  <xsl:value-of select="summary"/>
  <xsl:text>
     *
     * &#60;p&#62;This value comes from the configuration file and is associated
     * with the key &#60;b&#62;</xsl:text>
  <xsl:value-of select="key"/>
  <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>

  <xsl:if test="(@min)">
    <xsl:text>     * &#60;p&#62;It has a minimum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@min)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:if test="(@max)">
    <xsl:text>     * &#60;p&#62;It has a maximum value of: &#60;b&#62;</xsl:text>
    <xsl:value-of select="(@max)"/>
    <xsl:text>&#60;/b&#62;.&#60;/p&#62;
</xsl:text>
  </xsl:if>

  <xsl:choose>

    <xsl:when test="@default = 'REQUIRED'">
      <xsl:text>     * &#60;p&#62;This value MUST be specified in the config file (no default).&#60;/p&#62;</xsl:text>
    </xsl:when>

    <xsl:otherwise>
      <xsl:text>     * &#60;p&#62;It has a default value (when not found in the config file) of:
     * &#60;b&#62;</xsl:text>
      <xsl:call-template name="format-cctype-value">
        <xsl:with-param name="cctype" select="@cctype" />
        <xsl:with-param name="value" select="@default" />
      </xsl:call-template>
      <xsl:text>&#60;/b&#62;.&#60;/p&#62;</xsl:text>
    </xsl:otherwise>

  </xsl:choose>

  <xsl:text>
     *
     * @return </xsl:text>
  <xsl:value-of select="(@type)"/>
  <xsl:text> */

    </xsl:text>

    <xsl:choose>
      <xsl:when test="@type = 'DATE'">
        <xsl:text>nanoval</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="(@cctype)"/>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:choose>
      <xsl:when test="@cctype='bool'">
        <xsl:text> is</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> get</xsl:text>
      </xsl:otherwise>
    </xsl:choose>

    <xsl:value-of select="(@varname)"/>
    <xsl:text>() const {
      return _</xsl:text>
    <xsl:value-of select="(@varname)"/>
    <xsl:text>;
    }

  private:
    </xsl:text>

    <xsl:choose>
      <xsl:when test="@type = 'DATE'">
        <xsl:text>nanoval</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="(@cctype)"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text> _</xsl:text>
    <xsl:value-of select="(@varname)"/>
    <xsl:text>;</xsl:text>

</xsl:template>

</xsl:stylesheet>
