HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
packageUtils.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_UTILS_H
8 #define PXR_USD_AR_PACKAGE_UTILS_H
9 
10 /// \file ar/packageUtils.h
11 /// Utility functions for working with package assets
12 
13 #include "pxr/pxr.h"
14 #include "pxr/usd/ar/api.h"
15 
16 #include <string>
17 #include <vector>
18 
20 
21 // --------------------------------------------------------------------- //
22 /// \anchor Ar_packagePaths
23 /// \name Package Relative Paths
24 ///
25 /// Assets within package assets can be addressed via "package-relative"
26 /// paths. For example, given a hypothetical package <tt>"Model.package"</tt>,
27 /// the asset <tt>"Geom.file"</tt>, can be referred to using the path
28 /// <tt>"Model.package[Geom.file]"</tt>.
29 ///
30 /// A package-relative path consists of two parts:
31 ///
32 /// - The outer "package" path is the path to the containing package asset.
33 /// This path can be whatever is appropriate to the client's asset system.
34 ///
35 /// - The inner "packaged" path is the path to an asset contained within the
36 /// package asset. This path must be a relative path delimited by forward
37 /// slashes '/', with no leading slashes or drive or device letters. Note
38 /// that packaged paths may themselves be package-relative paths, since
39 /// package assets may be nested.
40 ///
41 /// Examples:
42 /// - <tt>/path/to/Model.package[a/b/Geom.file]</tt>
43 /// - <tt>/path/to/Model.package[a/b/Sub.package[c/d/Geom.file]]</tt>
44 ///
45 /// @{
46 // --------------------------------------------------------------------- //
47 
48 /// Return true if \p path is a package-relative path, false otherwise.
49 AR_API
50 bool
51 ArIsPackageRelativePath(const std::string& path);
52 
53 /// Combines the given \p paths into a single package-relative path, nesting
54 /// paths as necessary.
55 ///
56 /// \code
57 /// ArJoinPackageRelativePath(["a.pack", "b.pack"])
58 /// => "a.pack[b.pack]"
59 ///
60 /// ArJoinPackageRelativePath(["a.pack", "b.pack", "c.pack"])
61 /// => "a.pack[b.pack[c.pack]]"
62 ///
63 /// ArJoinPackageRelativePath(["a.pack[b.pack]", "c.pack"])
64 /// => "a.pack[b.pack[c.pack]]"
65 /// \endcode
66 AR_API
67 std::string
68 ArJoinPackageRelativePath(const std::vector<std::string>& paths);
69 
70 /// \overload
71 AR_API
72 std::string
73 ArJoinPackageRelativePath(const std::pair<std::string, std::string>& paths);
74 
75 /// \overload
76 AR_API
77 std::string
79  const std::string& packagePath, const std::string& packagedPath);
80 
81 /// Split package-relative path \p path into a (package path, packaged path)
82 /// pair. If \p packageRelativePath contains nested package-relative paths
83 /// the package path will be the outermost package path, and the packaged path
84 /// will be the inner package-relative path.
85 ///
86 /// \code
87 /// ArSplitPackageRelativePathOuter("a.pack[b.pack]")
88 /// => ("a.pack", "b.pack")
89 ///
90 /// ArSplitPackageRelativePathOuter("a.pack[b.pack[c.pack]]")
91 /// => ("a.pack", "b.pack[c.pack]")
92 /// \endcode
93 AR_API
94 std::pair<std::string, std::string>
95 ArSplitPackageRelativePathOuter(const std::string& path);
96 
97 /// Split package-relative path \p path into a (package path, packaged path)
98 /// pair. If \p packageRelativePath contains nested package-relative paths
99 /// the package path will be the outermost package-relative path, and the
100 /// packaged path will be the innermost packaged path.
101 ///
102 /// \code
103 /// ArSplitPackageRelativePathInner("a.pack[b.pack]")
104 /// => ("a.pack", "b.pack")
105 ///
106 /// ArSplitPackageRelativePathInner("a.pack[b.pack[c.pack]]")
107 /// => ("a.pack[b.pack]", "c.pack")
108 /// \endcode
109 AR_API
110 std::pair<std::string, std::string>
111 ArSplitPackageRelativePathInner(const std::string& path);
112 
113 /// @}
114 
116 
117 #endif // PXR_USD_AR_PACKAGE_UTILS_H
AR_API std::pair< std::string, std::string > ArSplitPackageRelativePathOuter(const std::string &path)
AR_API std::pair< std::string, std::string > ArSplitPackageRelativePathInner(const std::string &path)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
AR_API std::string ArJoinPackageRelativePath(const std::vector< std::string > &paths)
#define AR_API
Definition: api.h:23
AR_API bool ArIsPackageRelativePath(const std::string &path)
Return true if path is a package-relative path, false otherwise.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74