HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
assetPath.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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 #ifndef PXR_USD_SDF_ASSET_PATH_H
25 #define PXR_USD_SDF_ASSET_PATH_H
26 
27 /// \file sdf/assetPath.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 #include "pxr/base/tf/hash.h"
32 
33 #include <iosfwd>
34 #include <string>
35 
37 
38 /// \class SdfAssetPath
39 ///
40 /// Contains an asset path and an optional resolved path. Asset paths may
41 /// contain non-control UTF-8 encoded characters. Specifically, U+0000..U+001F
42 /// (C0 controls), U+007F (delete), and U+0080..U+009F (C1 controls) are
43 /// disallowed. Attempts to construct asset paths with such characters will
44 /// issue a TfError and produce the default-constructed empty asset path.
45 ///
47 {
48 public:
49  /// \name Constructors
50  /// @{
51  ///
52 
53  /// Construct an empty asset path.
55 
56  /// Construct an asset path with \p path and no associated resolved path.
57  ///
58  /// If the passed \p path is not valid UTF-8 or contains C0 or C1 control
59  /// characters, raise a TfError and return the default-constructed empty
60  /// asset path.
61  SDF_API explicit SdfAssetPath(const std::string &path);
62 
63  /// Construct an asset path with \p path and an associated \p resolvedPath.
64  ///
65  /// If either the passed \path or \p resolvedPath are not valid UTF-8 or
66  /// either contain C0 or C1 control characters, raise a TfError and return
67  /// the default-constructed empty asset path.
68  SDF_API
69  SdfAssetPath(const std::string &path, const std::string &resolvedPath);
70 
71  /// @}
72 
73  ///\name Operators
74  /// @{
75 
76  /// Equality, including the resolved path.
77  bool operator==(const SdfAssetPath &rhs) const {
78  return _assetPath == rhs._assetPath &&
79  _resolvedPath == rhs._resolvedPath;
80  }
81 
82  /// Inequality operator
83  /// \sa SdfAssetPath::operator==(const SdfAssetPath&)
84  bool operator!=(const SdfAssetPath& rhs) const {
85  return !(*this == rhs);
86  }
87 
88  /// Ordering first by asset path, then by resolved path.
89  SDF_API bool operator<(const SdfAssetPath &rhs) const;
90 
91  /// Less than or equal operator
92  /// \sa SdfAssetPath::operator<(const SdfAssetPath&)
93  bool operator<=(const SdfAssetPath& rhs) const {
94  return !(rhs < *this);
95  }
96 
97  /// Greater than operator
98  /// \sa SdfAssetPath::operator<(const SdfAssetPath&)
99  bool operator>(const SdfAssetPath& rhs) const {
100  return rhs < *this;
101  }
102 
103  /// Greater than or equal operator
104  /// \sa SdfAssetPath::operator<(const SdfAssetPath&)
105  bool operator>=(const SdfAssetPath& rhs) const {
106  return !(*this < rhs);
107  }
108 
109  /// Hash function
110  size_t GetHash() const {
111  return TfHash::Combine(_assetPath, _resolvedPath);
112  }
113 
114  /// \class Hash
115  struct Hash
116  {
117  size_t operator()(const SdfAssetPath &ap) const {
118  return ap.GetHash();
119  }
120  };
121 
122  friend size_t hash_value(const SdfAssetPath &ap) { return ap.GetHash(); }
123 
124  /// @}
125 
126  /// \name Accessors
127  /// @{
128 
129  /// Return the asset path.
130  const std::string &GetAssetPath() const & {
131  return _assetPath;
132  }
133 
134  /// Overload for rvalues, move out the asset path.
136  return std::move(_assetPath);
137  }
138 
139  /// Return the resolved asset path, if any.
140  ///
141  /// Note that SdfAssetPath carries a resolved path only if its creator
142  /// passed one to the constructor. SdfAssetPath never performs resolution
143  /// itself.
144  const std::string &GetResolvedPath() const & {
145  return _resolvedPath;
146  }
147 
148  /// Overload for rvalues, move out the asset path.
150  return std::move(_resolvedPath);
151  }
152 
153  /// @}
154 
155 private:
156  friend inline void swap(SdfAssetPath &lhs, SdfAssetPath &rhs) {
157  lhs._assetPath.swap(rhs._assetPath);
158  lhs._resolvedPath.swap(rhs._resolvedPath);
159  }
160 
161  std::string _assetPath;
162  std::string _resolvedPath;
163 };
164 
165 /// \name Related
166 /// @{
167 
168 /// Stream insertion operator for the string representation of this assetPath.
169 ///
170 /// \note This always encodes only the result of GetAssetPath(). The resolved
171 /// path is ignored for the purpose of this operator. This means that
172 /// two SdfAssetPath s that do not compare equal may produce
173 /// indistinguishable ostream output.
174 SDF_API std::ostream& operator<<(std::ostream& out, const SdfAssetPath& ap);
175 
176 /// @}
177 
179 
180 #endif // PXR_USD_SDF_ASSET_PATH_H
SDF_API bool operator<(const SdfAssetPath &rhs) const
Ordering first by asset path, then by resolved path.
friend size_t hash_value(const SdfAssetPath &ap)
Equality, including the resolved path.
Definition: assetPath.h:122
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
friend void swap(SdfAssetPath &lhs, SdfAssetPath &rhs)
Definition: assetPath.h:156
SDF_API SdfAssetPath()
Construct an empty asset path.
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
const std::string & GetResolvedPath() const &
Definition: assetPath.h:144
bool operator>(const SdfAssetPath &rhs) const
Definition: assetPath.h:99
std::string GetResolvedPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:149
size_t GetHash() const
Hash function.
Definition: assetPath.h:110
const std::string & GetAssetPath() const &
Return the asset path.
Definition: assetPath.h:130
std::string GetAssetPath() const &&
Overload for rvalues, move out the asset path.
Definition: assetPath.h:135
bool operator<=(const SdfAssetPath &rhs) const
Definition: assetPath.h:93
size_t operator()(const SdfAssetPath &ap) const
Definition: assetPath.h:117
bool operator==(const SdfAssetPath &rhs) const
Equality, including the resolved path.
Definition: assetPath.h:77
#define SDF_API
Definition: api.h:40
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
SDF_API std::ostream & operator<<(std::ostream &out, const SdfAssetPath &ap)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator>=(const SdfAssetPath &rhs) const
Definition: assetPath.h:105
bool operator!=(const SdfAssetPath &rhs) const
Definition: assetPath.h:84