Base: Units: refactor

Refactor Units making it constexpr, immutable, with repetition reduced.
Separate data from code.

Constexpr constructed units allow constructing predefined Quantities
from predefined unit types.
This commit is contained in:
bofdahof
2025-01-01 18:17:00 +10:00
committed by Ladislav Michl
parent a0917bcc7c
commit 2e0df80e84
8 changed files with 729 additions and 1155 deletions

View File

@@ -37,16 +37,12 @@ protected:
App::DocumentObject* this_obj() { return _this_obj; }
Base::Quantity parse_expression_text_as_quantity(const char* expression_text) {
auto expression = App::ExpressionParser::parse(this_obj(), expression_text);
auto expression_value = expression->getValueAsAny();
auto quantity_result = App::any_cast<Base::Quantity>(expression_value);
return quantity_result;
const auto expression = App::ExpressionParser::parse(this_obj(), expression_text);
return App::any_cast<Base::Quantity>(expression->getValueAsAny());
}
Base::Quantity parse_quantity_text_as_quantity(const char* quantity_text) {
auto quantity_str = std::string(quantity_text);
auto quantity_result = Base::Quantity::parse(quantity_str);
return quantity_result;
return Base::Quantity::parse(quantity_text);
}
private: