Loading...
Searching...
No Matches
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
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
28PXR_NAMESPACE_OPEN_SCOPE
29
30class SdrShaderNode;
33
35
38inline const std::string&
39SdrGetIdentifierString(const SdrIdentifier& id) { return id.GetString(); }
40typedef std::vector<SdrIdentifier> SdrIdentifierVec;
41typedef std::unordered_set<SdrIdentifier,
42 SdrIdentifierHashFunctor> SdrIdentifierSet;
43
44// Token
45typedef std::vector<TfToken> SdrTokenVec;
46typedef std::unordered_map<TfToken, std::string,
47 TfToken::HashFunctor> SdrTokenMap;
48
49// ShaderNode
51typedef SdrShaderNode const* SdrShaderNodeConstPtr;
52typedef std::unique_ptr<SdrShaderNode> SdrShaderNodeUniquePtr;
53typedef std::vector<SdrShaderNodeConstPtr> SdrShaderNodeConstPtrVec;
54typedef SdrShaderNodeConstPtrVec SdrShaderNodePtrVec;
55typedef std::vector<SdrShaderNodeUniquePtr> SdrShaderNodeUniquePtrVec;
56
57// ShaderProperty
59typedef SdrShaderProperty const* SdrShaderPropertyConstPtr;
60typedef std::unique_ptr<SdrShaderProperty> SdrShaderPropertyUniquePtr;
61typedef std::vector<SdrShaderPropertyUniquePtr> SdrShaderPropertyUniquePtrVec;
62typedef std::unordered_map<TfToken, SdrShaderPropertyConstPtr,
63 TfToken::HashFunctor> SdrShaderPropertyMap;
64typedef SdrShaderPropertyMap SdrPropertyMap;
65
66// Misc
67typedef std::vector<std::string> SdrStringVec;
68typedef std::pair<TfToken, TfToken> SdrOption;
69typedef std::vector<SdrOption> SdrOptionVec;
70typedef std::unordered_set<std::string> SdrStringSet;
71
74public:
76 SDR_API
77 SdrVersion() = default;
81 SDR_API
82 SdrVersion(int major, int minor = 0);
85 SDR_API
86 SdrVersion(const std::string& x);
87
90 SDR_API
92 {
93 return SdrVersion(*this, true);
94 }
95
97 SDR_API
98 int GetMajor() const { return _major; }
100 SDR_API
101 int GetMinor() const { return _minor; }
103 SDR_API
104 bool IsDefault() const { return _isDefault; }
105
107 SDR_API
108 std::string GetString() const;
109
111 SDR_API
112 std::string GetStringSuffix() const;
113
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
123 SDR_API
124 explicit operator bool() const
125 {
126 return !!*this;
127 }
128
130 SDR_API
131 bool operator!() const
132 {
133 return _major == 0 && _minor == 0;
134 }
135
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
144 SDR_API
145 friend bool operator!=(const SdrVersion& lhs, const SdrVersion& rhs)
146 {
147 return !(lhs == rhs);
148 }
149
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
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
167 SDR_API
168 friend bool operator>(const SdrVersion& lhs, const SdrVersion& rhs)
169 {
170 return !(lhs <= rhs);
171 }
172
174 SDR_API
175 friend bool operator>=(const SdrVersion& lhs, const SdrVersion& rhs)
176 {
177 return !(lhs < rhs);
178 }
179
180private:
181 SdrVersion(const SdrVersion& x, bool)
182 : _major(x._major), _minor(x._minor), _isDefault(true) { }
183
184private:
185 int _major = 0, _minor = 0;
186 bool _isDefault = false;
187};
188
191 SdrVersionFilterDefaultOnly,
192 SdrVersionFilterAllVersions,
193 SdrNumVersionFilters
194};
195
202SDR_API
204
210SDR_API
212
218SDR_API
220
221PXR_NAMESPACE_CLOSE_SCOPE
222
223#endif // PXR_USD_SDR_DECLARE_H
NdrVersion.
Definition: declare.h:79
Represents a value type name, i.e.
Definition: valueTypeName.h:71
Represents a node that holds shading information.
Definition: shaderNode.h:78
Represents a property (input or output) that is part of a SdrShaderNode instance.
SdrVersion.
Definition: declare.h:73
SDR_API int GetMajor() const
Return the major version number or zero for an invalid version.
Definition: declare.h:98
SDR_API std::string GetStringSuffix() const
Return the version as a identifier suffix.
SDR_API std::string GetString() const
Return the version as a string.
SDR_API friend bool operator==(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff versions are equal.
Definition: declare.h:138
SDR_API bool IsDefault() const
Return true iff this version is marked as default.
Definition: declare.h:104
SDR_API SdrVersion(const std::string &x)
Create a version from a string.
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
SDR_API SdrVersion GetAsDefault() const
Return an equal version marked as default.
Definition: declare.h:91
SDR_API friend bool operator!=(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff versions are not equal.
Definition: declare.h:145
SDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:131
SDR_API std::size_t GetHash() const
Return a hash for the version.
Definition: declare.h:116
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
SDR_API int GetMinor() const
Return the minor version number or zero for an invalid version.
Definition: declare.h:101
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
SDR_API SdrVersion()=default
Create an invalid version.
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
SDR_API SdrVersion(int major, int minor=0)
Create a version with the given major and minor numbers.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
Common typedefs that are used throughout the NDR library.
NdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:198
SDR_API NdrVersion SdrToNdrVersion(SdrVersion version)
Helper function to translate SdrVersion to NdrVersion.
SDR_API NdrVersionFilter SdrVersionFilterToNdr(SdrVersionFilter filter)
Helper function to translate SdrVersionFilter values to NdrVersionFilter values.
TfToken SdrIdentifier
Common typedefs that are used throughout the SDR library.
Definition: declare.h:36
SdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:190
SDR_API SdrVersion NdrToSdrVersion(NdrVersion version)
Helper function to translate NdrVersion to SdrVersion.