mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-18 16:27:34 +01:00
[poincare/unit] Lighten Representative constructor
This commit is contained in:
committed by
Léa Saviot
parent
9fc1182733
commit
1e3b8581e5
@@ -45,12 +45,13 @@ public:
|
||||
No,
|
||||
Yes
|
||||
};
|
||||
constexpr Representative(const char * rootSymbol, const char * definition, const Prefixable prefixable, const Prefix * outputPrefixes, size_t numberOfOutputPrefixes) :
|
||||
template <size_t N>
|
||||
constexpr Representative(const char * rootSymbol, const char * definition, const Prefixable prefixable, const Prefix (&outputPrefixes)[N]) :
|
||||
m_rootSymbol(rootSymbol),
|
||||
m_definition(definition),
|
||||
m_prefixable(prefixable),
|
||||
m_outputPrefixes(outputPrefixes),
|
||||
m_outputPrefixesUpperBound(outputPrefixes + numberOfOutputPrefixes)
|
||||
m_outputPrefixesUpperBound(outputPrefixes + N)
|
||||
{
|
||||
}
|
||||
const char * rootSymbol() const { return m_rootSymbol; }
|
||||
@@ -216,170 +217,163 @@ public:
|
||||
GigaPrefix,
|
||||
TeraPrefix,
|
||||
};
|
||||
static constexpr size_t
|
||||
NoPrefixCount = sizeof(NoPrefix)/sizeof(Prefix),
|
||||
NegativeLongScalePrefixesCount = sizeof(NegativeLongScalePrefixes)/sizeof(Prefix),
|
||||
PositiveLongScalePrefixesCount = sizeof(PositiveLongScalePrefixes)/sizeof(Prefix),
|
||||
LongScalePrefixesCount = sizeof(LongScalePrefixes)/sizeof(Prefix),
|
||||
NegativePrefixesCount = sizeof(NegativePrefixes)/sizeof(Prefix),
|
||||
AllPrefixesCount = sizeof(AllPrefixes)/sizeof(Prefix);
|
||||
static constexpr const Representative
|
||||
TimeRepresentatives[] = {
|
||||
Representative("s", nullptr,
|
||||
Representative::Prefixable::Yes,
|
||||
NegativeLongScalePrefixes, NegativeLongScalePrefixesCount),
|
||||
NegativeLongScalePrefixes),
|
||||
Representative("min", "60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("h", "60*60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("day", "24*60*60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("week", "7*24*60*60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("month", "30*7*24*60*60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("year", "365.25*24*60*60*_s",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
DistanceRepresentatives[] = {
|
||||
Representative("m", nullptr,
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
Representative("au", "149587870700*_m",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("ly", "299792458*_m/_s*_year",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("pc", "180*60*60/π*_au",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
MassRepresentatives[] = {
|
||||
Representative("g", nullptr,
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
Representative("t", "1000_kg",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("Da", "(6.02214076*10^23*1000)^-1*_kg",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
CurrentRepresentatives[] = {
|
||||
Representative("A", nullptr,
|
||||
Representative::Prefixable::Yes,
|
||||
NegativeLongScalePrefixes, NegativeLongScalePrefixesCount),
|
||||
NegativeLongScalePrefixes),
|
||||
},
|
||||
TemperatureRepresentatives[] = {
|
||||
Representative("K", nullptr,
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
AmountOfSubstanceRepresentatives[] = {
|
||||
Representative("mol", nullptr,
|
||||
Representative::Prefixable::Yes,
|
||||
NegativeLongScalePrefixes, NegativeLongScalePrefixesCount),
|
||||
NegativeLongScalePrefixes),
|
||||
},
|
||||
LuminousIntensityRepresentatives[] = {
|
||||
Representative("cd", nullptr,
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
FrequencyRepresentatives[] = {
|
||||
Representative("Hz", "_s^-1",
|
||||
Representative::Prefixable::Yes,
|
||||
PositiveLongScalePrefixes, PositiveLongScalePrefixesCount),
|
||||
PositiveLongScalePrefixes),
|
||||
},
|
||||
ForceRepresentatives[] = {
|
||||
Representative("N", "_kg*_m*_s^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
PressureRepresentatives[] = {
|
||||
Representative("Pa", "_kg*_m^-1*_s^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
Representative("bar", "1000_hPa",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
Representative("atm", "101325_Pa",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
EnergyRepresentatives[] = {
|
||||
Representative("J", "_kg*_m^2*_s^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
Representative("eV", "1.602176634ᴇ-19*_J",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
PowerRepresentatives[] = {
|
||||
Representative("W", "_kg*_m^2*_s^-3",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
ElectricChargeRepresentatives[] = {
|
||||
Representative("C", "_A*_s",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
ElectricPotentialRepresentatives[] = {
|
||||
Representative("V", "_kg*_m^2*_s^-3*_A^-1",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
ElectricCapacitanceRepresentatives[] = {
|
||||
Representative("F", "_A^2*_s^4*_kg^-1*_m^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
ElectricResistanceRepresentatives[] = {
|
||||
Representative("Ω", "_kg*_m^2*_s^-3*_A^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
ElectricConductanceRepresentatives[] = {
|
||||
Representative("S", "_A^2*_s^3*_kg^-1*_m^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
LongScalePrefixes, LongScalePrefixesCount),
|
||||
LongScalePrefixes),
|
||||
},
|
||||
MagneticFluxRepresentatives[] = {
|
||||
Representative("Wb", "_kg*_m^2*_s^-2*_A^-1",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
MagneticFieldRepresentatives[] = {
|
||||
Representative("T", "_kg*_s^-2*_A^-1",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
InductanceRepresentatives[] = {
|
||||
Representative("H", "_kg*_m^2*_s^-2*_A^-2",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
CatalyticActivityRepresentatives[] = {
|
||||
Representative("kat", "_mol*_s^-1",
|
||||
Representative::Prefixable::Yes,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
SurfaceRepresentatives[] = {
|
||||
Representative("ha", "10^4*_m^2",
|
||||
Representative::Prefixable::No,
|
||||
NoPrefix, NoPrefixCount),
|
||||
NoPrefix),
|
||||
},
|
||||
VolumeRepresentatives[] = {
|
||||
Representative("L", "10^-3*_m^3",
|
||||
Representative::Prefixable::Yes,
|
||||
NegativePrefixes, NegativePrefixesCount),
|
||||
NegativePrefixes),
|
||||
};
|
||||
static constexpr const Dimension DimensionTable[] = {
|
||||
/* The current table is sorted from most to least simple units.
|
||||
|
||||
@@ -28,7 +28,7 @@ bool UnitNode::Representative::canParse(const char * symbol, size_t length,
|
||||
return length == 0;
|
||||
}
|
||||
const Prefix * pre = Unit::AllPrefixes;
|
||||
while (pre < Unit::AllPrefixes + Unit::AllPrefixesCount) {
|
||||
while (pre < Unit::AllPrefixes + sizeof(Unit::AllPrefixes)/sizeof(Unit::Prefix)) {
|
||||
const char * prefixSymbol = pre->symbol();
|
||||
if (strncmp(symbol, prefixSymbol, length) == 0 &&
|
||||
prefixSymbol[length] == 0)
|
||||
@@ -173,13 +173,6 @@ constexpr const Unit::Prefix
|
||||
Unit::LongScalePrefixes[],
|
||||
Unit::NegativePrefixes[],
|
||||
Unit::AllPrefixes[];
|
||||
constexpr size_t
|
||||
Unit::NoPrefixCount,
|
||||
Unit::NegativeLongScalePrefixesCount,
|
||||
Unit::PositiveLongScalePrefixesCount,
|
||||
Unit::LongScalePrefixesCount,
|
||||
Unit::NegativePrefixesCount,
|
||||
Unit::AllPrefixesCount;
|
||||
constexpr const Unit::Representative
|
||||
Unit::TimeRepresentatives[],
|
||||
Unit::DistanceRepresentatives[],
|
||||
|
||||
@@ -295,7 +295,7 @@ QUIZ_CASE(poincare_parsing_units) {
|
||||
Expression unit = parse_expression(buffer, nullptr, false);
|
||||
quiz_assert_print_if_failure(unit.type() == ExpressionNode::Type::Unit, "Should be parsed as a Unit");
|
||||
if (rep->isPrefixable()) {
|
||||
for (const Unit::Prefix * pre = Unit::AllPrefixes; pre < Unit::AllPrefixes + Unit::AllPrefixesCount; pre++) {
|
||||
for (const Unit::Prefix * pre = Unit::AllPrefixes; pre < Unit::AllPrefixes + sizeof(Unit::AllPrefixes)/sizeof(Unit::Prefix); pre++) {
|
||||
Unit::Builder(dim, rep, pre).serialize(buffer, bufferSize, Preferences::PrintFloatMode::Decimal, Preferences::VeryShortNumberOfSignificantDigits);
|
||||
Expression unit = parse_expression(buffer, nullptr, false);
|
||||
quiz_assert_print_if_failure(unit.type() == ExpressionNode::Type::Unit, "Should be parsed as a Unit");
|
||||
|
||||
Reference in New Issue
Block a user