carb/tokens/ITokens.h
File members: carb/tokens/ITokens.h
// Copyright (c) 2019-2024, NVIDIA CORPORATION. All rights reserved.
//
// NVIDIA CORPORATION and its licensors retain all intellectual property
// and proprietary rights in and to this software, related documentation
// and any modifications thereto. Any use, reproduction, disclosure or
// distribution of this software and related documentation without an express
// license agreement from NVIDIA CORPORATION is strictly prohibited.
//
#pragma once
#include "../Interface.h"
namespace carb
{
namespace tokens
{
enum class ResolveResult
{
eSuccess,
eTruncated,
eFailure,
};
enum class StringEndingMode
{
eNullTerminator,
eNoNullTerminator
};
using ResolveFlags = uint32_t;
const ResolveFlags kResolveFlagNone = 0;
const ResolveFlags kResolveFlagLeaveTokenIfNotFound = 1;
struct ITokens
{
CARB_PLUGIN_INTERFACE("carb::tokens::ITokens", 1, 0)
bool(CARB_ABI* setValue)(const char* name, const char* value);
void setInitialValue(const char* name, const char* value) const;
bool removeToken(const char* name) const;
ResolveResult(CARB_ABI* resolveString)(const char* sourceBuf,
size_t sourceBufLen,
char* destBuf,
size_t destBufLen,
StringEndingMode endingMode,
ResolveFlags resolveFlags,
size_t* resolvedSize);
size_t(CARB_ABI* calculateDestinationBufferSize)(const char* sourceBuf,
size_t sourceBufLen,
StringEndingMode endingMode,
ResolveFlags resolveFlags,
ResolveResult* resolveResult);
bool(CARB_ABI* exists)(const char* tokenName);
};
inline void ITokens::setInitialValue(const char* name, const char* value) const
{
if (!exists(name) && value)
{
setValue(name, value);
}
}
inline bool ITokens::removeToken(const char* name) const
{
return setValue(name, nullptr);
}
} // namespace tokens
} // namespace carb