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
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdr/api.h"
14#include "pxr/base/tf/token.h"
15
16#include <memory>
17#include <string>
18#include <unordered_map>
19#include <unordered_set>
20#include <vector>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24class SdrShaderNode;
27
29
32inline const std::string&
33SdrGetIdentifierString(const SdrIdentifier& id) { return id.GetString(); }
34typedef std::vector<SdrIdentifier> SdrIdentifierVec;
35typedef std::unordered_set<SdrIdentifier,
36 SdrIdentifierHashFunctor> SdrIdentifierSet;
37
38// Token
39typedef std::vector<TfToken> SdrTokenVec;
40typedef std::unordered_map<TfToken, std::string,
41 TfToken::HashFunctor> SdrTokenMap;
42
43// ShaderNode
45typedef SdrShaderNode const* SdrShaderNodeConstPtr;
46typedef std::unique_ptr<SdrShaderNode> SdrShaderNodeUniquePtr;
47typedef std::vector<SdrShaderNodeConstPtr> SdrShaderNodeConstPtrVec;
48typedef SdrShaderNodeConstPtrVec SdrShaderNodePtrVec;
49typedef std::vector<SdrShaderNodeUniquePtr> SdrShaderNodeUniquePtrVec;
50
51// ShaderProperty
53typedef SdrShaderProperty const* SdrShaderPropertyConstPtr;
54typedef std::unique_ptr<SdrShaderProperty> SdrShaderPropertyUniquePtr;
55typedef std::vector<SdrShaderPropertyUniquePtr> SdrShaderPropertyUniquePtrVec;
56typedef std::unordered_map<TfToken, SdrShaderPropertyConstPtr,
57 TfToken::HashFunctor> SdrShaderPropertyMap;
58typedef SdrShaderPropertyMap SdrPropertyMap;
59
60// Misc
61typedef std::vector<std::string> SdrStringVec;
62typedef std::pair<TfToken, TfToken> SdrOption;
63typedef std::vector<SdrOption> SdrOptionVec;
64typedef std::unordered_set<std::string> SdrStringSet;
65
68public:
70 SDR_API
71 SdrVersion() = default;
75 SDR_API
76 SdrVersion(int major, int minor = 0);
79 SDR_API
80 SdrVersion(const std::string& x);
81
84 SDR_API
86 {
87 return SdrVersion(*this, true);
88 }
89
91 SDR_API
92 int GetMajor() const { return _major; }
94 SDR_API
95 int GetMinor() const { return _minor; }
97 SDR_API
98 bool IsDefault() const { return _isDefault; }
99
101 SDR_API
102 std::string GetString() const;
103
105 SDR_API
106 std::string GetStringSuffix() const;
107
109 SDR_API
110 std::size_t GetHash() const
111 {
112 return (static_cast<std::size_t>(_major) << 32) +
113 static_cast<std::size_t>(_minor);
114 }
115
117 SDR_API
118 explicit operator bool() const
119 {
120 return !!*this;
121 }
122
124 SDR_API
125 bool operator!() const
126 {
127 return _major == 0 && _minor == 0;
128 }
129
131 SDR_API
132 friend bool operator==(const SdrVersion& lhs, const SdrVersion& rhs)
133 {
134 return lhs._major == rhs._major && lhs._minor == rhs._minor;
135 }
136
138 SDR_API
139 friend bool operator!=(const SdrVersion& lhs, const SdrVersion& rhs)
140 {
141 return !(lhs == rhs);
142 }
143
145 SDR_API
146 friend bool operator<(const SdrVersion& lhs, const SdrVersion& rhs)
147 {
148 return lhs._major < rhs._major ||
149 (lhs._major == rhs._major && lhs._minor < rhs._minor);
150 }
151
153 SDR_API
154 friend bool operator<=(const SdrVersion& lhs, const SdrVersion& rhs)
155 {
156 return lhs._major < rhs._major ||
157 (lhs._major == rhs._major && lhs._minor <= rhs._minor);
158 }
159
161 SDR_API
162 friend bool operator>(const SdrVersion& lhs, const SdrVersion& rhs)
163 {
164 return !(lhs <= rhs);
165 }
166
168 SDR_API
169 friend bool operator>=(const SdrVersion& lhs, const SdrVersion& rhs)
170 {
171 return !(lhs < rhs);
172 }
173
174private:
175 SdrVersion(const SdrVersion& x, bool)
176 : _major(x._major), _minor(x._minor), _isDefault(true) { }
177
178private:
179 int _major = 0, _minor = 0;
180 bool _isDefault = false;
181};
182
185 SdrVersionFilterDefaultOnly,
186 SdrVersionFilterAllVersions,
187 SdrNumVersionFilters
188};
189
190PXR_NAMESPACE_CLOSE_SCOPE
191
192#endif // PXR_USD_SDR_DECLARE_H
Represents a value type name, i.e.
Definition: valueTypeName.h:72
Represents a node that holds shading information.
Definition: shaderNode.h:89
Represents a property (input or output) that is part of a SdrShaderNode instance.
SdrVersion.
Definition: declare.h:67
SDR_API int GetMajor() const
Return the major version number or zero for an invalid version.
Definition: declare.h:92
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:132
SDR_API bool IsDefault() const
Return true iff this version is marked as default.
Definition: declare.h:98
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:154
SDR_API SdrVersion GetAsDefault() const
Return an equal version marked as default.
Definition: declare.h:85
SDR_API friend bool operator!=(const SdrVersion &lhs, const SdrVersion &rhs)
Return true iff versions are not equal.
Definition: declare.h:139
SDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:125
SDR_API std::size_t GetHash() const
Return a hash for the version.
Definition: declare.h:110
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:169
SDR_API int GetMinor() const
Return the minor version number or zero for an invalid version.
Definition: declare.h:95
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:146
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:162
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...
TfToken SdrIdentifier
Common typedefs that are used throughout the SDR library.
Definition: declare.h:30
SdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:184