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
26inline bool
27VtValueCanComposeOver(VtValueRef val) {
28 return val.CanComposeOver();
29}
30
37VT_API bool
38VtValueCanComposeOver(VtValueRef stronger, VtValueRef weaker);
39
42VT_API std::optional<VtValue>
43VtValueTryComposeOver(VtValueRef a, VtValueRef b);
44
50VT_API VtValue
51VtValueComposeOver(VtValueRef a, VtValueRef b);
52
60inline constexpr VtBackgroundType VtBackground;
61
62// Required to store VtBackground in a VtValue.
63inline bool
65 return true;
66}
67
68// Private helper implementation.
69VT_API void
70Vt_RegisterComposeOver(std::type_info const &strongType,
71 std::type_info const &weakType,
72 void (*voidFn)(),
73 VtValue (*over)(VtValueRef, VtValueRef, void (*)()));
74
78template <class Ret, class Strong, class Weak>
79void
80VtRegisterComposeOver(Ret (*fn)(Strong const &, Weak const &))
81{
82 static_assert(!VtIsKnownValueType<Strong>() || VtIsArrayEdit<Strong>::value,
83 "Unexpected compose-over registration for one of the "
84 "known value types");
85
87 "Use VT_VALUE_TYPE_COMPOSES or specialize "
88 "VtValueTypeCanCompose<> before registering compose-over "
89 "functionality");
90
91 using TypedFn = Ret (*)(Strong const &, Weak const &);
92 using VoidFn = void (*)();
93
94 VoidFn voidFn = reinterpret_cast<VoidFn>(fn);
95 Vt_RegisterComposeOver(
96 typeid(Strong), typeid(Weak), voidFn,
97 [](VtValueRef strong, VtValueRef weak, void (*vFn)()) {
98 TypedFn tFn = reinterpret_cast<TypedFn>(vFn);
99 TF_DEV_AXIOM(strong.IsHolding<Strong>());
100 TF_DEV_AXIOM(weak.IsHolding<Weak>());
101 return VtValue {
102 tFn(strong.UncheckedGet<Strong>(), weak.UncheckedGet<Weak>())
103 };
104 });
105}
106
107PXR_NAMESPACE_CLOSE_SCOPE
108
109#endif // PXR_BASE_VT_VALUE_COMPOSE_OVER_H
Defines all the types "TYPED" for which Vt creates a VtTYPEDArray typedef.
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
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