mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-06 11:39:49 -06:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user