Loading...
Searching...
No Matches
valueComposeOver.h
1//
2// Copyright 2025 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_VT_VALUE_COMPOSE_OVER_H
9#define PXR_BASE_VT_VALUE_COMPOSE_OVER_H
10
11#include "pxr/pxr.h"
12
13#include "pxr/base/vt/api.h"
14#include "pxr/base/vt/traits.h"
15#include "pxr/base/vt/types.h"
16#include "pxr/base/vt/value.h"
17#include "pxr/base/vt/valueRef.h"
18
19#include <optional>
20
21PXR_NAMESPACE_OPEN_SCOPE
22
27inline bool
28VtValueCanComposeOver(VtValueRef val) {
29 return val.CanComposeOver();
30}
31
34VT_API bool
35VtValueTypeCanComposeOver(std::type_info const &strongType);
36
43VT_API bool
44VtValueCanComposeOver(VtValueRef stronger, VtValueRef weaker);
45
48VT_API std::optional<VtValue>
49VtValueTryComposeOver(VtValueRef stronger, VtValueRef weaker);
50
56VT_API VtValue
57VtValueComposeOver(VtValueRef stronger, VtValueRef weaker);
58
66inline constexpr VtBackgroundType VtBackground;
67
68// Required to store VtBackground in a VtValue.
69inline bool
71 return true;
72}
73
74// Private helper implementation.
75VT_API void
76Vt_RegisterComposeOver(std::type_info const &strongType,
77 std::type_info const &weakType,
78 void (*voidFn)(),
79 VtValue (*over)(VtValueRef, VtValueRef, void (*)()));
80
84template <class Ret, class Strong, class Weak>
85void
86VtRegisterComposeOver(Ret (*fn)(Strong const &, Weak const &))
87{
88 static_assert(!VtIsKnownValueType<Strong>() || VtIsArrayEdit<Strong>::value,
89 "Unexpected compose-over registration for one of the "
90 "known value types");
91
93 "Use VT_VALUE_TYPE_CAN_COMPOSE or specialize "
94 "VtValueTypeCanCompose<> before registering compose-over "
95 "functionality");
96
97 using TypedFn = Ret (*)(Strong const &, Weak const &);
98 using VoidFn = void (*)();
99
100 VoidFn voidFn = reinterpret_cast<VoidFn>(fn);
101 Vt_RegisterComposeOver(
102 typeid(Strong), typeid(Weak), voidFn,
103 [](VtValueRef strong, VtValueRef weak, void (*vFn)()) {
104 TypedFn tFn = reinterpret_cast<TypedFn>(vFn);
105 TF_DEV_AXIOM(strong.IsHolding<Strong>());
106 TF_DEV_AXIOM(weak.IsHolding<Weak>());
107 return VtValue {
108 tFn(strong.UncheckedGet<Strong>(), weak.UncheckedGet<Weak>())
109 };
110 });
111}
112
113PXR_NAMESPACE_CLOSE_SCOPE
114
115#endif // PXR_BASE_VT_VALUE_COMPOSE_OVER_H
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
A non-owning type-erased view of a value, interoperating with VtValue.
Definition: valueRef.h:65
bool CanComposeOver() const
Return true if this value holds a type that has been declared at compile time to support composing ov...
Definition: valueRef.h:535
_TypeInfoFor< T >::GetObjResultType UncheckedGet() const
Return a const reference to the viewed object if the viewed object is of type T.
Definition: valueRef.h:452
bool IsHolding() const
Return true if this value is viewing an object of type T, false otherwise.
Definition: valueRef.h:403
#define TF_DEV_AXIOM(cond)
The same as TF_AXIOM, but compiled only in dev builds.
Definition: diagnostic.h:205
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
A special sentinel type and singular value that can be used to "finalize" a composing type.
A trait to detect instantiations of VtArrayEdit, specialized in arrayEdit.h.
Definition: traits.h:26
A trait indicating whether VtValue compose-over functionality can be registered for a type.
Definition: traits.h:137