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 TfHash::Combine(_major, _minor);
113 }
114
116 SDR_API
117 explicit operator bool() const
118 {
119 return !!*this;
120 }
121
123 SDR_API
124 bool operator!() const
125 {
126 return _major == 0 && _minor == 0;
127 }
128
130 SDR_API
131 friend bool operator==(const SdrVersion& lhs, const SdrVersion& rhs)
132 {
133 return lhs._major == rhs._major && lhs._minor == rhs._minor;
134 }
135
137 SDR_API
138 friend bool operator!=(const SdrVersion& lhs, const SdrVersion& rhs)
139 {
140 return !(lhs == rhs);
141 }
142
144 SDR_API
145 friend bool operator<(const SdrVersion& lhs, const SdrVersion& rhs)
146 {
147 return lhs._major < rhs._major ||
148 (lhs._major == rhs._major && lhs._minor < rhs._minor);
149 }
150
152 SDR_API
153 friend bool operator<=(const SdrVersion& lhs, const SdrVersion& rhs)
154 {
155 return lhs._major < rhs._major ||
156 (lhs._major == rhs._major && lhs._minor <= rhs._minor);
157 }
158
160 SDR_API
161 friend bool operator>(const SdrVersion& lhs, const SdrVersion& rhs)
162 {
163 return !(lhs <= rhs);
164 }
165
167 SDR_API
168 friend bool operator>=(const SdrVersion& lhs, const SdrVersion& rhs)
169 {
170 return !(lhs < rhs);
171 }
172
173private:
174 SdrVersion(const SdrVersion& x, bool)
175 : _major(x._major), _minor(x._minor), _isDefault(true) { }
176
177private:
178 int _major = 0, _minor = 0;
179 bool _isDefault = false;
180};
181
184 SdrVersionFilterDefaultOnly,
185 SdrVersionFilterAllVersions,
186 SdrNumVersionFilters
187};
188
189PXR_NAMESPACE_CLOSE_SCOPE
190
191#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:131
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:153
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:138
SDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:124
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:168
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:145
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:161
SDR_API SdrVersion(int major, int minor=0)
Create a version with the given major and minor numbers.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
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:183