Loading...
Searching...
No Matches
valueTypeDispatch.h
1//
2// Copyright 2024 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_BASE_TS_VALUE_TYPE_DISPATCH_H
9#define PXR_BASE_TS_VALUE_TYPE_DISPATCH_H
10
11#include "pxr/pxr.h"
12#include "pxr/base/ts/typeHelpers.h"
13#include "pxr/base/gf/half.h"
14#include "pxr/base/tf/type.h"
16
17#include <utility>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21
22// Makes a call to a template functor based on a dynamic type. No return value;
23// obtain outputs with out-params. Supports all valid spline value types.
24//
25// Example:
26//
27// template <typename T>
28// struct _HasNonzeroValue
29// {
30// void operator()(const TsKnot &knot, bool *resultOut)
31// {
32// T value = 0;
33// if (knot.GetValue(&value))
34// *resultOut = (value != 0);
35// else
36// *resultOut = false;
37// }
38// };
39//
40// bool nonzero = false;
41// TsDispatchToValueTypeTemplate<_HasNonzeroValue>(
42// myKnot.GetValueType(), myKnot, &nonzero);
43//
44template <
45 template <typename T> class Cls,
46 typename... Args>
47void TsDispatchToValueTypeTemplate(
48 TfType valueType, Args&&... args)
49{
50#define _MAKE_CLAUSE(unused, tuple) \
51if (valueType == Ts_GetType<TS_SPLINE_VALUE_CPP_TYPE(tuple)>()) \
52{ \
53 Cls<TS_SPLINE_VALUE_CPP_TYPE(tuple)>()(std::forward<Args>(args)...); \
54 return; \
55}
56TF_PP_SEQ_FOR_EACH(_MAKE_CLAUSE, ~, TS_SPLINE_SUPPORTED_VALUE_TYPES)
57 TF_CODING_ERROR("Unsupported spline value type");
58}
59#undef _MAKE_CLAUSE
60
61PXR_NAMESPACE_CLOSE_SCOPE
62
63#endif
Low-level utilities for informing users of various internal and external diagnostic conditions.
TfType represents a dynamic runtime type.
Definition: type.h:48
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68
This header serves to simply bring in the half float datatype and provide a hash_value function.