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
8#ifndef PXR_USD_NDR_DECLARE_H
9#define PXR_USD_NDR_DECLARE_H
10
16
17#include "pxr/pxr.h"
18#include "pxr/usd/ndr/api.h"
19#include "pxr/base/tf/token.h"
20
21#include <memory>
22#include <string>
23#include <unordered_map>
24#include <unordered_set>
25#include <vector>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29class NdrNode;
30class NdrProperty;
32
40
43inline const std::string&
44NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
45typedef std::vector<NdrIdentifier> NdrIdentifierVec;
46typedef std::unordered_set<NdrIdentifier,
47 NdrIdentifierHashFunctor> NdrIdentifierSet;
48
49// Token
50typedef std::vector<TfToken> NdrTokenVec;
51typedef std::unordered_map<TfToken, std::string,
52 TfToken::HashFunctor> NdrTokenMap;
53
54// Property
56typedef NdrProperty const* NdrPropertyConstPtr;
57typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
58typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
59typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
60 TfToken::HashFunctor> NdrPropertyPtrMap;
61
62// Node
63typedef NdrNode* NdrNodePtr;
64typedef NdrNode const* NdrNodeConstPtr;
65typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
66typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
67typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
68
69// Misc
70typedef std::vector<std::string> NdrStringVec;
71typedef std::pair<TfToken, TfToken> NdrOption;
72typedef std::vector<NdrOption> NdrOptionVec;
73typedef std::unordered_set<std::string> NdrStringSet;
74
80public:
82 NDR_API
83 NdrVersion() = default;
87 NDR_API
88 NdrVersion(int major, int minor = 0);
91 NDR_API
92 NdrVersion(const std::string& x);
93
96 NDR_API
98 {
99 return NdrVersion(*this, true);
100 }
101
103 NDR_API
104 int GetMajor() const { return _major; }
106 NDR_API
107 int GetMinor() const { return _minor; }
109 NDR_API
110 bool IsDefault() const { return _isDefault; }
111
113 NDR_API
114 std::string GetString() const;
115
117 NDR_API
118 std::string GetStringSuffix() const;
119
121 NDR_API
122 std::size_t GetHash() const
123 {
124 return (static_cast<std::size_t>(_major) << 32) +
125 static_cast<std::size_t>(_minor);
126 }
127
129 NDR_API
130 explicit operator bool() const
131 {
132 return !!*this;
133 }
134
136 NDR_API
137 bool operator!() const
138 {
139 return _major == 0 && _minor == 0;
140 }
141
143 NDR_API
144 friend bool operator==(const NdrVersion& lhs, const NdrVersion& rhs)
145 {
146 return lhs._major == rhs._major && lhs._minor == rhs._minor;
147 }
148
150 NDR_API
151 friend bool operator!=(const NdrVersion& lhs, const NdrVersion& rhs)
152 {
153 return !(lhs == rhs);
154 }
155
157 NDR_API
158 friend bool operator<(const NdrVersion& lhs, const NdrVersion& rhs)
159 {
160 return lhs._major < rhs._major ||
161 (lhs._major == rhs._major && lhs._minor < rhs._minor);
162 }
163
165 NDR_API
166 friend bool operator<=(const NdrVersion& lhs, const NdrVersion& rhs)
167 {
168 return lhs._major < rhs._major ||
169 (lhs._major == rhs._major && lhs._minor <= rhs._minor);
170 }
171
173 NDR_API
174 friend bool operator>(const NdrVersion& lhs, const NdrVersion& rhs)
175 {
176 return !(lhs <= rhs);
177 }
178
180 NDR_API
181 friend bool operator>=(const NdrVersion& lhs, const NdrVersion& rhs)
182 {
183 return !(lhs < rhs);
184 }
185
186private:
187 NdrVersion(const NdrVersion& x, bool)
188 : _major(x._major), _minor(x._minor), _isDefault(true) { }
189
190private:
191 int _major = 0, _minor = 0;
192 bool _isDefault = false;
193};
194
199 NdrVersionFilterDefaultOnly,
200 NdrVersionFilterAllVersions,
201 NdrNumVersionFilters
202};
203
204PXR_NAMESPACE_CLOSE_SCOPE
205
206#endif // PXR_USD_NDR_DECLARE_H
Represents an abstract node.
Definition: node.h:38
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:42
NdrVersion.
Definition: declare.h:79
NDR_API NdrVersion()=default
Create an invalid version.
NDR_API int GetMajor() const
Return the major version number or zero for an invalid version.
Definition: declare.h:104
NDR_API std::string GetStringSuffix() const
Return the version as a identifier suffix.
NDR_API NdrVersion(int major, int minor=0)
Create a version with the given major and minor numbers.
NDR_API NdrVersion(const std::string &x)
Create a version from a string.
NDR_API friend bool operator<(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff the left side is less than the right side.
Definition: declare.h:158
NDR_API std::size_t GetHash() const
Return a hash for the version.
Definition: declare.h:122
NDR_API bool IsDefault() const
Return true iff this version is marked as default.
Definition: declare.h:110
NDR_API friend bool operator>=(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff the left side is greater than or equal to the right side.
Definition: declare.h:181
NDR_API friend bool operator>(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff the left side is greater than the right side.
Definition: declare.h:174
NDR_API NdrVersion GetAsDefault() const
Return an equal version marked as default.
Definition: declare.h:97
NDR_API std::string GetString() const
Return the version as a string.
NDR_API int GetMinor() const
Return the minor version number or zero for an invalid version.
Definition: declare.h:107
NDR_API friend bool operator!=(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff versions are not equal.
Definition: declare.h:151
NDR_API friend bool operator==(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff versions are equal.
Definition: declare.h:144
NDR_API friend bool operator<=(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff the left side is less than or equal to the right side.
Definition: declare.h:166
NDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:137
Represents a value type name, i.e.
Definition: valueTypeName.h:71
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...
NdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:198