Brewtarget / brewtarget

Main brewtarget source code repository.
GNU General Public License v3.0
315 stars 135 forks source link

Tidy up Unit, UnitSystem classes etc #587

Closed matty0ung closed 3 years ago

matty0ung commented 3 years ago

It seemed to me that these classes were more complicated than they needed to be, especially with modern C++ features such as lambdas available to us. This tidies them up and, in the process, fixes https://github.com/Brewtarget/brewtarget/issues/560.

Look at Unit.h, Unit.cpp, UnitSystem.h, UnitSystem.cpp first and then all the other consequential changes hopefully make sense.

Essentially, I've got rid of all the subclasses of Unit and UnitSystem because they were repeating code unnecessarily. The differences between different units and unit systems are just data and (simple) formulae, so they don't need a plethora of subclasses. I also removed/fixed some comments that seemed incorrect (eg about the iteration order of QMap).

I think there is still room for some further tidying up of UnitSystem (see comments in that class), but hopefully this is already something of an improvement.

mattiasmaahl commented 3 years ago

Beautiful coding, really admire your coding style!