HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
maskedOutput.h
Go to the documentation of this file.
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 #ifndef PXR_EXEC_VDF_MASKED_OUTPUT_H
8 #define PXR_EXEC_VDF_MASKED_OUTPUT_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
15 #include "pxr/exec/vdf/mask.h"
16 
17 #include <string>
18 #include <utility>
19 
21 
22 class VdfOutput;
23 
24 /// \class VdfMaskedOutput
25 ///
26 /// \brief Class to hold on to an externally owned output and a mask.
27 ///
28 /// Objects of this class explicitly have two operators defined so that
29 /// they can act as VdfOutput.
30 ///
32 {
33 public :
34 
36  _output(nullptr) {}
37 
39  _output(output), _mask(mask) {}
40 
42  _output(output), _mask(std::move(mask)) {}
43 
44  /// Cast to bool: returns true if the output is non-null.
45  ///
46  explicit operator bool() const {
47  return static_cast<bool>(_output);
48  }
49 
50  /// Returns the VdfOutput.
51  ///
52  VdfOutput *GetOutput() const {
53  return _output;
54  }
55 
56  /// Sets the output to \p output.
57  ///
58  void SetOutput(VdfOutput *output) {
59  _output = output;
60  }
61 
62  /// Returns the VdfMask.
63  ///
64  const VdfMask &GetMask() const {
65  return _mask;
66  }
67 
68  /// Sets the mask to \p mask.
69  ///
70  void SetMask(const VdfMask &mask) {
71  _mask = mask;
72  }
73 
74  /// Sets the mask to \p mask.
75  ///
76  void SetMask(VdfMask &&mask) {
77  _mask = std::move(mask);
78  }
79 
80  /// Equality comparison.
81  ///
82  bool operator==(const VdfMaskedOutput &rhs) const {
83  return _output == rhs._output &&
84  _mask == rhs._mask;
85  }
86 
87  bool operator!=(const VdfMaskedOutput &rhs) const {
88  return !(*this == rhs);
89  }
90 
91  struct Hash
92  {
93  size_t operator()(const VdfMaskedOutput &maskedOutput) const
94  {
95  // Note: maskedOutput.GetMask() is a flyweight.
96  return (size_t)maskedOutput.GetOutput() +
97  maskedOutput.GetMask().GetHash();
98  }
99  };
100 
101  bool operator<(const VdfMaskedOutput &rhs) const {
102  std::less<const VdfOutput *> outputLT;
103  if (outputLT(_output, rhs._output))
104  return true;
105 
106  if (outputLT(rhs._output, _output))
107  return false;
108 
109  return VdfMask::ArbitraryLessThan()(_mask, rhs._mask);
110  }
111 
112  bool operator<=(const VdfMaskedOutput &rhs) const {
113  return !(rhs < *this);
114  }
115 
116  bool operator>(const VdfMaskedOutput &rhs) const {
117  return rhs < *this;
118  }
119 
120  bool operator>=(const VdfMaskedOutput &rhs) const {
121  return !(*this < rhs);
122  }
123 
124  friend inline void swap(VdfMaskedOutput &lhs, VdfMaskedOutput &rhs) {
125  using std::swap;
126  swap(lhs._output, rhs._output);
127  swap(lhs._mask, rhs._mask);
128  }
129 
130  /// Returns a string describing this masked output.
131  ///
132  VDF_API
133  std::string GetDebugName() const;
134 
135 // -----------------------------------------------------------------------------
136 
137 private :
138 
139  VdfOutput *_output;
140  VdfMask _mask;
141 };
142 
144 
145 #endif
bool operator==(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:82
friend void swap(VdfMaskedOutput &lhs, VdfMaskedOutput &rhs)
Definition: maskedOutput.h:124
bool operator>=(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:120
void SetMask(const VdfMask &mask)
Definition: maskedOutput.h:70
size_t GetHash() const
Returns a hash for the mask.
Definition: mask.h:565
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1699
void SetOutput(VdfOutput *output)
Definition: maskedOutput.h:58
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
const VdfMask & GetMask() const
Definition: maskedOutput.h:64
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
#define VDF_API
Definition: api.h:25
VDF_API std::string GetDebugName() const
OutGridT const XformOp bool bool
GLint GLuint mask
Definition: glcorearb.h:124
bool operator<=(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:112
void SetMask(VdfMask &&mask)
Definition: maskedOutput.h:76
bool operator<(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:101
VdfMaskedOutput(VdfOutput *output, VdfMask &&mask)
Definition: maskedOutput.h:41
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
bool operator!=(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:87
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
size_t operator()(const VdfMaskedOutput &maskedOutput) const
Definition: maskedOutput.h:93
bool operator>(const VdfMaskedOutput &rhs) const
Definition: maskedOutput.h:116
VdfOutput * GetOutput() const
Definition: maskedOutput.h:52
VdfMaskedOutput(VdfOutput *output, const VdfMask &mask)
Definition: maskedOutput.h:38