SettingsHelpers.h#
Fully qualified name: omni/extras/SettingsHelpers.h
File members: omni/extras/SettingsHelpers.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/settings/SettingsUtils.h"
#include <string>
#include <vector>
namespace carb
{
namespace settings
{
template <typename T>
T getSettingOrDefault(const char* path, T defaultValue = {})
{
ISettings* s = getCachedInterface<ISettings>();
if (s->getItemType(path) == dictionary::ItemType::eCount)
return defaultValue;
return s->get<T>(path);
}
template <typename T>
T setDefaultAndGetSetting(const char* path, T defaultValue = {})
{
ISettings* s = getCachedInterface<ISettings>();
s->setDefault<T>(path, defaultValue);
return s->get<T>(path);
}
inline void appendToStringArray(const char* path, const std::vector<std::string>& values)
{
if (values.empty())
return;
ISettings* s = getCachedInterface<ISettings>();
carb::settings::ScopedWrite writeLock; // Hold a write lock while the modification takes place
// TODO: This could be implemented a lot more efficiently than fully copying everything twice
std::vector<std::string> v = settings::getStringArray(s, path);
v.insert(v.end(), values.begin(), values.end());
settings::setStringArray(s, path, v);
}
} // namespace settings
} // namespace carb