HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
defaultResolverContext.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 #ifndef PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
25 #define PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
26 
27 /// \file ar/defaultResolverContext.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/ar/api.h"
32 
33 #include <string>
34 #include <vector>
35 
37 
38 /// \class ArDefaultResolverContext
39 ///
40 /// Resolver context object that specifies a search path to use during
41 /// asset resolution. This object is intended for use with the default
42 /// ArDefaultResolver asset resolution implementation; see documentation for
43 /// that class for more details on the search path resolution algorithm.
44 ///
45 /// Example usage:
46 /// \code
47 /// ArDefaultResolverContext ctx({"/Local/Models", "/Installed/Models"});
48 /// {
49 /// // Bind the context object:
50 /// ArResolverContextBinder binder(ctx);
51 ///
52 /// // While the context is bound, all calls to ArResolver::Resolve
53 /// // (assuming ArDefaultResolver is the underlying implementation being
54 /// // used) will include the specified paths during resolution.
55 /// std::string resolvedPath = resolver.Resolve("ModelName/File.txt")
56 /// }
57 ///
58 /// // Once the context is no longer bound (due to the ArResolverContextBinder
59 /// // going out of scope), its search path no longer factors into asset
60 /// // resolution.
61 /// \endcode
62 ///
64 {
65 public:
66  /// Default construct a context with no search path.
67  ArDefaultResolverContext() = default;
68 
69  /// Construct a context with the given \p searchPath.
70  /// Elements in \p searchPath should be absolute paths. If they are not,
71  /// they will be anchored to the current working directory.
72  AR_API ArDefaultResolverContext(const std::vector<std::string>& searchPath);
73 
74  AR_API bool operator<(const ArDefaultResolverContext& rhs) const;
75  AR_API bool operator==(const ArDefaultResolverContext& rhs) const;
76  AR_API bool operator!=(const ArDefaultResolverContext& rhs) const;
77 
78  /// Return this context's search path.
79  const std::vector<std::string>& GetSearchPath() const
80  {
81  return _searchPath;
82  }
83 
84  /// Return a string representation of this context for debugging.
86 
87 private:
88  std::vector<std::string> _searchPath;
89 };
90 
91 AR_API size_t
93 
94 inline std::string
96 {
97  return context.GetAsString();
98 }
99 
101 
103 
104 #endif // PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
#define AR_API
Definition: api.h:40
std::string ArGetDebugString(const ArDefaultResolverContext &context)
AR_API bool operator<(const ArDefaultResolverContext &rhs) const
AR_DECLARE_RESOLVER_CONTEXT(ArDefaultResolverContext)
GLsizei const GLchar *const * string
Definition: glew.h:1844
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
AR_API bool operator!=(const ArDefaultResolverContext &rhs) const
AR_API std::string GetAsString() const
Return a string representation of this context for debugging.
const std::vector< std::string > & GetSearchPath() const
Return this context's search path.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
AR_API size_t hash_value(const ArDefaultResolverContext &context)
ArDefaultResolverContext()=default
Default construct a context with no search path.
AR_API bool operator==(const ArDefaultResolverContext &rhs) const