HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
declare.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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_USD_SDR_DECLARE_H
8 #define PXR_USD_SDR_DECLARE_H
9 
10 /// \file sdr/declare.h
11 ///
12 /// \note
13 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
14 /// in this file. All existing pxr/usd/ndr implementations will be moved to
15 /// pxr/usd/sdr.
16 
17 #include "pxr/pxr.h"
18 #include "pxr/usd/sdr/api.h"
19 #include "pxr/usd/ndr/declare.h"
20 #include "pxr/base/tf/token.h"
21 
22 #include <memory>
23 #include <string>
24 #include <unordered_map>
25 #include <unordered_set>
26 #include <vector>
27 
29 
30 class SdrShaderNode;
31 class SdrShaderProperty;
33 
34 /// Common typedefs that are used throughout the SDR library.
35 
36 typedef TfToken SdrIdentifier;
38 inline const std::string&
39 SdrGetIdentifierString(const SdrIdentifier& id) { return id.GetString(); }
40 typedef std::vector<SdrIdentifier> SdrIdentifierVec;
41 typedef std::unordered_set<SdrIdentifier,
43 
44 // Token
45 typedef std::vector<TfToken> SdrTokenVec;
46 typedef std::unordered_map<TfToken, std::string,
48 
49 // ShaderNode
52 typedef std::unique_ptr<SdrShaderNode> SdrShaderNodeUniquePtr;
53 typedef std::vector<SdrShaderNodeConstPtr> SdrShaderNodeConstPtrVec;
55 typedef std::vector<SdrShaderNodeUniquePtr> SdrShaderNodeUniquePtrVec;
56 
57 // ShaderProperty
60 typedef std::unique_ptr<SdrShaderProperty> SdrShaderPropertyUniquePtr;
61 typedef std::vector<SdrShaderPropertyUniquePtr> SdrShaderPropertyUniquePtrVec;
62 typedef std::unordered_map<TfToken, SdrShaderPropertyConstPtr,
64 typedef SdrShaderPropertyMap SdrPropertyMap;
65 
66 // Misc
67 typedef std::vector<std::string> SdrStringVec;
68 typedef std::pair<TfToken, TfToken> SdrOption;
69 typedef std::vector<SdrOption> SdrOptionVec;
70 typedef std::unordered_set<std::string> SdrStringSet;
71 
72 /// SdrVersion
73 class SdrVersion {
74 public:
75  /// Create an invalid version.
76  SDR_API
77  SdrVersion() = default;
78  /// Create a version with the given major and minor numbers.
79  /// Numbers must be non-negative, and at least one must be non-zero.
80  /// On failure generates an error and yields an invalid version.
81  SDR_API
82  SdrVersion(int major, int minor = 0);
83  /// Create a version from a string. On failure generates an error and
84  /// yields an invalid version.
85  SDR_API
86  SdrVersion(const std::string& x);
87 
88  /// Return an equal version marked as default. It's permitted to mark
89  /// an invalid version as the default.
90  SDR_API
91  SdrVersion GetAsDefault() const
92  {
93  return SdrVersion(*this, true);
94  }
95 
96  /// Return the major version number or zero for an invalid version.
97  SDR_API
98  int GetMajor() const { return _major; }
99  /// Return the minor version number or zero for an invalid version.
100  SDR_API
101  int GetMinor() const { return _minor; }
102  /// Return true iff this version is marked as default.
103  SDR_API
104  bool IsDefault() const { return _isDefault; }
105 
106  /// Return the version as a string.
107  SDR_API
108  std::string GetString() const;
109 
110  /// Return the version as a identifier suffix.
111  SDR_API
112  std::string GetStringSuffix() const;
113 
114  /// Return a hash for the version.
115  SDR_API
116  std::size_t GetHash() const
117  {
118  return (static_cast<std::size_t>(_major) << 32) +
119  static_cast<std::size_t>(_minor);
120  }
121 
122  /// Return true iff the version is valid.
123  SDR_API
124  explicit operator bool() const
125  {
126  return !!*this;
127  }
128 
129  /// Return true iff the version is invalid.
130  SDR_API
131  bool operator!() const
132  {
133  return _major == 0 && _minor == 0;
134  }
135 
136  /// Return true iff versions are equal.
137  SDR_API
138  friend bool operator==(const SdrVersion& lhs, const SdrVersion& rhs)
139  {
140  return lhs._major == rhs._major && lhs._minor == rhs._minor;
141  }
142 
143  /// Return true iff versions are not equal.
144  SDR_API
145  friend bool operator!=(const SdrVersion& lhs, const SdrVersion& rhs)
146  {
147  return !(lhs == rhs);
148  }
149 
150  /// Return true iff the left side is less than the right side.
151  SDR_API
152  friend bool operator<(const SdrVersion& lhs, const SdrVersion& rhs)
153  {
154  return lhs._major < rhs._major ||
155  (lhs._major == rhs._major && lhs._minor < rhs._minor);
156  }
157 
158  /// Return true iff the left side is less than or equal to the right side.
159  SDR_API
160  friend bool operator<=(const SdrVersion& lhs, const SdrVersion& rhs)
161  {
162  return lhs._major < rhs._major ||
163  (lhs._major == rhs._major && lhs._minor <= rhs._minor);
164  }
165 
166  /// Return true iff the left side is greater than the right side.
167  SDR_API
168  friend bool operator>(const SdrVersion& lhs, const SdrVersion& rhs)
169  {
170  return !(lhs <= rhs);
171  }
172 
173  /// Return true iff the left side is greater than or equal to the right side.
174  SDR_API
175  friend bool operator>=(const SdrVersion& lhs, const SdrVersion& rhs)
176  {
177  return !(lhs < rhs);
178  }
179 
180 private:
181  SdrVersion(const SdrVersion& x, bool)
182  : _major(x._major), _minor(x._minor), _isDefault(true) { }
183 
184 private:
185  int _major = 0, _minor = 0;
186  bool _isDefault = false;
187 };
188 
189 /// Enumeration used to select nodes by version.
194 };
195 
196 /// Helper function to translate SdrVersionFilter values to NdrVersionFilter
197 /// values.
198 ///
199 /// \deprecated
200 /// This function is deprecated and will be removed with the removal of
201 /// the Ndr library.
202 SDR_API
204 
205 /// Helper function to translate SdrVersion to NdrVersion
206 ///
207 /// \deprecated
208 /// This function is deprecated and will be removed with the removal of
209 /// the Ndr library.
210 SDR_API
212 
213 /// Helper function to translate NdrVersion to SdrVersion
214 ///
215 /// \deprecated
216 /// This function is deprecated and will be removed with the removal of
217 /// the Ndr library.
218 SDR_API
220 
222 
223 #endif // PXR_USD_SDR_DECLARE_H
TfToken::HashFunctor SdrIdentifierHashFunctor
Definition: declare.h:37
std::vector< std::string > SdrStringVec
Definition: declare.h:67
SDR_API friend bool operator<(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff the left side is less than the right side.
Definition: declare.h:152
NdrVersionFilter
Definition: declare.h:198
SdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:190
std::pair< TfToken, TfToken > SdrOption
Definition: declare.h:68
SDR_API std::string GetString() const
Return the version as a string.
std::unordered_set< SdrIdentifier, SdrIdentifierHashFunctor > SdrIdentifierSet
Definition: declare.h:42
SDR_API std::size_t GetHash() const
Return a hash for the version.
Definition: declare.h:116
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
std::vector< SdrIdentifier > SdrIdentifierVec
Definition: declare.h:40
SDR_API friend bool operator<=(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff the left side is less than or equal to the right side.
Definition: declare.h:160
SdrShaderNode const * SdrShaderNodeConstPtr
Definition: declare.h:51
SDR_API friend bool operator>(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff the left side is greater than the right side.
Definition: declare.h:168
OutGridT const XformOp bool bool
SdrVersion.
Definition: declare.h:73
SDR_API int GetMinor() const
Return the minor version number or zero for an invalid version.
Definition: declare.h:101
SdrShaderNodeConstPtrVec SdrShaderNodePtrVec
Definition: declare.h:54
SdrShaderNode * SdrShaderNodePtr
Definition: declare.h:50
Definition: token.h:70
SDR_API SdrVersion GetAsDefault() const
Definition: declare.h:91
TfToken SdrIdentifier
Common typedefs that are used throughout the SDR library.
Definition: declare.h:32
SDR_API SdrVersion()=default
Create an invalid version.
SDR_API friend bool operator!=(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff versions are not equal.
Definition: declare.h:145
SDR_API friend bool operator==(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff versions are equal.
Definition: declare.h:138
SdrShaderPropertyMap SdrPropertyMap
Definition: declare.h:64
SDR_API std::string GetStringSuffix() const
Return the version as a identifier suffix.
SDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:131
std::unordered_set< std::string > SdrStringSet
Definition: declare.h:70
SDR_API NdrVersion SdrToNdrVersion(SdrVersion version)
SdrShaderProperty const * SdrShaderPropertyConstPtr
Definition: declare.h:59
GLint GLenum GLint x
Definition: glcorearb.h:409
std::vector< SdrShaderNodeConstPtr > SdrShaderNodeConstPtrVec
Definition: declare.h:53
GT_API const UT_StringHolder version
const std::string & SdrGetIdentifierString(const SdrIdentifier &id)
Definition: declare.h:39
std::unique_ptr< SdrShaderProperty > SdrShaderPropertyUniquePtr
Definition: declare.h:60
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
std::unique_ptr< SdrShaderNode > SdrShaderNodeUniquePtr
Definition: declare.h:52
std::unordered_map< TfToken, SdrShaderPropertyConstPtr, TfToken::HashFunctor > SdrShaderPropertyMap
Definition: declare.h:63
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::vector< SdrShaderNodeUniquePtr > SdrShaderNodeUniquePtrVec
Definition: declare.h:55
SdrShaderProperty * SdrShaderPropertyPtr
Definition: declare.h:58
std::vector< TfToken > SdrTokenVec
Definition: declare.h:45
SDR_API int GetMajor() const
Return the major version number or zero for an invalid version.
Definition: declare.h:98
SDR_API friend bool operator>=(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff the left side is greater than or equal to the right side.
Definition: declare.h:175
#define SDR_API
Definition: api.h:23
std::vector< SdrOption > SdrOptionVec
Definition: declare.h:69
SDR_API bool IsDefault() const
Return true iff this version is marked as default.
Definition: declare.h:104
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > SdrTokenMap
Definition: declare.h:47
std::vector< SdrShaderPropertyUniquePtr > SdrShaderPropertyUniquePtrVec
Definition: declare.h:61
SDR_API SdrVersion NdrToSdrVersion(NdrVersion version)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
SDR_API NdrVersionFilter SdrVersionFilterToNdr(SdrVersionFilter filter)