MCPcopy Create free account
hub / github.com/OSGeo/gdal / ReadAsStringArray

Method ReadAsStringArray

gcore/multidim/gdalmultidim_attribute.cpp:471–495  ·  view source on GitHub ↗

Return the value of an attribute as an array of strings. * * This is the same as the C function GDALAttributeReadAsStringArray() */

Source from the content-addressed store, hash-verified

469 * This is the same as the C function GDALAttributeReadAsStringArray()
470 */
471CPLStringList GDALAttribute::ReadAsStringArray() const
472{
473 const auto nElts = GetTotalElementsCount();
474 if (nElts > static_cast<unsigned>(std::numeric_limits<int>::max() - 1))
475 return CPLStringList();
476 char **papszList = static_cast<char **>(
477 VSI_CALLOC_VERBOSE(static_cast<int>(nElts) + 1, sizeof(char *)));
478 const auto &dims = GetDimensions();
479 const auto nDims = GetDimensionCount();
480 std::vector<GUInt64> startIdx(1 + nDims, 0);
481 std::vector<size_t> count(1 + nDims);
482 for (size_t i = 0; i < nDims; i++)
483 {
484 count[i] = static_cast<size_t>(dims[i]->GetSize());
485 }
486 Read(startIdx.data(), count.data(), nullptr, nullptr,
487 GDALExtendedDataType::CreateString(), papszList, papszList,
488 sizeof(char *) * static_cast<int>(nElts));
489 for (int i = 0; i < static_cast<int>(nElts); i++)
490 {
491 if (papszList[i] == nullptr)
492 papszList[i] = CPLStrdup("");
493 }
494 return CPLStringList(papszList);
495}
496
497/************************************************************************/
498/* ReadAsIntArray() */

Calls 4

CPLStrdupFunction · 0.85
maxFunction · 0.50
GetSizeMethod · 0.45
dataMethod · 0.45