Fawkes API  Fawkes Development Version
tolua_generator.h
1 
2 /***************************************************************************
3  * tolua_generator.h - ToLua++ Interface generator
4  *
5  * Created: Tue Mar 11 15:30:09 2008
6  * Copyright 2006-2008 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #ifndef __INTERFACES_GENERATOR_TOLUA_GENERATOR_H_
24 #define __INTERFACES_GENERATOR_TOLUA_GENERATOR_H_
25 
26 #include "field.h"
27 #include "constant.h"
28 #include "enum_constant.h"
29 #include "message.h"
30 #include "pseudomap.h"
31 
32 #include <vector>
33 #include <string>
34 #include <stdio.h>
35 
37 {
38  public:
39  ToLuaInterfaceGenerator(std::string directory, std::string interface_name,
40  std::string config_basename, std::string author,
41  std::string year, std::string creation_date,
42  std::string data_comment,
43  const unsigned char *hash, size_t hash_size,
44  const std::vector<InterfaceConstant> &constants,
45  const std::vector<InterfaceEnumConstant> &enum_constants,
46  const std::vector<InterfaceField> &data_fields,
47  const std::vector<InterfacePseudoMap> &pseudo_maps,
48  const std::vector<InterfaceMessage> &messages
49  );
51 
52  void write_toluaf(FILE *f);
53 
54  void write_header(FILE *f, std::string filename);
55  void write_constants_h(FILE *f);
56  void write_messages_h(FILE *f);
57  void write_message_superclass_h(FILE *f);
58  void write_superclass_h(FILE *f);
59  void write_lua_code(FILE *f, std::string classname);
60  void write_methods_h(FILE *f,
61  std::string /* indent space */ is,
62  std::vector<InterfaceField> fields);
63  void write_methods_h(FILE *f, std::string /* indent space */ is,
64  std::vector<InterfaceField> fields,
65  std::vector<InterfacePseudoMap> pseudo_maps);
66  void write_message_ctor_dtor_h(FILE *f, std::string /* indent space */ is,
67  std::string classname,
68  std::vector<InterfaceField> fields);
69  void write_ctor_dtor_h(FILE *f, std::string /* indent space */ is,
70  std::string classname);
71 
72  void generate();
73 
74  const char * convert_type(std::string c_type);
75 
76  private:
77  std::vector<InterfaceConstant> constants;
78  std::vector<InterfaceEnumConstant> enum_constants;
79  std::vector<InterfaceField> data_fields;
80  std::vector<InterfacePseudoMap> pseudo_maps;
81  std::vector<InterfaceMessage> messages;
82 
83  std::string dir;
84  std::string filename_tolua;
85  std::string filename_h;
86  std::string class_name;
87  std::string gendate;
88  std::string author;
89  std::string year;
90  std::string creation_date;
91  std::string data_comment;
92 
93  const unsigned char *hash;
94  size_t hash_size;
95 };
96 
97 
98 #endif
~ToLuaInterfaceGenerator()
Destructor.
void write_toluaf(FILE *f)
Write h file.
void write_superclass_h(FILE *f)
Write superclass methods.
void write_message_ctor_dtor_h(FILE *f, std::string is, std::string classname, std::vector< InterfaceField > fields)
Write constructor and destructor for message to h file.
void write_methods_h(FILE *f, std::string is, std::vector< InterfaceField > fields)
Write methods to h file.
void write_constants_h(FILE *f)
Write constants to h file.
const char * convert_type(std::string c_type)
Convert C type to Lua type.
void write_messages_h(FILE *f)
Write messages to h file.
void write_message_superclass_h(FILE *f)
Write superclass methods.
void write_header(FILE *f, std::string filename)
Write header to file.
void generate()
Generator cpp and h files.
ToLuaInterfaceGenerator(std::string directory, std::string interface_name, std::string config_basename, std::string author, std::string year, std::string creation_date, std::string data_comment, const unsigned char *hash, size_t hash_size, const std::vector< InterfaceConstant > &constants, const std::vector< InterfaceEnumConstant > &enum_constants, const std::vector< InterfaceField > &data_fields, const std::vector< InterfacePseudoMap > &pseudo_maps, const std::vector< InterfaceMessage > &messages)
Constructor.
Generator that transforms input from the InterfaceParser into valid ToLua++ package file...
void write_ctor_dtor_h(FILE *f, std::string is, std::string classname)
Write constructor and destructor to h file.
void write_lua_code(FILE *f, std::string classname)
Write additional Lua code to file.