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 {
110 explicit operator bool()
const;
145 std::vector<std::string> errors;
155 std::unordered_set<std::string> usedVariables;
200 template <
class ResultType>
206 r.value =
VtValue(ResultType());
208 else if (!r.value.IsEmpty() && !r.value.IsHolding<ResultType>()) {
210 _FormatUnexpectedTypeError(r.value,
VtValue(ResultType())));
254 Builder(std::string&& expr) : _expr(std::move(expr)) { }
266 template <
class Argument>
270 SDF_API
operator Builder() const &;
287 template <
class Element>
296 SDF_API
operator Builder() const &;
311 template <
class... Arguments>
312 static FunctionBuilder
316 (b.
AddArgument(std::forward<Arguments>(fnArgs)), ...);
325 template <
class... Elements>
330 (b.
AddElement(std::forward<Elements>(elems)), ...);
364 _FormatUnexpectedTypeError(
const VtValue& got,
const VtValue& expected);
373 _AppendBuilder(std::string* expr,
const Builder& b,
bool first);
375 template <
class Argument>
377 _Append(std::string* expr, Argument&& arg,
bool first)
381 if constexpr (std::is_same_v<
383 _AppendExpression(expr, std::forward<Argument>(arg), first);
386 _AppendBuilder(expr, std::forward<Argument>(arg), first);
390 std::vector<std::string> _errors;
391 std::shared_ptr<Sdf_VariableExpressionImpl::Node> _expression;
392 std::string _expressionStr;
411template <
class Argument>
415 SdfVariableExpression::_Append(
416 &_expr, std::forward<Argument>(arg),
417 *_expr.rbegin() ==
'(');
421template <
class Element>
425 SdfVariableExpression::_Append(
426 &_expr, std::forward<Element>(arg),
427 *_expr.rbegin() ==
'[');
434 const std::vector<T>& values)
436 for (
const T& v : values) {
442PXR_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 bool IsValidVariableType(const VtValue &value)
Returns true if value holds a type that is supported by variable expressions, false otherwise.
SDF_API SdfVariableExpression(std::string &&expr)
This is an overloaded member function, provided for convenience. It differs from the above function o...
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 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...
A trait to detect instantiations of VtArray, specialized in array.h.