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

View File

@@ -30,40 +30,29 @@
#include <ghoul/misc/templatefactory.h>
namespace {
constexpr const char* KeyType = "Type";
struct [[codegen::Dictionary(PlanetGeometry)]] Parameters {
// The type of the PlanetGeometry that will can be constructed
std::string type;
};
#include "planetgeometry_codegen.cpp"
} // namespace
namespace openspace::planetgeometry {
documentation::Documentation PlanetGeometry::Documentation() {
using namespace documentation;
return {
"Planet Geometry",
"space_geometry_planet",
{
{
KeyType,
new StringVerifier,
Optional::No,
"The type of the PlanetGeometry that will can be constructed."
}
}
};
documentation::Documentation doc = codegen::doc<Parameters>();
doc.id = "space_geometry_planet";
return doc;
}
std::unique_ptr<PlanetGeometry> PlanetGeometry::createFromDictionary(
const ghoul::Dictionary& dictionary)
{
documentation::testSpecificationAndThrow(
Documentation(),
dictionary,
"PlanetGeometry"
);
const Parameters p = codegen::bake<Parameters>(dictionary);
std::string geometryType = dictionary.value<std::string>(KeyType);
auto factory = FactoryManager::ref().factory<PlanetGeometry>();
PlanetGeometry* result = factory->create(geometryType, dictionary);
PlanetGeometry* result = factory->create(p.type, dictionary);
return std::unique_ptr<PlanetGeometry>(result);
}