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 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_H
25 #define PXR_USD_AR_DEFAULT_RESOLVER_H
26 
27 /// \file ar/defaultResolver.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/ar/api.h"
33 #include "pxr/usd/ar/resolver.h"
34 
35 #include <memory>
36 #include <string>
37 #include <vector>
38 
40 
41 /// \class ArDefaultResolver
42 ///
43 /// Default asset resolution implementation used when no plugin
44 /// implementation is provided.
45 ///
46 /// In order to resolve assets specified by relative paths, this resolver
47 /// implements a simple "search path" scheme. The resolver will anchor the
48 /// relative path to a series of directories and return the first absolute
49 /// path where the asset exists.
50 ///
51 /// The first directory will always be the current working directory. The
52 /// resolver will then examine the directories specified via the following
53 /// mechanisms (in order):
54 ///
55 /// - The currently-bound ArDefaultResolverContext for the calling thread
56 /// - ArDefaultResolver::SetDefaultSearchPath
57 /// - The environment variable PXR_AR_DEFAULT_SEARCH_PATH. This is
58 /// expected to be a list of directories delimited by the platform's
59 /// standard path separator.
60 ///
61 /// ArDefaultResolver supports creating an ArDefaultResolverContext via
62 /// ArResolver::CreateContextFromString by passing a list of directories
63 /// delimited by the platform's standard path separator.
65  : public ArResolver
66 {
67 public:
68  AR_API
70 
71  AR_API
72  virtual ~ArDefaultResolver();
73 
74  /// Set the default search path that will be used during asset
75  /// resolution. This must be called before the first call
76  /// to \ref ArGetResolver.
77  /// The specified paths will be searched *in addition to, and before*
78  /// paths specified via the environment variable PXR_AR_DEFAULT_SEARCH_PATH
79  AR_API
80  static void SetDefaultSearchPath(
81  const std::vector<std::string>& searchPath);
82 
83 protected:
84  AR_API
86  const std::string& assetPath,
87  const ArResolvedPath& anchorAssetPath) const override;
88 
89  AR_API
91  const std::string& assetPath,
92  const ArResolvedPath& anchorAssetPath) const override;
93 
94  AR_API
96  const std::string& assetPath) const override;
97 
98  AR_API
100  const std::string& assetPath) const override;
101 
102  AR_API
103  ArResolverContext _CreateDefaultContext() const override;
104 
105  /// Creates a context that adds the directory containing \p assetPath
106  /// as a first directory to be searched, when the resulting context is
107  /// bound (\see ArResolverContextBinder).
108  ///
109  /// If \p assetPath is empty, returns an empty context; otherwise, if
110  /// \p assetPath is not an absolute filesystem path, it will first be
111  /// anchored to the process's current working directory.
112  AR_API
114  const std::string& assetPath) const override;
115 
116  /// Creates an ArDefaultResolverContext from \p contextStr. This
117  /// string is expected to be a list of directories delimited by
118  /// the platform's standard path separator.
119  AR_API
121  const std::string& contextStr) const override;
122 
123  AR_API
125  const std::string& assetPath) const override;
126 
127  AR_API
129  const std::string& path,
130  const ArResolvedPath& resolvedPath) const override;
131 
132  AR_API
133  std::shared_ptr<ArAsset> _OpenAsset(
134  const ArResolvedPath& resolvedPath) const override;
135 
136  /// Creates an ArFilesystemWriteableAsset for the asset at the
137  /// given \p resolvedPath.
138  AR_API
139  std::shared_ptr<ArWritableAsset> _OpenAssetForWrite(
140  const ArResolvedPath& resolvedPath,
141  WriteMode writeMode) const override;
142 
143 private:
144  const ArDefaultResolverContext* _GetCurrentContextPtr() const;
145 
146  ArDefaultResolverContext _fallbackContext;
147  ArResolverContext _defaultContext;
148 };
149 
151 
152 #endif // PXR_USD_AR_DEFAULT_RESOLVER_H
AR_API std::string _CreateIdentifier(const std::string &assetPath, const ArResolvedPath &anchorAssetPath) const override
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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:40
virtual AR_API ~ArDefaultResolver()
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
AR_API ArResolverContext _CreateDefaultContextForAsset(const std::string &assetPath) const override
AR_API ArDefaultResolver()
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:1432
static AR_API void SetDefaultSearchPath(const std::vector< std::string > &searchPath)
WriteMode
Enumeration of write modes for OpenAssetForWrite.
Definition: resolver.h:311
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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