| 243 | } |
| 244 | |
| 245 | boost::optional<Unit> UnitFactory::createUnitSimple(const std::string& unitString, UnitSystem system) const { |
| 246 | if (unitString.empty()) { |
| 247 | Unit result = createDimensionlessUnit(system); |
| 248 | if (OptionalTemperatureUnit T = result.optionalCast<TemperatureUnit>()) { |
| 249 | T->setAsRelative(); |
| 250 | } |
| 251 | return result; |
| 252 | } |
| 253 | |
| 254 | OptionalUnit candidate; |
| 255 | StandardStringLookupMap::const_iterator lookupPair; |
| 256 | auto standardStringMapEnd = m_standardStringLookupMap.end(); |
| 257 | lookupPair = m_standardStringLookupMap.find(unitString); |
| 258 | if (lookupPair != standardStringMapEnd) { |
| 259 | |
| 260 | // unitString is registered |
| 261 | for (const std::string& standardString : lookupPair->second) { |
| 262 | |
| 263 | // instantiate the standardString |
| 264 | CallbackMapMap::const_iterator callbackMap; |
| 265 | StandardStringCallbackMap::const_iterator callbackPair; |
| 266 | OptionalUnit temp; |
| 267 | // try base map |
| 268 | callbackMap = m_callbackMaps.find(UnitSystem(UnitSystem::Mixed)); |
| 269 | OS_ASSERT(callbackMap != m_callbackMaps.end()); |
| 270 | callbackPair = callbackMap->second.find(standardString); |
| 271 | // clang-modernize note: This line must not compare against nullptr |
| 272 | if ((callbackPair != callbackMap->second.end()) && (callbackPair->second != NULL)) { |
| 273 | temp = callbackPair->second(); |
| 274 | } else { |
| 275 | // try system map |
| 276 | callbackMap = m_callbackMaps.find(system); |
| 277 | if (callbackMap != m_callbackMaps.end()) { |
| 278 | callbackPair = callbackMap->second.find(standardString); |
| 279 | // clang-modernize note: This line must not compare against nullptr |
| 280 | if ((callbackPair != callbackMap->second.end()) && (callbackPair->second != NULL)) { |
| 281 | temp = callbackPair->second(); |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | // try all other maps |
| 286 | if (!temp) { |
| 287 | for (int sysValue : UnitSystem::getValues()) { |
| 288 | UnitSystem tempSystem(sysValue); |
| 289 | if ((tempSystem == UnitSystem::Mixed) || (tempSystem == system)) { |
| 290 | continue; |
| 291 | } |
| 292 | callbackMap = m_callbackMaps.find(tempSystem); |
| 293 | if (callbackMap != m_callbackMaps.end()) { |
| 294 | callbackPair = callbackMap->second.find(standardString); |
| 295 | // clang-modernize note: This line must not compare against nullptr |
| 296 | if ((callbackPair != callbackMap->second.end()) && (callbackPair->second != NULL)) { |
| 297 | temp = callbackPair->second(); |
| 298 | break; |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
nothing calls this directly
no test coverage detected