All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 NDR_DECLARE_H
26 #define 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 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 class NdrNode;
43 class NdrProperty;
44 class SdfValueTypeName;
45 
49 
50 typedef TfToken NdrIdentifier;
52 inline const std::string&
53 NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
54 typedef std::vector<NdrIdentifier> NdrIdentifierVec;
55 typedef std::unordered_set<NdrIdentifier,
56  NdrIdentifierHashFunctor> NdrIdentifierSet;
57 
58 // Token
59 typedef std::vector<TfToken> NdrTokenVec;
60 typedef std::unordered_map<TfToken, std::string,
61  TfToken::HashFunctor> NdrTokenMap;
62 
63 // Property
65 typedef NdrProperty const* NdrPropertyConstPtr;
66 typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
67 typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
68 typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
69  TfToken::HashFunctor> NdrPropertyPtrMap;
70 
71 // Node
72 typedef NdrNode* NdrNodePtr;
73 typedef NdrNode const* NdrNodeConstPtr;
74 typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
75 typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
76 typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
77 
78 // Misc
79 typedef std::vector<std::string> NdrStringVec;
80 typedef std::pair<TfToken, TfToken> NdrOption;
81 typedef std::vector<NdrOption> NdrOptionVec;
82 typedef std::unordered_set<std::string> NdrStringSet;
83 typedef std::pair<SdfValueTypeName, TfToken> SdfTypeIndicator;
84 
85 // Version
86 class NdrVersion {
87 public:
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 
193 private:
194  NdrVersion(const NdrVersion& x, bool)
195  : _major(x._major), _minor(x._minor), _isDefault(true) { }
196 
197 private:
198  int _major = 0, _minor = 0;
199  bool _isDefault = false;
200 };
201 
204  NdrVersionFilterDefaultOnly,
205  NdrVersionFilterAllVersions,
206  NdrNumVersionFilters
207 };
208 
209 PXR_NAMESPACE_CLOSE_SCOPE
210 
211 #endif // NDR_DECLARE_H
Functor to use for hash maps from tokens to other things.
Definition: token.h:168
Represents a value type name, i.e.
Definition: valueTypeName.h:83
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:50
Represents an abstract node.
Definition: node.h:48
NdrVersionFilter
Enumeration used to select nodes by version.
Definition: declare.h:203
VT_API bool operator==(VtDictionary const &, VtDictionary const &)
Equality comparison.