]> git.tdb.fi Git - libs/game.git/blobdiff - tools/setupgen/struct.h
Add a tool for generating setup structs and loaders for them
[libs/game.git] / tools / setupgen / struct.h
diff --git a/tools/setupgen/struct.h b/tools/setupgen/struct.h
new file mode 100644 (file)
index 0000000..adc95f8
--- /dev/null
@@ -0,0 +1,62 @@
+#ifndef STRUCT_H_
+#define STRUCT_H_
+
+#include <string>
+#include <vector>
+#include <msp/datafile/objectloader.h>
+#include <msp/io/base.h>
+
+class SetupGen;
+class Type;
+
+class Struct
+{
+public:
+       enum Kind
+       {
+               DATA,
+               ENTITY,
+               COMPONENT
+       };
+
+       struct Field
+       {
+               class Loader;
+
+               std::string name;
+               const Type *type = nullptr;
+               std::string default_value;
+       };
+
+       class Loader;
+
+private:
+       std::string name;
+       Kind kind;
+       std::vector<Field> fields;
+
+public:
+       Struct(const std::string &, Kind);
+
+       const std::vector<Field> &get_fields() const { return fields; }
+
+       void define_type(Msp::IO::Base &) const;
+       void define_loader(Msp::IO::Base &) const;
+       void define_functions(Msp::IO::Base &) const;
+};
+
+class Struct::Loader: public Msp::DataFile::ObjectLoader<Struct>
+{
+private:
+       const SetupGen &gen;
+
+public:
+       Loader(Struct &, const SetupGen &);
+
+private:
+       void init_actions() override;
+
+       void field(const Msp::DataFile::Symbol &, const Msp::DataFile::Symbol &);
+};
+
+#endif