| 58 | } |
| 59 | |
| 60 | void LinearUnitConverter::write(DocumentPtr doc) const |
| 61 | { |
| 62 | if (!doc->getUnitTypeDef(_unitType)) |
| 63 | { |
| 64 | // Add a unittypedef |
| 65 | doc->addUnitTypeDef(_unitType); |
| 66 | |
| 67 | // Add a unitdef definition |
| 68 | string unitdefName = "UD_stdlib_" + _unitType; |
| 69 | if (!doc->getUnitDef(unitdefName)) |
| 70 | { |
| 71 | UnitDefPtr unitDef = doc->addUnitDef(unitdefName); |
| 72 | unitDef->setUnitType(_unitType); |
| 73 | |
| 74 | // Add in units to the definition |
| 75 | for (const auto& unitScale : _unitScale) |
| 76 | { |
| 77 | const string& unitName = unitScale.first; |
| 78 | UnitPtr unitPtr = unitDef->addUnit(unitName); |
| 79 | unitPtr->setAttribute(SCALE_ATTRIBUTE, std::to_string(unitScale.second)); |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | float LinearUnitConverter::conversionRatio(const string& inputUnit, const string& outputUnit) const |
| 86 | { |