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

#ifndef INITSTRUCTFUN_LUA_GEN_CLASS_H
#define INITSTRUCTFUN_LUA_GEN_CLASS_H

#include <string>
#include <iostream>

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

class initstructfun_lua_gen_class
{
 protected:
  string genfieldinit;
  string structname;

 public:
  initstructfun_lua_gen_class()
  {
  }
  
  initstructfun_lua_gen_class(const string &_genfieldinit, const string &_structname) :
    genfieldinit (_genfieldinit), structname (_structname)
  {
  }

  virtual ~initstructfun_lua_gen_class()
  {
  }

  static void
  generate_string(const string &s, ostream &stream, unsigned int indent)
  {
    if (!indent || s.find('\n') == string::npos)
      {
        stream << s;
        return;
      }

    string::size_type pos;
    string::size_type start = 0;
    string ind (indent, ' ');
    while ( (pos=s.find('\n', start)) != string::npos)
      {
        stream << s.substr (start, (pos+1)-start);
        start = pos+1;
        if (start+1 <= s.size ())
          stream << ind;
      }
    if (start+1 <= s.size ())
      stream << s.substr (start);
  }

  virtual void generate_genfieldinit(ostream &stream, unsigned int indent) = 0;

  void set_genfieldinit(const string &_genfieldinit)
  {
    genfieldinit = _genfieldinit;
  }

  void set_structname(const string &_structname)
  {
    structname = _structname;
  }

  void generate_initstructfun_lua(ostream &stream, unsigned int indent = 0)
  {
    string indent_str (indent, ' ');
    indent = 0;
  
    stream << "\n";
    stream << indent_str;
    stream << "function init_";
    stream << structname;
    stream << "(record)";
    stream << "\n";
    stream << indent_str;
    indent = 2;
    if (genfieldinit.size () > 0)
      generate_string (genfieldinit, stream, indent + indent_str.length ());
    else
      generate_genfieldinit (stream, indent + indent_str.length ());
    indent = 0;
    stream << indent_str;
    stream << "end";
    stream << "\n";
    stream << indent_str;
  }
};

#endif // INITSTRUCTFUN_LUA_GEN_CLASS_H
