--------------------------------- ArrayToJsonArray Converts a sequential view to a JSON array
| 327 | // Converts a sequential view to a JSON array |
| 328 | // |
| 329 | bool ArrayToJsonArray(const rttr::variant_sequential_view& view, JSON::Value*& outVal) |
| 330 | { |
| 331 | JSON::Array* outArr = new JSON::Array(); |
| 332 | outVal = outArr; |
| 333 | |
| 334 | bool allItemsSucceeded = true; |
| 335 | |
| 336 | for (const auto& item : view) |
| 337 | { |
| 338 | JSON::Value* jItem = nullptr; |
| 339 | |
| 340 | if (item.is_sequential_container()) // inner array |
| 341 | { |
| 342 | if (!ArrayToJsonArray(item.create_sequential_view(), jItem)) |
| 343 | { |
| 344 | LOG("ArrayToJsonArray > failed to convert array element to inner json array, typeName: '" + |
| 345 | item.get_type().get_name().to_string() + std::string("'!"), LogLevel::Warning); |
| 346 | |
| 347 | allItemsSucceeded = false; |
| 348 | } |
| 349 | } |
| 350 | else // atomic type or object |
| 351 | { |
| 352 | rttr::variant wrappedVar = item.extract_wrapped_value(); |
| 353 | rttr::type valueType = wrappedVar.get_type(); |
| 354 | |
| 355 | if (valueType.is_arithmetic() |
| 356 | || (valueType == rttr::type::get<std::string>()) |
| 357 | || valueType.is_enumeration() |
| 358 | || (valueType == rttr::type::get<HashString>())) |
| 359 | { |
| 360 | if (!AtomicTypeToJsonValue(valueType, wrappedVar, jItem)) |
| 361 | { |
| 362 | LOG("ArrayToJsonArray > failed to convert array element to atomic type, typeName: '" + valueType.get_name().to_string() |
| 363 | + std::string("'!"), LogLevel::Warning); |
| 364 | |
| 365 | allItemsSucceeded = false; |
| 366 | } |
| 367 | } |
| 368 | else // object |
| 369 | { |
| 370 | if (!ToJsonRecursive(wrappedVar, jItem, valueType)) |
| 371 | { |
| 372 | LOG("ArrayToJsonArray > failed to convert array element to json object, typeName: '" + valueType.get_name().to_string() |
| 373 | + std::string("'!"), LogLevel::Warning); |
| 374 | |
| 375 | allItemsSucceeded = false; |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
| 380 | outArr->value.emplace_back(jItem); |
| 381 | } |
| 382 | |
| 383 | return allItemsSucceeded; |
| 384 | } |
| 385 | |
| 386 | //--------------------------------- |
no test coverage detected