MCPcopy Create free account
hub / github.com/Illation/ETEngine / ArrayToJsonArray

Function ArrayToJsonArray

Engine/source/EtCore/Reflection/serialization.cpp:329–384  ·  view source on GitHub ↗

--------------------------------- ArrayToJsonArray Converts a sequential view to a JSON array

Source from the content-addressed store, hash-verified

327// Converts a sequential view to a JSON array
328//
329bool 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//---------------------------------

Callers 1

VariantToJsonValueFunction · 0.85

Calls 2

AtomicTypeToJsonValueFunction · 0.85
ToJsonRecursiveFunction · 0.85

Tested by

no test coverage detected