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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
8 #define PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
9 
10 /// \file ar/defaultResolverContext.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/ar/api.h"
15 
16 #include <string>
17 #include <vector>
18 
20 
21 /// \class ArDefaultResolverContext
22 ///
23 /// Resolver context object that specifies a search path to use during
24 /// asset resolution. This object is intended for use with the default
25 /// ArDefaultResolver asset resolution implementation; see documentation for
26 /// that class for more details on the search path resolution algorithm.
27 ///
28 /// Example usage:
29 /// \code
30 /// ArDefaultResolverContext ctx({"/Local/Models", "/Installed/Models"});
31 /// {
32 /// // Bind the context object:
33 /// ArResolverContextBinder binder(ctx);
34 ///
35 /// // While the context is bound, all calls to ArResolver::Resolve
36 /// // (assuming ArDefaultResolver is the underlying implementation being
37 /// // used) will include the specified paths during resolution.
38 /// std::string resolvedPath = resolver.Resolve("ModelName/File.txt")
39 /// }
40 ///
41 /// // Once the context is no longer bound (due to the ArResolverContextBinder
42 /// // going out of scope), its search path no longer factors into asset
43 /// // resolution.
44 /// \endcode
45 ///
47 {
48 public:
49  /// Default construct a context with no search path.
50  ArDefaultResolverContext() = default;
51 
52  /// Construct a context with the given \p searchPath.
53  /// Elements in \p searchPath should be absolute paths. If they are not,
54  /// they will be anchored to the current working directory.
55  AR_API ArDefaultResolverContext(const std::vector<std::string>& searchPath);
56 
57  AR_API bool operator<(const ArDefaultResolverContext& rhs) const;
58  AR_API bool operator==(const ArDefaultResolverContext& rhs) const;
59  AR_API bool operator!=(const ArDefaultResolverContext& rhs) const;
60 
61  /// Return this context's search path.
62  const std::vector<std::string>& GetSearchPath() const
63  {
64  return _searchPath;
65  }
66 
67  /// Return a string representation of this context for debugging.
68  AR_API std::string GetAsString() const;
69 
70 private:
71  std::vector<std::string> _searchPath;
72 };
73 
74 AR_API size_t
75 hash_value(const ArDefaultResolverContext& context);
76 
77 inline std::string
79 {
80  return context.GetAsString();
81 }
82 
84 
86 
87 #endif // PXR_USD_AR_DEFAULT_RESOLVER_CONTEXT_H
#define AR_API
Definition: api.h:23
std::string ArGetDebugString(const ArDefaultResolverContext &context)
AR_API bool operator<(const ArDefaultResolverContext &rhs) const
AR_DECLARE_RESOLVER_CONTEXT(ArDefaultResolverContext)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
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:74
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