Loading...
Searching...
No Matches
declare.h
Go to the documentation of this file.
1//
2// Copyright 2018 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24
25#ifndef PXR_USD_NDR_DECLARE_H
26#define PXR_USD_NDR_DECLARE_H
27
29
30#include "pxr/pxr.h"
31#include "pxr/usd/ndr/api.h"
32#include "pxr/base/tf/token.h"
33
34#include <memory>
35#include <string>
36#include <unordered_map>
37#include <unordered_set>
38#include <vector>
39
40PXR_NAMESPACE_OPEN_SCOPE
41
42class NdrNode;
43class NdrProperty;
45
49
52inline const std::string&
53NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
54typedef std::vector<NdrIdentifier> NdrIdentifierVec;
55typedef std::unordered_set<NdrIdentifier,
56 NdrIdentifierHashFunctor> NdrIdentifierSet;
57
58// Token
59typedef std::vector<TfToken> NdrTokenVec;
60typedef std::unordered_map<TfToken, std::string,
61 TfToken::HashFunctor> NdrTokenMap;
62
63// Property
65typedef NdrProperty const* NdrPropertyConstPtr;
66typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
67typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
68typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
69 TfToken::HashFunctor> NdrPropertyPtrMap;
70
71// Node
72typedef NdrNode* NdrNodePtr;
73typedef NdrNode const* NdrNodeConstPtr;
74typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
75typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
76typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
77
78// Misc
79typedef std::vector<std::string> NdrStringVec;
80typedef std::pair<TfToken, TfToken> NdrOption;
81typedef std::vector<NdrOption> NdrOptionVec;
82typedef std::unordered_set<std::string> NdrStringSet;
83typedef std::pair<SdfValueTypeName, TfToken> NdrSdfTypeIndicator;
84
85// Version
86class NdrVersion {
87public:
89 NDR_API
90 NdrVersion() = default;
94 NDR_API
95 NdrVersion(int major, int minor = 0);
98 NDR_API
99 NdrVersion(const std::string& x);
100
103 NDR_API
104 NdrVersion GetAsDefault() const
105 {
106 return NdrVersion(*this, true);
107 }
108
110 NDR_API
111 int GetMajor() const { return _major; }
113 NDR_API
114 int GetMinor() const { return _minor; }
116 NDR_API
117 bool IsDefault() const { return _isDefault; }
118
120 NDR_API
121 std::string GetString() const;
122
124 NDR_API
125 std::string GetStringSuffix() const;
126
128 NDR_API
129 std::size_t GetHash() const
130 {
131 return (static_cast<std::size_t>(_major) << 32) +
132 static_cast<std::size_t>(_minor);
133 }
134
136 NDR_API
137 explicit operator bool() const
138 {
139 return !!*this;
140 }
141
143 NDR_API
144 bool operator!() const
145 {
146 return _major == 0 && _minor == 0;
147 }
148
150 NDR_API
151 friend bool operator==(const NdrVersion& lhs, const NdrVersion& rhs)
152 {
153 return lhs._major == rhs._major && lhs._minor == rhs._minor;
154 }
155
157 NDR_API
158 friend bool operator!=(const NdrVersion& lhs, const NdrVersion& rhs)
159 {
160 return !(lhs == rhs);
161 }
162
164 NDR_API
165 friend bool operator<(const NdrVersion& lhs, const NdrVersion& rhs)
166 {
167 return lhs._major < rhs._major ||
168 (lhs._major == rhs._major && lhs._minor < rhs._minor);
169 }
170
172 NDR_API
173 friend bool operator<=(const NdrVersion& lhs, const NdrVersion& rhs)
174 {
175 return lhs._major < rhs._major ||
176 (lhs._major == rhs._major && lhs._minor <= rhs._minor);
177 }
178
180 NDR_API
181 friend bool operator>(const NdrVersion& lhs, const NdrVersion& rhs)
182 {
183 return !(lhs <= rhs);
184 }
185
187 NDR_API
188 friend bool operator>=(const NdrVersion& lhs, const NdrVersion& rhs)
189 {
190 return !(lhs < rhs);
191 }
192
193private:
194 NdrVersion(const NdrVersion& x, bool)
195 : _major(x._major), _minor(x._minor), _isDefault(true) { }
196
197private:
198 int _major = 0, _minor = 0;
199 bool _isDefault = false;
200};
201
204 NdrVersionFilterDefaultOnly,
205 NdrVersionFilterAllVersions,
206 NdrNumVersionFilters
207};
208
209PXR_NAMESPACE_CLOSE_SCOPE
210
211#endif // PXR_USD_NDR_DECLARE_H
Represents an abstract node.
Definition: node.h:49
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:51
Represents a value type name, i.e.
Definition: valueTypeName.h:88
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Functor to use for hash maps from tokens to other things.
Definition: token.h:166
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:203