/*
    PIP - Platform Independent Primitives
	Mass units
    Ivan Pelipenko peri4ko@yandex.ru

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "piunits_class_mass.h"


PIString PIUnits::Class::Mass::name(int type) const {
	switch (type) {
	case Gram: return "gram"_tr("PIUnitsMass");
	case Pound: return "pound"_tr("PIUnitsMass");
	case Ounce: return "ounce"_tr("PIUnitsMass");
	}
	return Class::Internal::unknown;
}


PIString PIUnits::Class::Mass::unit(int type) const {
	switch (type) {
	case Gram: return "g"_tr("PIUnitsMass");
	case Pound: return "lb"_tr("PIUnitsMass");
	case Ounce: return "℥"_tr("PIUnitsMass");
	}
	return Class::Internal::unknown;
}


double PIUnits::Class::Mass::convert(double v, int from, int to) const {
	static constexpr double pound_to_g = 453.59237;
	static constexpr double ounce_to_g = 28.349523125;
	double g                           = v;
	switch (from) {
	case Pound: g *= pound_to_g; break;
	case Ounce: g *= ounce_to_g; break;
	}
	switch (to) {
	case Pound: g /= pound_to_g; break;
	case Ounce: g /= ounce_to_g; break;
	}
	return g;
}


PIString PIUnits::Class::Mass::valueToString(double v, char format, int prec) const {
	return PIString::fromNumber(v, format, prec);
}


bool PIUnits::Class::Mass::supportPrefixes(int type) const {
	return type == Gram;
}


bool PIUnits::Class::Mass::supportPrefixesNon3(int type) const {
	return false;
}


bool PIUnits::Class::Mass::supportPrefixesGreater(int type) const {
	return ClassBase::supportPrefixesGreater(type);
}


bool PIUnits::Class::Mass::supportPrefixesSmaller(int type) const {
	return ClassBase::supportPrefixesSmaller(type);
}
