HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
valueTypeDispatch.h
Go to the documentation of this file.
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"
13 #include "pxr/base/gf/half.h"
14 #include "pxr/base/tf/type.h"
15 #include "pxr/base/tf/diagnostic.h"
16 
17 #include <utility>
18 
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 //
44 template <
45  template <typename T> class Cls,
46  typename... Args>
48  TfType valueType, Args&&... args)
49 {
50 #define _MAKE_CLAUSE(unused, tuple) \
51 if (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 }
57  TF_CODING_ERROR("Unsupported spline value type");
58 }
59 
60 
62 
63 #endif
#define TF_CODING_ERROR
PXR_NAMESPACE_OPEN_SCOPE void TsDispatchToValueTypeTemplate(TfType valueType, Args &&...args)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define TF_PP_SEQ_FOR_EACH(_macro, data, seq)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
**If you just want to fire and args
Definition: thread.h:618
Definition: type.h:47
#define TS_SPLINE_SUPPORTED_VALUE_TYPES
Definition: types.h:29
#define _MAKE_CLAUSE(unused, tuple)