7#ifndef PXR_USD_SDF_VARIABLE_EXPRESSION
8#define PXR_USD_SDF_VARIABLE_EXPRESSION
13#include "pxr/usd/sdf/api.h"
17#include "pxr/base/vt/value.h"
21#include <unordered_set>
24PXR_NAMESPACE_OPEN_SCOPE
26namespace Sdf_VariableExpressionImpl {
109 explicit operator bool()
const;
144 std::vector<std::string> errors;
154 std::unordered_set<std::string> usedVariables;
199 template <
class ResultType>
205 r.value =
VtValue(ResultType());
209 _FormatUnexpectedTypeError(r.value,
VtValue(ResultType())));
253 Builder(std::string&& expr) : _expr(std::move(expr)) { }
265 template <
class Argument>
269 SDF_API
operator Builder() const &;
286 template <
class Element>
295 SDF_API
operator Builder() const &;
310 template <
class... Arguments>
311 static FunctionBuilder
315 (b.
AddArgument(std::forward<Arguments>(fnArgs)), ...);
324 template <
class... Elements>
329 (b.
AddElement(std::forward<Elements>(elems)), ...);
373 _FormatUnexpectedTypeError(
const VtValue& got,
const VtValue& expected);
382 _AppendBuilder(std::string* expr,
const Builder& b,
bool first);
384 template <
class Argument>
386 _Append(std::string* expr, Argument&& arg,
bool first)
390 if constexpr (std::is_same_v<
392 _AppendExpression(expr, std::forward<Argument>(arg), first);
395 _AppendBuilder(expr, std::forward<Argument>(arg), first);
399 std::vector<std::string> _errors;
400 std::shared_ptr<Sdf_VariableExpressionImpl::Node> _expression;
401 std::string _expressionStr;
420template <
class Argument>
424 SdfVariableExpression::_Append(
425 &_expr, std::forward<Argument>(arg),
426 *_expr.rbegin() ==
'(');
430template <
class Element>
434 SdfVariableExpression::_Append(
435 &_expr, std::forward<Element>(arg),
436 *_expr.rbegin() ==
'[');
443 const std::vector<T>& values)
445 for (
const T& v : values) {
451PXR_NAMESPACE_CLOSE_SCOPE
Helper class for storing intermediate results when building a variable expression.
Helper class for storing intermediate results when building a function variable expression.
FunctionBuilder & AddArgument(Argument &&arg)
Add an expression as an argument to the function call.
Helper class for storing intermediate results when building a list variable expression.
ListBuilder & AddElement(Element &&elem)
Add an expression as an element to the list.
ListBuilder & AddLiteralValues(const std::vector< T > &values)
Add values in values as literal expressions to the list.
Class responsible for parsing and evaluating variable expressions.
SDF_API const std::string & GetString() const
Returns the expression string used to construct this object.
static SDF_API bool IsExpression(const std::string &s)
Returns true if s is a variable expression, false otherwise.
SDF_API SdfVariableExpression()
Construct an object representing an invalid expression.
static ListBuilder MakeListOfLiterals(const std::vector< T > &values)
Create a list expression with the values in values as literal elements.
static FunctionBuilder MakeFunction(const std::string &fnName, Arguments &&... fnArgs)
Create a function expression that calls the function named fnName with fnArgs as arguments,...
static SDF_API Builder MakeVariable(const std::string &name, const Builder &fallbackValue)
Create a variable reference expression for the variable named name and fallbackValue,...
static SDF_API bool IsValidVariableType(const VtValue &value)
Returns true if value holds a type that is supported by variable expressions, false otherwise.
SDF_API Result Evaluate(const VtDictionary &variables) const
Evaluates this expression using the variables in variables and returns a Result object with the final...
SDF_API const std::vector< std::string > & GetErrors() const
Returns a list of errors encountered when parsing this expression.
static SDF_API Builder MakeVariable(const std::string &name)
Create a variable reference expression for the variable named name, i.e.
static SDF_API Builder MakeNone()
Create a "None" literal expression.
static SDF_API Builder MakeVariable(const std::string &name, const SdfVariableExpression &fallbackValue)
Create a variable reference expression whose fallback is the expression fallbackValue.
static ListBuilder MakeList(Elements &&... elems)
Create a list expression with listElems as elements, i.e.
Result EvaluateTyped(const VtDictionary &variables) const
Evaluates this expression using the variables in variables and returns a Result object with the final...
static SDF_API Builder MakeLiteral(int64_t value)
Create a literal expression for value.
SDF_API SdfVariableExpression(const std::string &expr)
Construct using the expression expr.
A result value representing an empty list.
A map with string keys and VtValue values.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
bool IsEmpty() const
Returns true iff this value is empty.
bool IsHolding() const
Return true if this value is holding an object of type T, false otherwise.
A trait to detect instantiations of VtArray, specialized in array.h.