]> git.tdb.fi Git - libs/game.git/blobdiff - tools/setupgen/setupgen.h
Add a tool for generating setup structs and loaders for them
[libs/game.git] / tools / setupgen / setupgen.h
diff --git a/tools/setupgen/setupgen.h b/tools/setupgen/setupgen.h
new file mode 100644 (file)
index 0000000..98d1ab8
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef SETUPGEN_H_
+#define SETUPGEN_H_
+
+#include <map>
+#include <memory>
+#include <set>
+#include <string>
+#include <msp/core/application.h>
+#include <msp/datafile/objectloader.h>
+#include "enum.h"
+#include "struct.h"
+#include "type.h"
+
+class SetupGen: public Msp::RegisteredApplication<SetupGen>
+{
+private:
+       class Loader: public Msp::DataFile::ObjectLoader<SetupGen>
+       {
+       public:
+               Loader(SetupGen &);
+
+       private:
+               void init_actions() override;
+
+               void enum_def(const Msp::DataFile::Symbol &);
+               void name_space(const std::string &);
+               void struct_def(Struct::Kind, const Msp::DataFile::Symbol &);
+       };
+
+       std::string in_fn;
+       std::string out_fn;
+       std::string name_space;
+       std::map<std::string, Type> types;
+       std::vector<std::unique_ptr<Enum>> enums;
+       std::vector<std::unique_ptr<Struct>> structs;
+       std::set<std::string> headers;
+
+public:
+       SetupGen(int, char **);
+
+       int main() override;
+private:
+       void create_standard_types();
+       Type &add_type(const std::string &, Type::Kind);
+public:
+       const Type &get_type(const std::string &) const;
+
+private:
+       void load();
+       void collect_headers();
+       void generate_header(Msp::IO::Base &) const;
+       void generate_code(Msp::IO::Base &) const;
+};
+
+#endif