diff --git a/poincare/include/poincare/unit.h b/poincare/include/poincare/unit.h index 3be06ccf6..e78b58905 100644 --- a/poincare/include/poincare/unit.h +++ b/poincare/include/poincare/unit.h @@ -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), diff --git a/poincare/src/unit.cpp b/poincare/src/unit.cpp index 97b05093a..769e575a3 100644 --- a/poincare/src/unit.cpp +++ b/poincare/src/unit.cpp @@ -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; }