/*
 * File automatically generated by
 * gengen 1.0 by Lorenzo Bettini 
 * http://www.gnu.org/software/gengen
 */

#ifndef C_CONVERT_GEN_CLASS_H
#define C_CONVERT_GEN_CLASS_H

#include <string>
#include <iostream>

using std::string;
using std::ostream;

class c_convert_gen_class
{
 protected:
  bool hasbools;
  bool hasints;

 public:
  c_convert_gen_class() :
    hasbools (false), hasints (false)
  {
  }
  
  c_convert_gen_class(bool _hasbools, bool _hasints) :
    hasbools (_hasbools), hasints (_hasints)
  {
  }

  void set_hasbools(bool _hasbools)
  {
    hasbools = _hasbools;
  }

  void set_hasints(bool _hasints)
  {
    hasints = _hasints;
  }

  void generate_c_convert(ostream &stream, unsigned int indent = 0)
  {
    string indent_str (indent, ' ');
    indent = 0;
  
    if (hasints)
      {
        stream << "\n";
        stream << indent_str;
        stream << "static char *";
        stream << "\n";
        stream << indent_str;
        stream << "int_to_string(int i)";
        stream << "\n";
        stream << indent_str;
        stream << "{";
        stream << "\n";
        stream << indent_str;
        stream << "  static char buffer[256];";
        stream << "\n";
        stream << indent_str;
        stream << "\n";
        stream << indent_str;
        stream << "  snprintf (buffer, 255, \"%d\", i);";
        stream << "\n";
        stream << indent_str;
        stream << "\n";
        stream << indent_str;
        stream << "  return buffer;";
        stream << "\n";
        stream << indent_str;
        stream << "}";
        stream << "\n";
        stream << indent_str;
        stream << "\n";
        stream << indent_str;
      }
    if (hasbools)
      {
        stream << "\n";
        stream << indent_str;
        stream << "static const char *";
        stream << "\n";
        stream << indent_str;
        stream << "bool_to_string(short b)";
        stream << "\n";
        stream << indent_str;
        stream << "{";
        stream << "\n";
        stream << indent_str;
        stream << "  return (b ? \"true\" : \"false\");";
        stream << "\n";
        stream << indent_str;
        stream << "}";
        stream << "\n";
        stream << indent_str;
        stream << "\n";
        stream << indent_str;
      }
  }
};

#endif // C_CONVERT_GEN_CLASS_H
