]> git.tdb.fi Git - libs/game.git/blob - tools/setupgen/setupgen.h
Add a tool for generating setup structs and loaders for them
[libs/game.git] / tools / setupgen / setupgen.h
1 #ifndef SETUPGEN_H_
2 #define SETUPGEN_H_
3
4 #include <map>
5 #include <memory>
6 #include <set>
7 #include <string>
8 #include <msp/core/application.h>
9 #include <msp/datafile/objectloader.h>
10 #include "enum.h"
11 #include "struct.h"
12 #include "type.h"
13
14 class SetupGen: public Msp::RegisteredApplication<SetupGen>
15 {
16 private:
17         class Loader: public Msp::DataFile::ObjectLoader<SetupGen>
18         {
19         public:
20                 Loader(SetupGen &);
21
22         private:
23                 void init_actions() override;
24
25                 void enum_def(const Msp::DataFile::Symbol &);
26                 void name_space(const std::string &);
27                 void struct_def(Struct::Kind, const Msp::DataFile::Symbol &);
28         };
29
30         std::string in_fn;
31         std::string out_fn;
32         std::string name_space;
33         std::map<std::string, Type> types;
34         std::vector<std::unique_ptr<Enum>> enums;
35         std::vector<std::unique_ptr<Struct>> structs;
36         std::set<std::string> headers;
37
38 public:
39         SetupGen(int, char **);
40
41         int main() override;
42 private:
43         void create_standard_types();
44         Type &add_type(const std::string &, Type::Kind);
45 public:
46         const Type &get_type(const std::string &) const;
47
48 private:
49         void load();
50         void collect_headers();
51         void generate_header(Msp::IO::Base &) const;
52         void generate_code(Msp::IO::Base &) const;
53 };
54
55 #endif