PathAlias.h#

Fully qualified name: carb/tokens/PathAlias.h

File members: carb/tokens/PathAlias.h

// SPDX-FileCopyrightText: Copyright (c) 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 "TokensUtils.h"
#include "../cpp/StringView.h"
#include "../Defines.h"

namespace carb::tokens
{

#if !CARB_VERSION_ATLEAST(carb_tokens_ITokens, 2, 0)

inline void registerPathAlias(const char* alias, const char* value)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();
    CARB_IGNORE_DEPRECATION_BEGIN
    tokens->setValue(alias, value);
    CARB_IGNORE_DEPRECATION_END
}

inline void unregisterPathAlias(const char* alias)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();

    CARB_IGNORE_DEPRECATION_BEGIN
    tokens->removeToken(alias);
    CARB_IGNORE_DEPRECATION_END
}

inline std::string resolvePathAliases(const char* srcBuf)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();
    return carb::tokens::resolveString(tokens, carb::cpp::string_view(carb::cpp::unsafe_length, srcBuf));
}

#else // CARB_VERSION_ATLEAST(carb_tokens_ITokens, 2, 0)

inline bool registerPathAlias(cpp::string_view alias, cpp::string_view value)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();
    if (!tokens)
        return false;
    return carb::tokens::detail::setValue(tokens, alias, value);
}

inline bool unregisterPathAlias(cpp::string_view alias)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();
    if (!tokens)
        return false;
    return carb::tokens::detail::deleteValue(tokens, alias);
}

inline omni::expected<omni::string, ResolveError> resolvePathAliases(cpp::string_view srcBuf)
{
    auto tokens = carb::getCachedInterface<carb::tokens::ITokens>();
    return carb::tokens::detail::resolveString(tokens, srcBuf);
}

#endif // CARB_VERSION_ATLEAST(carb_tokens_ITokens, 2, 0)

} // namespace carb::tokens