| 254 | // --------------------------------------------------------------------------- |
| 255 | |
| 256 | void UnitOfMeasure::_exportToJSON( |
| 257 | JSONFormatter *formatter) const // throw(FormattingException) |
| 258 | { |
| 259 | auto writer = formatter->writer(); |
| 260 | const auto &l_codeSpace = codeSpace(); |
| 261 | auto objContext( |
| 262 | formatter->MakeObjectContext(nullptr, !l_codeSpace.empty())); |
| 263 | writer->AddObjKey("type"); |
| 264 | const auto l_type = type(); |
| 265 | if (l_type == Type::LINEAR) { |
| 266 | writer->Add("LinearUnit"); |
| 267 | } else if (l_type == Type::ANGULAR) { |
| 268 | writer->Add("AngularUnit"); |
| 269 | } else if (l_type == Type::SCALE) { |
| 270 | writer->Add("ScaleUnit"); |
| 271 | } else if (l_type == Type::TIME) { |
| 272 | writer->Add("TimeUnit"); |
| 273 | } else if (l_type == Type::PARAMETRIC) { |
| 274 | writer->Add("ParametricUnit"); |
| 275 | } else { |
| 276 | writer->Add("Unit"); |
| 277 | } |
| 278 | |
| 279 | writer->AddObjKey("name"); |
| 280 | const auto &l_name = name(); |
| 281 | writer->Add(l_name); |
| 282 | |
| 283 | const auto &factor = conversionToSI(); |
| 284 | writer->AddObjKey("conversion_factor"); |
| 285 | writer->Add(factor, 15); |
| 286 | |
| 287 | if (!l_codeSpace.empty() && formatter->outputId()) { |
| 288 | writer->AddObjKey("id"); |
| 289 | auto idContext(formatter->MakeObjectContext(nullptr, false)); |
| 290 | writer->AddObjKey("authority"); |
| 291 | writer->Add(l_codeSpace); |
| 292 | writer->AddObjKey("code"); |
| 293 | const auto &l_code = code(); |
| 294 | try { |
| 295 | writer->Add(std::stoi(l_code)); |
| 296 | } catch (const std::exception &) { |
| 297 | writer->Add(l_code); |
| 298 | } |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | //! @endcond |
| 303 |
no test coverage detected