25 #include "../system/eptexception.h"
26 #include "../system/log.h"
27 #include "../settings.h"
28 #include "../adapters/filemanager.h"
30 using tinyxml2::XMLDocument;
31 using tinyxml2::XMLElement;
38 document.Parse(fileContent.c_str(), fileContent.size());
40 if (document.Error()) {
44 const XMLElement *root = document.FirstChildElement();
50 const int year = root->IntAttribute(
"year");
51 std::string author = root->Attribute(
"author");
53 std::string description;
56 for (
const XMLElement *child = root->FirstChildElement(); child; child = child->NextSiblingElement()) {
57 if (strcmp(child->Name(),
"name") == 0) {
60 }
else if (strcmp(child->Name(),
"description") == 0) {
63 }
else if (strcmp(child->Name(),
"param") == 0) {
70 return std::shared_ptr<const AlgorithmInformation>(
75 EptAssert(element,
"XMLElement has to exist");
79 std::string defaultLanguageString;
81 for (
const XMLElement *child = element->FirstChildElement(); child; child = child->NextSiblingElement()) {
82 if (strcmp(child->Name(),
"string") != 0) {
84 + std::string(element->Name()) +
"', but element with name '"
85 + std::string(child->Name()) +
"' was given.");
88 if (child->Attribute(
"lang")) {
89 if (languageId == child->Attribute(
"lang")) {
90 return child->GetText();
94 defaultLanguageString = child->GetText();
96 if (languageId ==
"en") {
98 return defaultLanguageString;
106 if (defaultLanguageString.size() > 0) {
107 LogD(
"Element '%s' has missing translation for '%s'", element->Value(), languageId.c_str());
108 return defaultLanguageString;
115 EptAssert(element,
"XMLElement has to exist");
117 const std::string
id = element->Attribute(
"id");
118 const std::string type = element->Attribute(
"type");
120 std::string label, description;
122 const XMLElement *labelElement = element->FirstChildElement(
"label");
123 const XMLElement *descriptionElement = element->FirstChildElement(
"description");
131 if (descriptionElement) {
134 LogD(
"Desciption of parameter not set.");
137 if (type ==
"double") {
138 const double defaultValue = element->DoubleAttribute(
"default");
139 double minValue = std::numeric_limits<double>::min();
140 double maxValue = std::numeric_limits<double>::max();
143 element->QueryDoubleAttribute(
"min", &minValue);
144 element->QueryDoubleAttribute(
"max", &maxValue);
145 element->QueryIntAttribute(
"precision", &precision);
146 return AlgorithmParameter(
id, label, description, defaultValue, minValue, maxValue, precision);
147 }
else if (type ==
"int") {
148 const int defaultValue = element->IntAttribute(
"default");
149 int minValue = std::numeric_limits<int>::min();
150 int maxValue = std::numeric_limits<int>::max();
152 element->QueryIntAttribute(
"min", &minValue);
153 element->QueryIntAttribute(
"max", &maxValue);
155 }
else if (type ==
"list") {
156 const std::string defaultValue = element->Attribute(
"default");
159 for (
const XMLElement *entry = element->FirstChildElement(
"entry"); entry;
160 entry = entry->NextSiblingElement(
"entry")) {
161 EptAssert(entry->Attribute(
"value"),
"Value entry is required for string list parameter.");
162 std::string value = entry->Attribute(
"value");
164 list.push_back(std::make_pair(value, label));
static Settings & getSingleton()
Get a pointer to the singleton instance.
static FileManager & getSingleton()
FileManager::getSingleton: Get a reference to the singleton.
#define EPT_EXCEPT(num, desc)
virtual std::string getUserLanguageId() const
Settings::getUserLanguageId.
std::vector< std::pair< std::string, std::string > > StringParameterList