[poincare] Add comment on how Units are built

This commit is contained in:
Émilie Feral
2020-05-07 10:23:39 +02:00
parent a48f65ba95
commit 0f4eee2d71
2 changed files with 10 additions and 0 deletions

View File

@@ -188,6 +188,13 @@ public:
typedef UnitNode::Prefix Prefix;
typedef UnitNode::Representative Representative;
typedef UnitNode::Dimension Dimension;
/* TODO: Prefix, Representative and Dimension defined below must be defined
* only once and all units must be constructed from their pointers. This way
* we can easily check if two Unit objects are equal by comparing pointers.
* This saves us from overloading the == operator on Prefix, Representative
* and Dimension and saves time at execution. We should assert at compilation
* that only one occurence of each is built by maybe privatizing constructors
* on these classes? */
static constexpr const Prefix
PicoPrefix = Prefix("p", -12),
NanoPrefix = Prefix("n", -9),

View File

@@ -393,15 +393,18 @@ Expression Unit::removeUnit(Expression * unit) {
}
bool Unit::isSecond() const {
// TODO: comparing pointers suffices because all time dimension are built from the same pointers. This should be asserted some way at compile-time?
return node()->dimension() == TimeDimension && node()->representative() == SecondRepresentative && node()->prefix() == &EmptyPrefix;
}
bool Unit::isMeter() const {
// See comment on isSecond
return node()->dimension() == DistanceDimension && node()->representative() == MeterRepresentative && node()->prefix() == &EmptyPrefix;
}
bool Unit::isKilogram() const {
// See comment on isSecond
return node()->dimension() == MassDimension && node()->representative() == KilogramRepresentative && node()->prefix() == &KiloPrefix;
}