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