ITokens2.h#

Fully qualified name: carb/tokens/detail/ITokens2.h

File members: carb/tokens/detail/ITokens2.h

// SPDX-FileCopyrightText: Copyright (c) 2025-2026 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

#ifndef carb_tokens_ITokens_latest
#    error Must include via ../ITokens.h
#endif

#if !CARB_VERSION_ATLEAST(carb_tokens_ITokens, 2, 0)
#    error Version too low to be included
#endif

#include "../../../omni/String.h"
#include "../../../omni/Expected.h"
#include "../../cpp/Optional.h"
#include "../../cpp/StringView.h"
#include "../../Defines.h"

namespace carb::tokens
{

#ifndef DOXYGEN_BUILD
inline namespace v2
{
#endif

class ITokens
{
public:
    // 2.0 - Virtual interface with string_view support
    CARB_PLUGIN_INTERFACE_EX("carb::tokens::ITokens", carb_tokens_ITokens_latest, carb_tokens_ITokens)

    virtual bool setValue(cpp::string_view name, cpp::string_view value) noexcept = 0;

    virtual bool setInitialValue(cpp::string_view name, cpp::string_view value) noexcept = 0;

    virtual bool deleteValue(cpp::string_view name) noexcept = 0;

    omni::expected<omni::string, ResolveError> resolveString(cpp::string_view source,
                                                             ResolveFlags resolveFlags = kResolveFlagNone) const noexcept
    {
        omni::string out;
        return resolveString(source, out, resolveFlags).transform([&] { return out; });
    }

    virtual omni::expected<void, ResolveError> resolveString(
        cpp::string_view source, omni::string& out, ResolveFlags resolveFlags = kResolveFlagNone) const noexcept = 0;

    virtual bool exists(cpp::string_view tokenName) const noexcept = 0;

    virtual cpp::optional<omni::string> getValue(cpp::string_view name) const noexcept = 0;

#if CARB_VERSION_ATLEAST(carb_tokens_ITokens, 2, 1)
    virtual void lock() const noexcept = 0;

    virtual void unlock() const noexcept = 0;
#endif
};

#ifndef DOXYGEN_BUILD
} // inline namespace v2
#endif

} // namespace carb::tokens