All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
12
13#include "pxr/pxr.h"
14#include "pxr/usd/ndr/api.h"
15#include "pxr/base/tf/token.h"
16
17#include <memory>
18#include <string>
19#include <unordered_map>
20#include <unordered_set>
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class NdrNode;
26class NdrProperty;
28
32
35inline const std::string&
36NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
37typedef std::vector<NdrIdentifier> NdrIdentifierVec;
38typedef std::unordered_set<NdrIdentifier,
39 NdrIdentifierHashFunctor> NdrIdentifierSet;
40
41// Token
42typedef std::vector<TfToken> NdrTokenVec;
43typedef std::unordered_map<TfToken, std::string,
44 TfToken::HashFunctor> NdrTokenMap;
45
46// Property
48typedef NdrProperty const* NdrPropertyConstPtr;
49typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
50typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
51typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
52 TfToken::HashFunctor> NdrPropertyPtrMap;
53
54// Node
55typedef NdrNode* NdrNodePtr;
56typedef NdrNode const* NdrNodeConstPtr;
57typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
58typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
59typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
60
61// Misc
62typedef std::vector<std::string> NdrStringVec;
63typedef std::pair<TfToken, TfToken> NdrOption;
64typedef std::vector<NdrOption> NdrOptionVec;
65typedef std::unordered_set<std::string> NdrStringSet;
66
67// Version
68class NdrVersion {
69public:
71 NDR_API
72 NdrVersion() = default;
76 NDR_API
77 NdrVersion(int major, int minor = 0);
80 NDR_API
81 NdrVersion(const std::string& x);
82
85 NDR_API
86 NdrVersion GetAsDefault() const
87 {
88 return NdrVersion(*this, true);
89 }
90
92 NDR_API
93 int GetMajor() const { return _major; }
95 NDR_API
96 int GetMinor() const { return _minor; }
98 NDR_API
99 bool IsDefault() const { return _isDefault; }
100
102 NDR_API
103 std::string GetString() const;
104
106 NDR_API
107 std::string GetStringSuffix() const;
108
110 NDR_API
111 std::size_t GetHash() const
112 {
113 return (static_cast<std::size_t>(_major) << 32) +
114 static_cast<std::size_t>(_minor);
115 }
116
118 NDR_API
119 explicit operator bool() const
120 {
121 return !!*this;
122 }
123
125 NDR_API
126 bool operator!() const
127 {
128 return _major == 0 && _minor == 0;
129 }
130
132 NDR_API
133 friend bool operator==(const NdrVersion& lhs, const NdrVersion& rhs)
134 {
135 return lhs._major == rhs._major && lhs._minor == rhs._minor;
136 }
137
139 NDR_API
140 friend bool operator!=(const NdrVersion& lhs, const NdrVersion& rhs)
141 {
142 return !(lhs == rhs);
143 }
144
146 NDR_API
147 friend bool operator<(const NdrVersion& lhs, const NdrVersion& rhs)
148 {
149 return lhs._major < rhs._major ||
150 (lhs._major == rhs._major && lhs._minor < rhs._minor);
151 }
152
154 NDR_API
155 friend bool operator<=(const NdrVersion& lhs, const NdrVersion& rhs)
156 {
157 return lhs._major < rhs._major ||
158 (lhs._major == rhs._major && lhs._minor <= rhs._minor);
159 }
160
162 NDR_API
163 friend bool operator>(const NdrVersion& lhs, const NdrVersion& rhs)
164 {
165 return !(lhs <= rhs);
166 }
167
169 NDR_API
170 friend bool operator>=(const NdrVersion& lhs, const NdrVersion& rhs)
171 {
172 return !(lhs < rhs);
173 }
174
175private:
176 NdrVersion(const NdrVersion& x, bool)
177 : _major(x._major), _minor(x._minor), _isDefault(true) { }
178
179private:
180 int _major = 0, _minor = 0;
181 bool _isDefault = false;
182};
183
186 NdrVersionFilterDefaultOnly,
187 NdrVersionFilterAllVersions,
188 NdrNumVersionFilters
189};
190
191PXR_NAMESPACE_CLOSE_SCOPE
192
193#endif // PXR_USD_NDR_DECLARE_H
Represents an abstract node.
Definition: node.h:32
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:35
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:185