Feature/codegen (#1480)

* Add the ability to automatically generate code to extract values out of a Dictionary (see https://github.com/openspace/codegen for more information on how to use this)
* Applied this technique to a large number of cases in the codebase
* Don't add _codegen files to the repository

Co-authored-by: Emma Broman <emma.broman@liu.se>
This commit is contained in:
Alexander Bock
2021-02-09 09:12:43 +01:00
committed by GitHub
parent 78c0b23194
commit 6d821d4f91
104 changed files with 2939 additions and 4769 deletions
+12 -27
View File
@@ -31,6 +31,7 @@
#include <ghoul/font/fontmanager.h>
#include <ghoul/font/fontrenderer.h>
#include <ghoul/misc/profiling.h>
#include <optional>
namespace {
constexpr openspace::properties::Property::PropertyInfo TextInfo = {
@@ -38,44 +39,28 @@ namespace {
"Text",
"The text to be displayed"
};
struct [[codegen::Dictionary(DashboardItemText)]] Parameters {
// [[codegen::verbatim(TextInfo.description)]]
std::optional<std::string> text;
};
#include "dashboarditemtext_codegen.cpp"
} // namespace
namespace openspace {
documentation::Documentation DashboardItemText::Documentation() {
using namespace documentation;
return {
"DashboardItem Text",
"base_dashboarditem_text",
{
{
"Type",
new StringEqualVerifier("DashboardItemText"),
Optional::No
},
{
TextInfo.identifier,
new StringVerifier,
Optional::Yes,
TextInfo.description
}
}
};
documentation::Documentation doc = codegen::doc<Parameters>();
doc.id = "base_dashboarditem_text";
return doc;
}
DashboardItemText::DashboardItemText(const ghoul::Dictionary& dictionary)
: DashboardTextItem(dictionary)
, _text(TextInfo, "")
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"DashboardItemText"
);
if (dictionary.hasKey(TextInfo.identifier)) {
_text = dictionary.value<std::string>(TextInfo.identifier);
};
const Parameters p = codegen::bake<Parameters>(dictionary);
_text = p.text.value_or(_text);
addProperty(_text);
}