TODO probably should be in OS proper helper method to do unit conversions;
| 1948 | //TODO probably should be in OS proper |
| 1949 | //helper method to do unit conversions; |
| 1950 | boost::optional<double> ReverseTranslator::unitToUnit(double val, const std::string& fstUnitString, const std::string& secUnitString) { |
| 1951 | //create the units from the strings |
| 1952 | boost::optional<Unit> fstUnit = UnitFactory::instance().createUnit(fstUnitString); |
| 1953 | boost::optional<Unit> secUnit = UnitFactory::instance().createUnit(secUnitString); |
| 1954 | |
| 1955 | //make sure both unit strings were valid |
| 1956 | if (fstUnit && secUnit) { |
| 1957 | |
| 1958 | //make the IP quantity |
| 1959 | Quantity ipQuant = Quantity(val, *fstUnit); |
| 1960 | |
| 1961 | //convert the IP quantity from IP to SI |
| 1962 | boost::optional<Quantity> siQuant = QuantityConverter::instance().convert(ipQuant, *secUnit); |
| 1963 | |
| 1964 | //if the conversion |
| 1965 | if (siQuant) { |
| 1966 | return siQuant->value(); |
| 1967 | } |
| 1968 | } |
| 1969 | |
| 1970 | return boost::none; |
| 1971 | } |
| 1972 | |
| 1973 | bool ReverseTranslator::autosize() const { |
| 1974 | if (m_masterAutosize) { |
nothing calls this directly
no test coverage detected