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