DictHelpers.h#
Fully qualified name: omni/extras/DictHelpers.h
File members: omni/extras/DictHelpers.h
// SPDX-FileCopyrightText: Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: LicenseRef-NvidiaProprietary
//
// NVIDIA CORPORATION, its affiliates and licensors retain all intellectual
// property and proprietary rights in and to this material, related
// documentation and any modifications thereto. Any use, reproduction,
// disclosure or distribution of this material and related documentation
// without an express license agreement from NVIDIA CORPORATION or
// its affiliates is strictly prohibited.
#pragma once
#include "../../carb/dictionary/DictionaryUtils.h"
#include <string>
#include <vector>
namespace carb
{
namespace dictionary
{
template <typename T>
T getValueOrDefault(const Item* baseItem, const char* path, T defaultValue)
{
IDictionary* d = getCachedDictionaryInterface();
auto item = d->getItem(baseItem, path);
if (!item)
return defaultValue;
return d->get<T>(item);
}
inline Item* makeStringArrayAtPath(Item* baseItem, const char* path, const std::vector<std::string>& arr)
{
IDictionary* dict = getCachedDictionaryInterface();
ScopedWrite g(*dict, baseItem);
Item* item = dict->getItemMutable(baseItem, path);
if (!item)
{
item = dict->createItem(baseItem, path, ItemType::eDictionary);
}
for (size_t i = 0, count = arr.size(); i < count; ++i)
{
dict->setStringAt(item, i, arr[i].c_str());
}
return item;
}
} // namespace dictionary
} // namespace carb