Skip to content

Commit

Permalink
Base: improve Quantity parser
Browse files Browse the repository at this point in the history
Add Quantity::concat() to handle quantity concatenation, which can
either be plus or minus depending on the signedness of the left
quantity.

1m1mm is interpreted as 1m plus 1mm,

-1m1mm means -1m minus 1mm.

-1m-1mm means -1m minus -1mm, i.e. -1m plus 1mm.

(0-1)m-1mm means -1m minus -1mm, i.e. -1m plus 1mm.
  • Loading branch information
realthunder committed Mar 23, 2020
1 parent eb0c138 commit e51749f
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 184 deletions.
10 changes: 10 additions & 0 deletions src/Base/Quantity.cpp
Expand Up @@ -164,6 +164,16 @@ Quantity Quantity::pow(double p) const
);
}

Quantity Quantity::concat(const Quantity &p) const
{
if (this->_Unit != p._Unit)
throw Base::UnitsMismatchError("Quantity: Unit mismatch in concat operation");
if(_Value >= 0.0)
return Quantity(this->_Value + p._Value,this->_Unit);
else
return Quantity(this->_Value - p._Value,this->_Unit);
}

Quantity Quantity::operator +(const Quantity &p) const
{
if (this->_Unit != p._Unit)
Expand Down
1 change: 1 addition & 0 deletions src/Base/Quantity.h
Expand Up @@ -137,6 +137,7 @@ class BaseExport Quantity
Quantity& operator =(const Quantity&);
Quantity pow(const Quantity&)const;
Quantity pow(double)const;
Quantity concat(const Quantity &)const;
//@}

const QuantityFormat& getFormat() const {
Expand Down

0 comments on commit e51749f

Please sign in to comment.