HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packageResolver.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_PACKAGE_RESOLVER_H
8 #define PXR_USD_AR_PACKAGE_RESOLVER_H
9 
10 /// \file ar/packageResolver.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/ar/api.h"
14 
15 #include <memory>
16 #include <string>
17 
19 
20 class ArAsset;
21 class VtValue;
22 
23 /// \class ArPackageResolver
24 ///
25 /// Interface for resolving assets within package assets. A package resolver
26 /// is responsible for processing particular package asset formats and
27 /// resolving information about assets stored within that package.
28 ///
29 /// Each package resolver is associated with particular file formats and is
30 /// invoked by asset resolution when handling package-relative paths involving
31 /// those formats. ArPackageResolver instances are only used internally by Ar
32 /// and are not directly exposed to clients.
33 ///
34 /// \section ar_implementing_package_resolver Implementing a Package Resolver
35 ///
36 /// To implement a package resolver, users must create a plugin containing a
37 /// subclass of ArPackageResolver and register it with the plugin system
38 /// so that it can be discovered and instantiated at runtime.
39 ///
40 /// - Implement an ArPackageResolver subclass
41 /// \code{.cpp}
42 /// class CustomPackageResolver : public ArPackageResolver {
43 /// // ...
44 /// }
45 /// \endcode
46 ///
47 /// - In its implementation, register the ArPackageResolver subclass using
48 /// #AR_DEFINE_PACKAGE_RESOLVER
49 /// \code{.cpp}
50 /// # custom resolver's .cpp file
51 /// AR_DEFINE_PACKAGE_RESOLVER(CustomPackageResolver, ArPackageResolver);
52 /// \endcode
53 ///
54 /// - Declare the ArPackageResolver subclass in the plugin's plugInfo.json file.
55 /// Note that the entry for the subclass must declare the file format it
56 /// handles in the 'extensions' metadata.
57 /// \code{.json}
58 /// # plugInfo.json
59 /// {
60 /// "Plugins": [
61 /// {
62 /// "Info": {
63 /// "Types" : {
64 /// "CustomPackageResolver" : {
65 /// "bases": [ "ArPackageResolver" ],
66 /// "extensions": [ "pack" ]
67 /// }
68 /// }
69 /// },
70 /// ...
71 /// },
72 /// ...
73 /// ]
74 ///
75 /// }
76 /// \endcode
77 ///
79 {
80 public:
81  ArPackageResolver(const ArPackageResolver&) = delete;
83 
84  AR_API
85  virtual ~ArPackageResolver();
86 
87  // --------------------------------------------------------------------- //
88  /// \name Packaged Path Resolution Operations
89  ///
90  /// @{
91  // --------------------------------------------------------------------- //
92 
93  /// Returns the resolved path for the asset located at \p packagedPath
94  /// in the package specified by \p resolvedPackagePath if it exists.
95  /// If the asset does not exist in the package, returns an empty string.
96  ///
97  /// When ArResolver::Resolve is invoked on a package-relative path, the
98  /// path will be parsed into the outermost package path, and the inner
99  /// packaged path. The outermost package path will be resolved by the
100  /// primary resolver. ArPackageResolver::Resolve will then be called on
101  /// the corresponding package resolver with that resolved path and the
102  /// inner packaged path. If the inner packaged path is itself a
103  /// package-relative path, this process recurses until all paths have been
104  /// resolved.
105  ///
106  /// \see ArResolver::Resolve
107  AR_API
108  virtual std::string Resolve(
109  const std::string& resolvedPackagePath,
110  const std::string& packagedPath) = 0;
111 
112  /// @}
113 
114  // --------------------------------------------------------------------- //
115  /// \name Asset-specific Operations
116  ///
117  /// @{
118  // --------------------------------------------------------------------- //
119 
120  /// Returns an ArAsset object for the asset at \p resolvedPackagedPath
121  /// located in the package asset at \p resolvedPackagePath.
122  /// Returns an invalid std::shared_ptr if object could not be created.
123  ///
124  /// \see ArResolver::OpenAsset
125  AR_API
126  virtual std::shared_ptr<ArAsset> OpenAsset(
127  const std::string& resolvedPackagePath,
128  const std::string& resolvedPackagedPath) = 0;
129 
130  // --------------------------------------------------------------------- //
131  /// \name Scoped Resolution Cache
132  ///
133  /// These functions are called when scoped resolution caches are enabled
134  /// via ArResolver.
135  ///
136  /// \see \ref ArResolver_scopedCache "Scoped Resolution Cache"
137  /// @{
138  // --------------------------------------------------------------------- //
139 
140  /// Mark the start of a resolution caching scope.
141  ///
142  /// \see ArResolver::BeginCacheScope
143  AR_API
144  virtual void BeginCacheScope(
145  VtValue* cacheScopeData) = 0;
146 
147  /// Mark the end of a resolution caching scope.
148  ///
149  /// \see ArResolver::EndCacheScope
150  AR_API
151  virtual void EndCacheScope(
152  VtValue* cacheScopeData) = 0;
153 
154 protected:
155  AR_API
157 };
158 
160 
161 #endif // PXR_USD_AR_PACKAGE_RESOLVER_H
virtual AR_API void EndCacheScope(VtValue *cacheScopeData)=0
Definition: asset.h:27
AR_API ArPackageResolver()
virtual AR_API std::string Resolve(const std::string &resolvedPackagePath, const std::string &packagedPath)=0
#define AR_API
Definition: api.h:23
virtual AR_API void BeginCacheScope(VtValue *cacheScopeData)=0
ArPackageResolver & operator=(const ArPackageResolver &)=delete
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual AR_API std::shared_ptr< ArAsset > OpenAsset(const std::string &resolvedPackagePath, const std::string &resolvedPackagedPath)=0
Definition: value.h:146
virtual AR_API ~ArPackageResolver()