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 
32 #include <hboost/functional/hash.hpp>
33 #include <hboost/operators.hpp>
34 #include <iosfwd>
35 #include <string>
36 
38 
39 /// \class SdfAssetPath
40 ///
41 /// Contains an asset path and an optional resolved path.
42 ///
44  public hboost::totally_ordered<SdfAssetPath>
45 {
46 public:
47  /// \name Constructors
48  /// @{
49  ///
50 
51  /// Construct an empty asset path.
53 
54  /// Construct asset path with no associated resolved path.
55  SDF_API explicit SdfAssetPath(const std::string &path);
56 
57  /// Construct an asset path with an associated resolved path.
58  SDF_API SdfAssetPath(const std::string &path, const std::string &resolvedPath);
59 
60  /// @}
61 
62  ///\name Operators
63  /// @{
64 
65  /// Equality, including the resolved path.
66  bool operator==(const SdfAssetPath &rhs) const {
67  return _assetPath == rhs._assetPath &&
68  _resolvedPath == rhs._resolvedPath;
69  }
70 
71  /// Ordering first by asset path, then by resolved path.
72  SDF_API bool operator<(const SdfAssetPath &rhs) const;
73 
74  /// Hash function
75  size_t GetHash() const {
76  size_t hash = 0;
77  hboost::hash_combine(hash, _assetPath);
78  hboost::hash_combine(hash, _resolvedPath);
79  return hash;
80  }
81 
82  /// \class Hash
83  struct Hash
84  {
85  size_t operator()(const SdfAssetPath &ap) const {
86  return ap.GetHash();
87  }
88  };
89 
90  friend size_t hash_value(const SdfAssetPath &ap) { return ap.GetHash(); }
91 
92  /// @}
93 
94  /// \name Accessors
95  /// @{
96 
97  /// Return the asset path.
98  const std::string &GetAssetPath() const {
99  return _assetPath;
100  }
101 
102  /// Return the resolved asset path, if any.
103  ///
104  /// Note that SdfAssetPath only carries a resolved path if the creator of
105  /// an instance supplied one to the constructor. SdfAssetPath will never
106  /// perform any resolution itself.
107  const std::string &GetResolvedPath() const {
108  return _resolvedPath;
109  }
110 
111  /// @}
112 
113 private:
114  friend inline void swap(SdfAssetPath &lhs, SdfAssetPath &rhs) {
115  lhs._assetPath.swap(rhs._assetPath);
116  lhs._resolvedPath.swap(rhs._resolvedPath);
117  }
118 
119  std::string _assetPath;
120  std::string _resolvedPath;
121 };
122 
123 /// \name Related
124 /// @{
125 
126 /// Stream insertion operator for the string representation of this assetPath.
127 ///
128 /// \note This always encodes only the result of GetAssetPath(). The resolved
129 /// path is ignored for the purpose of this operator. This means that
130 /// two SdfAssetPath that do not compare equal may produce
131 /// indistinguishable ostream output.
132 SDF_API std::ostream& operator<<(std::ostream& out, const SdfAssetPath& ap);
133 
134 /// @}
135 
137 
138 #endif // PXR_USD_SDF_ASSET_PATH_H
SDF_API bool operator<(const SdfAssetPath &rhs) const
Ordering first by asset path, then by resolved path.
const std::string & GetResolvedPath() const
Definition: assetPath.h:107
friend size_t hash_value(const SdfAssetPath &ap)
Equality, including the resolved path.
Definition: assetPath.h:90
friend void swap(SdfAssetPath &lhs, SdfAssetPath &rhs)
Definition: assetPath.h:114
SDF_API SdfAssetPath()
Construct an empty asset path.
size_t GetHash() const
Hash function.
Definition: assetPath.h:75
size_t operator()(const SdfAssetPath &ap) const
Definition: assetPath.h:85
GLsizei const GLchar *const * path
Definition: glew.h:6461
bool operator==(const SdfAssetPath &rhs) const
Equality, including the resolved path.
Definition: assetPath.h:66
#define SDF_API
Definition: api.h:40
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
const std::string & GetAssetPath() const
Return the asset path.
Definition: assetPath.h:98
SDF_API std::ostream & operator<<(std::ostream &out, const SdfAssetPath &ap)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91