HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
defaultResolver.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_H
8 #define PXR_USD_AR_DEFAULT_RESOLVER_H
9 
10 /// \file ar/defaultResolver.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/ar/api.h"
16 #include "pxr/usd/ar/resolver.h"
17 
18 #include <memory>
19 #include <string>
20 #include <vector>
21 
23 
24 /// \class ArDefaultResolver
25 ///
26 /// Default asset resolution implementation used when no plugin
27 /// implementation is provided.
28 ///
29 /// In order to resolve assets specified by relative paths, this resolver
30 /// implements a simple "search path" scheme. The resolver will anchor the
31 /// relative path to a series of directories and return the first absolute
32 /// path where the asset exists.
33 ///
34 /// The first directory will always be the current working directory. The
35 /// resolver will then examine the directories specified via the following
36 /// mechanisms (in order):
37 ///
38 /// - The currently-bound ArDefaultResolverContext for the calling thread
39 /// - ArDefaultResolver::SetDefaultSearchPath
40 ///
41 /// The environment variable PXR_AR_DEFAULT_SEARCH_PATH may be used to specify
42 /// an inital search path value. This is expected to be a list of directories
43 /// delimited by the platform's standard path separator. A search path
44 /// specified in this manner is overwritten by any call to
45 /// ArDefaultResolver::SetDefaultSearchPath.
46 ///
47 /// ArDefaultResolver supports creating an ArDefaultResolverContext via
48 /// ArResolver::CreateContextFromString by passing a list of directories
49 /// delimited by the platform's standard path separator.
51  : public ArResolver
52 {
53 public:
54  AR_API
55  ArDefaultResolver() = default;
56 
57  AR_API
58  virtual ~ArDefaultResolver() = default;
59 
60  /// Set the default search path that will be used during asset
61  /// resolution. Calling this function will trigger a ResolverChanged
62  /// notification to be sent if the search path differs from the
63  /// currently set default value.
64  ///
65  /// The inital search path may be specified using via the environment
66  /// variable PXR_AR_DEFAULT_SEARCH_PATH. Calling this function will
67  /// override any path specified in this manner.
68  ///
69  /// This function is not thread-safe and should not be called concurrently
70  /// with any other ArResolver operations
71  AR_API
72  static void SetDefaultSearchPath(
73  const std::vector<std::string>& searchPath);
74 
75 protected:
76  AR_API
77  std::string _CreateIdentifier(
78  const std::string& assetPath,
79  const ArResolvedPath& anchorAssetPath) const override;
80 
81  AR_API
82  std::string _CreateIdentifierForNewAsset(
83  const std::string& assetPath,
84  const ArResolvedPath& anchorAssetPath) const override;
85 
86  AR_API
88  const std::string& assetPath) const override;
89 
90  AR_API
92  const std::string& assetPath) const override;
93 
94  AR_API
96 
97  /// Creates a context that adds the directory containing \p assetPath
98  /// as a first directory to be searched, when the resulting context is
99  /// bound (\see ArResolverContextBinder).
100  ///
101  /// If \p assetPath is empty, returns an empty context; otherwise, if
102  /// \p assetPath is not an absolute filesystem path, it will first be
103  /// anchored to the process's current working directory.
104  AR_API
106  const std::string& assetPath) const override;
107 
108  /// Creates an ArDefaultResolverContext from \p contextStr. This
109  /// string is expected to be a list of directories delimited by
110  /// the platform's standard path separator.
111  AR_API
113  const std::string& contextStr) const override;
114 
115  AR_API
117  const std::string& assetPath) const override;
118 
119  AR_API
121  const std::string& path,
122  const ArResolvedPath& resolvedPath) const override;
123 
124  AR_API
125  std::shared_ptr<ArAsset> _OpenAsset(
126  const ArResolvedPath& resolvedPath) const override;
127 
128  /// Creates an ArFilesystemWriteableAsset for the asset at the
129  /// given \p resolvedPath.
130  AR_API
131  std::shared_ptr<ArWritableAsset> _OpenAssetForWrite(
132  const ArResolvedPath& resolvedPath,
133  WriteMode writeMode) const override;
134 
135 private:
136  const ArDefaultResolverContext* _GetCurrentContextPtr() const;
137 
138  ArResolverContext _defaultContext;
139 };
140 
142 
143 #endif // PXR_USD_AR_DEFAULT_RESOLVER_H
AR_API ArDefaultResolver()=default
AR_API std::string _CreateIdentifier(const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const override
AR_API ArResolvedPath _Resolve(const std::string &assetPath) const override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define AR_API
Definition: api.h:23
AR_API std::shared_ptr< ArAsset > _OpenAsset(const ArResolvedPath &resolvedPath) const override
AR_API ArTimestamp _GetModificationTimestamp(const std::string &path, const ArResolvedPath &resolvedPath) const override
virtual AR_API ~ArDefaultResolver()=default
AR_API ArResolverContext _CreateDefaultContextForAsset(const std::string &assetPath) const override
AR_API ArResolverContext _CreateContextFromString(const std::string &contextStr) const override
AR_API std::string _CreateIdentifierForNewAsset(const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const override
AR_API bool _IsContextDependentPath(const std::string &assetPath) const override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static AR_API void SetDefaultSearchPath(const std::vector< std::string > &searchPath)
WriteMode
Enumeration of write modes for OpenAssetForWrite.
Definition: resolver.h:294
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
AR_API std::shared_ptr< ArWritableAsset > _OpenAssetForWrite(const ArResolvedPath &resolvedPath, WriteMode writeMode) const override
AR_API ArResolverContext _CreateDefaultContext() const override
AR_API ArResolvedPath _ResolveForNewAsset(const std::string &assetPath) const override