MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / unitToUnit

Method unitToUnit

src/sdd/ReverseTranslator.cpp:1950–1971  ·  view source on GitHub ↗

TODO probably should be in OS proper helper method to do unit conversions;

Source from the content-addressed store, hash-verified

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) {

Callers

nothing calls this directly

Calls 4

createUnitMethod · 0.80
QuantityClass · 0.50
convertMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected