cpp_generator.h

00001
00002 /***************************************************************************
00003  *  cpp_generator.h - C++ Interface generator
00004  *
00005  *  Created: Thu Oct 12 01:59:02 2006
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022
00023 #ifndef __INTERFACES_GENERATOR_CPP_GENERATOR_H_
00024 #define __INTERFACES_GENERATOR_CPP_GENERATOR_H_
00025 
00026 #include "field.h"
00027 #include "constant.h"
00028 #include "enum_constant.h"
00029 #include "message.h"
00030 #include "pseudomap.h"
00031
00032 #include <vector>
00033 #include <string>
00034 #include <stdio.h>
00035
00036 class CppInterfaceGenerator
00037 {
00038  public:
00039   CppInterfaceGenerator(std::string directory, std::string interface_name,
00040                         std::string config_basename, std::string author,
00041                         std::string year, std::string creation_date,
00042                         std::string data_comment,
00043                         const unsigned char *hash, size_t hash_size,
00044                         const std::vector<InterfaceConstant> &constants,
00045                         const std::vector<InterfaceEnumConstant> &enum_constants,
00046                         const std::vector<InterfaceField> &data_fields,
00047                         const std::vector<InterfacePseudoMap> &pseudo_maps,
00048                         const std::vector<InterfaceMessage> &messages
00049                         );
00050   ~CppInterfaceGenerator();
00051
00052   void write_h(FILE *f);
00053   void write_cpp(FILE *f);
00054
00055   void write_constants_cpp(FILE *f);
00056   void write_constants_h(FILE *f);
00057
00058   void write_messages_cpp(FILE *f);
00059   void write_messages_h(FILE *f);
00060   void write_ctor_dtor_h(FILE *f,  std::string /* indent space */ is,
00061                          std::string classname);
00062   void write_ctor_dtor_cpp(FILE *f, std::string classname, std::string super_class,
00063                            std::string inclusion_prefix, std::vector<InterfaceField> fields,
00064                            std::vector<InterfaceMessage> messages);
00065
00066   void write_message_ctor_dtor_h(FILE *f,  std::string /* indent space */ is,
00067                                  std::string classname,
00068                                  std::vector<InterfaceField> fields);
00069   void write_message_ctor_dtor_cpp(FILE *f, std::string classname, std::string super_class,
00070                                    std::string inclusion_prefix,
00071                                    std::vector<InterfaceField> fields);
00072   void write_message_clone_method_h(FILE *f, std::string is);
00073   void write_message_clone_method_cpp(FILE *f, std::string classname);
00074
00075
00076   void write_methods_h(FILE *f,
00077                        std::string /* indent space */ is,
00078                        std::vector<InterfaceField> fields);
00079   void write_methods_cpp(FILE *f,
00080                          std::string interface_classname,
00081                          std::string classname,
00082                          std::vector<InterfaceField> fields,
00083                          std::string inclusion_prefix);
00084
00085   void write_create_message_method_cpp(FILE *f);
00086   void write_copy_value_method_cpp(FILE *f);
00087   void write_basemethods_h(FILE *f, std::string is);
00088   void write_basemethods_cpp(FILE *f);
00089
00090   void write_methods_h(FILE *f,
00091                        std::string /* indent space */ is,
00092                        std::vector<InterfaceField> fields,
00093                        std::vector<InterfacePseudoMap> pseudo_maps);
00094   void write_methods_cpp(FILE *f,
00095                          std::string interface_classname,
00096                          std::string classname,
00097                          std::vector<InterfaceField> fields,
00098                          std::vector<InterfacePseudoMap> pseudo_maps,
00099                          std::string inclusion_prefix);
00100
00101   void write_management_funcs_cpp(FILE *f);
00102
00103
00104   void write_struct(FILE *f, std::string name, std::string /* indent space */ is,
00105                     std::vector<InterfaceField> fields);
00106
00107   void write_header(FILE *f, std::string filename);
00108   void write_deflector(FILE *f);
00109   void generate();
00110
00111  private:
00112   std::vector<InterfaceConstant>     constants;
00113   std::vector<InterfaceEnumConstant> enum_constants;
00114   std::vector<InterfaceField>        data_fields;
00115   std::vector<InterfacePseudoMap>    pseudo_maps;
00116   std::vector<InterfaceMessage>      messages;
00117
00118   std::string dir;
00119   std::string filename_cpp;
00120   std::string filename_h;
00121   std::string filename_o;
00122   std::string class_name;
00123   std::string deflector;
00124   std::string gendate;
00125   std::string author;
00126   std::string year;
00127   std::string creation_date;
00128   std::string data_comment;
00129
00130   const unsigned char *hash;
00131   size_t hash_size;
00132 };
00133
00134
00135 #endif