| 19 | // |
| 20 | |
| 21 | LinearUnitConverter::LinearUnitConverter(UnitTypeDefPtr unitTypeDef) |
| 22 | { |
| 23 | if (!unitTypeDef) |
| 24 | { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // Populate the unit scale and offset maps for each UnitDef. |
| 29 | unsigned int enumerant = 0; |
| 30 | for (UnitDefPtr unitdef : unitTypeDef->getUnitDefs()) |
| 31 | { |
| 32 | for (UnitPtr unit : unitdef->getUnits()) |
| 33 | { |
| 34 | const string& name = unit->getName(); |
| 35 | if (!name.empty()) |
| 36 | { |
| 37 | const string& scaleString = unit->getAttribute(SCALE_ATTRIBUTE); |
| 38 | if (!scaleString.empty()) |
| 39 | { |
| 40 | ValuePtr scaleValue = Value::createValueFromStrings(scaleString, getTypeString<float>()); |
| 41 | _unitScale[name] = scaleValue->asA<float>(); |
| 42 | } |
| 43 | else |
| 44 | { |
| 45 | _unitScale[name] = 1.0f; |
| 46 | } |
| 47 | _unitEnumeration[name] = enumerant++; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | _unitType = unitTypeDef->getName(); |
| 53 | } |
| 54 | |
| 55 | LinearUnitConverterPtr LinearUnitConverter::create(UnitTypeDefPtr unitTypeDef) |
| 56 | { |
nothing calls this directly
no test coverage detected