HDK
 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 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 
11 /// \file ndr/declare.h
12 ///
13 /// \deprecated
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in sdr/declare.h
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 
28 
29 class NdrNode;
30 class NdrProperty;
31 class SdfValueTypeName;
32 
33 /// \file declare.h
34 ///
35 /// Common typedefs that are used throughout the NDR library.
36 ///
37 /// \deprecated
38 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
39 /// in sdr/declare.h
40 
43 inline const std::string&
44 NdrGetIdentifierString(const NdrIdentifier& id) { return id.GetString(); }
45 typedef std::vector<NdrIdentifier> NdrIdentifierVec;
46 typedef std::unordered_set<NdrIdentifier,
48 
49 // Token
50 typedef std::vector<TfToken> NdrTokenVec;
51 typedef std::unordered_map<TfToken, std::string,
53 
54 // Property
57 typedef std::unique_ptr<NdrProperty> NdrPropertyUniquePtr;
58 typedef std::vector<NdrPropertyUniquePtr> NdrPropertyUniquePtrVec;
59 typedef std::unordered_map<TfToken, NdrPropertyConstPtr,
61 
62 // Node
64 typedef NdrNode const* NdrNodeConstPtr;
65 typedef std::unique_ptr<NdrNode> NdrNodeUniquePtr;
66 typedef std::vector<NdrNodeConstPtr> NdrNodeConstPtrVec;
67 typedef std::vector<NdrNodeUniquePtr> NdrNodeUniquePtrVec;
68 
69 // Misc
70 typedef std::vector<std::string> NdrStringVec;
71 typedef std::pair<TfToken, TfToken> NdrOption;
72 typedef std::vector<NdrOption> NdrOptionVec;
73 typedef std::unordered_set<std::string> NdrStringSet;
74 
75 /// NdrVersion
76 ///
77 /// \deprecated
78 /// Deprecated in favor of SdrVersion
79 class NdrVersion {
80 public:
81  /// Create an invalid version.
82  NDR_API
83  NdrVersion() = default;
84  /// Create a version with the given major and minor numbers.
85  /// Numbers must be non-negative, and at least one must be non-zero.
86  /// On failure generates an error and yields an invalid version.
87  NDR_API
88  NdrVersion(int major, int minor = 0);
89  /// Create a version from a string. On failure generates an error and
90  /// yields an invalid version.
91  NDR_API
92  NdrVersion(const std::string& x);
93 
94  /// Return an equal version marked as default. It's permitted to mark
95  /// an invalid version as the default.
96  NDR_API
97  NdrVersion GetAsDefault() const
98  {
99  return NdrVersion(*this, true);
100  }
101 
102  /// Return the major version number or zero for an invalid version.
103  NDR_API
104  int GetMajor() const { return _major; }
105  /// Return the minor version number or zero for an invalid version.
106  NDR_API
107  int GetMinor() const { return _minor; }
108  /// Return true iff this version is marked as default.
109  NDR_API
110  bool IsDefault() const { return _isDefault; }
111 
112  /// Return the version as a string.
113  NDR_API
114  std::string GetString() const;
115 
116  /// Return the version as a identifier suffix.
117  NDR_API
118  std::string GetStringSuffix() const;
119 
120  /// Return a hash for the version.
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 
128  /// Return true iff the version is valid.
129  NDR_API
130  explicit operator bool() const
131  {
132  return !!*this;
133  }
134 
135  /// Return true iff the version is invalid.
136  NDR_API
137  bool operator!() const
138  {
139  return _major == 0 && _minor == 0;
140  }
141 
142  /// Return true iff versions are equal.
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 
149  /// Return true iff versions are not equal.
150  NDR_API
151  friend bool operator!=(const NdrVersion& lhs, const NdrVersion& rhs)
152  {
153  return !(lhs == rhs);
154  }
155 
156  /// Return true iff the left side is less than the right side.
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 
164  /// Return true iff the left side is less than or equal to the right side.
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 
172  /// Return true iff the left side is greater than the right side.
173  NDR_API
174  friend bool operator>(const NdrVersion& lhs, const NdrVersion& rhs)
175  {
176  return !(lhs <= rhs);
177  }
178 
179  /// Return true iff the left side is greater than or equal to the right side.
180  NDR_API
181  friend bool operator>=(const NdrVersion& lhs, const NdrVersion& rhs)
182  {
183  return !(lhs < rhs);
184  }
185 
186 private:
187  NdrVersion(const NdrVersion& x, bool)
188  : _major(x._major), _minor(x._minor), _isDefault(true) { }
189 
190 private:
191  int _major = 0, _minor = 0;
192  bool _isDefault = false;
193 };
194 
195 /// Enumeration used to select nodes by version.
196 ///
197 /// \deprecated in favor of SdrVersionFilter.
202 };
203 
205 
206 #endif // PXR_USD_NDR_DECLARE_H
NDR_API int GetMajor() const
Return the major version number or zero for an invalid version.
Definition: declare.h:104
NDR_API std::size_t GetHash() const
Return a hash for the version.
Definition: declare.h:122
NdrVersionFilter
Definition: declare.h:198
NDR_API int GetMinor() const
Return the minor version number or zero for an invalid version.
Definition: declare.h:107
std::vector< TfToken > NdrTokenVec
Definition: declare.h:50
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 std::string GetString() const
Return the version as a string.
NdrNode const * NdrNodeConstPtr
Definition: declare.h:64
std::vector< NdrNodeUniquePtr > NdrNodeUniquePtrVec
Definition: declare.h:67
TfToken NdrIdentifier
Definition: declare.h:41
std::vector< NdrOption > NdrOptionVec
Definition: declare.h:72
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
Functor to use for hash maps from tokens to other things.
Definition: token.h:149
NDR_API std::string GetStringSuffix() const
Return the version as a identifier suffix.
TfToken::HashFunctor NdrIdentifierHashFunctor
Definition: declare.h:42
std::vector< NdrNodeConstPtr > NdrNodeConstPtrVec
Definition: declare.h:66
NDR_API bool operator!() const
Return true iff the version is invalid.
Definition: declare.h:137
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
OutGridT const XformOp bool bool
std::vector< NdrPropertyUniquePtr > NdrPropertyUniquePtrVec
Definition: declare.h:58
Definition: token.h:70
std::vector< NdrIdentifier > NdrIdentifierVec
Definition: declare.h:45
NDR_API NdrVersion GetAsDefault() const
Definition: declare.h:97
NDR_API friend bool operator!=(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff versions are not equal.
Definition: declare.h:151
Definition: node.h:37
std::vector< std::string > NdrStringVec
Definition: declare.h:70
std::unordered_set< NdrIdentifier, NdrIdentifierHashFunctor > NdrIdentifierSet
Definition: declare.h:47
GLint GLenum GLint x
Definition: glcorearb.h:409
#define NDR_API
Definition: api.h:23
std::unique_ptr< NdrProperty > NdrPropertyUniquePtr
Definition: declare.h:57
std::pair< TfToken, TfToken > NdrOption
Definition: declare.h:71
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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 less than the right side.
Definition: declare.h:158
std::unique_ptr< NdrNode > NdrNodeUniquePtr
Definition: declare.h:65
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
NdrProperty * NdrPropertyPtr
Definition: declare.h:55
NDR_API friend bool operator==(const NdrVersion &lhs, const NdrVersion &rhs)
Return true iff versions are equal.
Definition: declare.h:144
std::unordered_set< std::string > NdrStringSet
Definition: declare.h:73
std::unordered_map< TfToken, std::string, TfToken::HashFunctor > NdrTokenMap
Definition: declare.h:52
std::unordered_map< TfToken, NdrPropertyConstPtr, TfToken::HashFunctor > NdrPropertyPtrMap
Definition: declare.h:60
NdrNode * NdrNodePtr
Definition: declare.h:63
NDR_API NdrVersion()=default
Create an invalid version.
NdrProperty const * NdrPropertyConstPtr
Definition: declare.h:56
const std::string & NdrGetIdentifierString(const NdrIdentifier &id)
Definition: declare.h:44