Skip to content

Commit

Permalink
Include optional arguments in preprocess-output-macros file
Browse files Browse the repository at this point in the history
Fixes #4697
  • Loading branch information
CelticMinstrel committed Aug 17, 2021
1 parent a9dcc25 commit b39d9b0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/serialization/preprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ void preproc_define::write_argument(config_writer& writer, const std::string& ar
writer.close_child(key);
}

void preproc_define::write_argument(config_writer& writer, const std::string& arg, const std::string& default_value) const
{
const std::string key = "argument";

writer.open_child(key);

writer.write_key_val("name", arg);
writer.write_key_val("default", default_value);
writer.close_child(key);
}

void preproc_define::write(config_writer& writer, const std::string& name) const
{
const std::string key = "preproc_define";
Expand All @@ -183,13 +194,21 @@ void preproc_define::write(config_writer& writer, const std::string& name) const
for(const std::string& arg : arguments) {
write_argument(writer, arg);
}

for(const auto& [key, default_value] : optional_arguments) {
write_argument(writer, key, default_value);
}

writer.close_child(key);
}

void preproc_define::read_argument(const config& cfg)
{
arguments.push_back(cfg["name"]);
if(cfg.has_attribute("default")) {
optional_arguments.emplace(cfg["name"], cfg["default"]);
} else {
arguments.push_back(cfg["name"]);
}
}

void preproc_define::read(const config& cfg)
Expand Down
1 change: 1 addition & 0 deletions src/serialization/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ struct preproc_define

void write(config_writer&, const std::string&) const;
void write_argument(config_writer&, const std::string&) const;
void write_argument(config_writer&, const std::string&, const std::string&) const;

void read(const config&);
void read_argument(const config&);
Expand Down

0 comments on commit b39d9b0

Please sign in to comment.