From 548f5db5fb32e84c4b1128ac98a79403885ddadd Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 8 Jan 2023 15:01:17 +0200 Subject: [PATCH] Support API decorations for setups --- tools/setupgen/setupgen.cpp | 17 +++++++++++++++++ tools/setupgen/setupgen.h | 4 ++++ tools/setupgen/struct.cpp | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/tools/setupgen/setupgen.cpp b/tools/setupgen/setupgen.cpp index efb93fb..204045f 100644 --- a/tools/setupgen/setupgen.cpp +++ b/tools/setupgen/setupgen.cpp @@ -106,6 +106,8 @@ void SetupGen::collect_headers(const Module &mod) { headers.insert("msp/datafile/objectloader.h"); headers.insert("msp/strings/lexicalcast.h"); + if(!mod.api_header.empty()) + headers.insert(mod.api_header); for(const unique_ptr &s: mod.structs) for(const Struct::Field &f: s->get_fields()) if(const string &h = f.type->get_header(); !h.empty()) @@ -131,6 +133,8 @@ void SetupGen::generate_header(const Module &mod, IO::Base &out) const IO::print(out, "#include <%s>\n", h); } + IO::print(out, "\n#define API %s\n", mod.api); + if(!mod.name_space.empty()) IO::print(out, "\nnamespace %s {\n", mod.name_space); @@ -196,6 +200,8 @@ SetupGen::Loader::Loader(SetupGen &s, Module &m): void SetupGen::Loader::init_actions() { + add("api", &Loader::api); + add("api", &Loader::api_with_header); add("component", &Loader::struct_def, Struct::COMPONENT); add("entity", &Loader::struct_def, Struct::ENTITY); add("enum", &Loader::enum_def); @@ -203,6 +209,17 @@ void SetupGen::Loader::init_actions() add("namespace", &Loader::name_space); } +void SetupGen::Loader::api(const string &a) +{ + api_with_header(a, string()); +} + +void SetupGen::Loader::api_with_header(const string &a, const string &h) +{ + mod.api = a; + mod.api_header = h; +} + void SetupGen::Loader::enum_def(const DataFile::Symbol &n) { Enum en(n.name); diff --git a/tools/setupgen/setupgen.h b/tools/setupgen/setupgen.h index 1ff2b8d..f792e45 100644 --- a/tools/setupgen/setupgen.h +++ b/tools/setupgen/setupgen.h @@ -19,6 +19,8 @@ private: struct Module { std::string name_space; + std::string api; + std::string api_header; std::vector> enums; std::vector> structs; }; @@ -34,6 +36,8 @@ private: private: void init_actions() override; + void api(const std::string &); + void api_with_header(const std::string &, const std::string &); void enum_def(const Msp::DataFile::Symbol &); void import(const std::string &); void name_space(const std::string &); diff --git a/tools/setupgen/struct.cpp b/tools/setupgen/struct.cpp index b93b5be..89b30f1 100644 --- a/tools/setupgen/struct.cpp +++ b/tools/setupgen/struct.cpp @@ -24,7 +24,7 @@ Struct::Struct(const string &n, Kind k): void Struct::define_type(IO::Base &out) const { - IO::print(out, "struct %s\n{\n", name); + IO::print(out, "struct API %s\n{\n", name); IO::print(out, "\tclass Loader;\n\n"); for(const Field &f: fields) @@ -49,7 +49,7 @@ void Struct::define_type(IO::Base &out) const void Struct::define_loader(IO::Base &out) const { - IO::print(out, "class %s::Loader: public Msp::DataFile::ObjectLoader<%s>\n{\n", name, name); + IO::print(out, "class API %s::Loader: public Msp::DataFile::ObjectLoader<%s>\n{\n", name, name); IO::print(out, "public:\n"); IO::print(out, "\tLoader(%s &);\n", name); IO::print(out, "\nprivate:\n"); -- 2.45.2