HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystemDiscoveryHelpers.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_SDR_FILESYSTEM_DISCOVERY_HELPERS_H
9 #define PXR_USD_SDR_FILESYSTEM_DISCOVERY_HELPERS_H
10 
11 /// \file sdr/filesystemDiscoveryHelpers.h
12 
13 #include "pxr/pxr.h"
14 #include "pxr/usd/sdr/api.h"
15 #include "pxr/usd/sdr/declare.h"
18 
19 #include <functional>
20 
22 
24 
25 /// \file filesystemDiscoveryHelpers.h
26 ///
27 /// Provides utilities that the default filesystem discovery plugin uses. If
28 /// a custom filesystem discovery plugin is needed, these can be used to fill
29 /// in a large chunk of the functionality.
30 ///
31 
32 /// Type of a function that can be used to parse a discovery result's identifier
33 /// into its function, name, and version.
34 using SdrParseIdentifierFn = std::function<
35  bool (const TfToken &identifier,
36  TfToken *function,
37  TfToken *name,
39 
40 /// Given a shader's \p identifier token, computes the corresponding
41 /// SdrShaderNode's function name, implementation name and shader version
42 /// (as SdrVersion).
43 ///
44 /// * \p function is the prefix of \p identifier up to and not
45 /// including the first underscore.
46 /// * \p version is the suffix of \p identifier comprised of one or
47 /// two integers representing the major and minor version numbers.
48 /// * \p name is the string we get by joining
49 /// <i>function</i> with everything that's in between <i>function</i>
50 /// and <i>version</i> with an underscore.
51 ///
52 /// Returns true if \p identifier is valid and was successfully split
53 /// into the different components.
54 ///
55 /// \note The python version of this function returns a tuple containing
56 /// (famiyName, implementationName, version).
57 SDR_API
58 bool
60  const TfToken &identifier,
61  TfToken *function,
62  TfToken *name,
64 
65 /// Returns a vector of discovery results that have been found while walking
66 /// the given search paths.
67 ///
68 /// Each path in \p searchPaths is walked recursively, optionally following
69 /// symlinks if \p followSymlinks is true, looking for files that match one of
70 /// the provided \p allowedExtensions. These files are represented in the
71 /// discovery results that are returned.
72 ///
73 /// The identifier for each discovery result is the base name of the represented
74 /// file with the extension removed. The \p parseIdentifierFn is used to parse
75 /// the function, name, and version from the identifier that will set in the
76 /// file's discovery result. By default, SdrFsHelpersSplitShaderIdentifier is
77 /// used to parse the identifier, but the function/name/version parsing behavior
78 /// can be changed by passing a custom parseIdentifierFn. Any identifiers that
79 /// cannot be parsed by whatever the parseIdentifierFn will be considered
80 /// invalid and not added as a discovery result. Note that the version for
81 /// every discovery result returned by this function will be naively marked as
82 /// being default even if multiple versions with the same name are found.
83 SDR_API
86  const SdrStringVec& searchPaths,
87  const SdrStringVec& allowedExtensions,
88  bool followSymlinks = true,
89  const SdrDiscoveryPluginContext* context = nullptr,
90  const SdrParseIdentifierFn &parseIdentifierFn =
92 );
93 
94 /// Struct for holding a URI and its resolved URI for a file discovered
95 /// by SdrFsHelpersDiscoverFiles
97 {
98  std::string uri;
99  std::string resolvedUri;
100 };
101 
102 /// A vector of URI/resolved URI structs.
103 using SdrDiscoveryUriVec = std::vector<SdrDiscoveryUri>;
104 
105 /// Returns a vector of discovered URIs (as both the unresolved URI and the
106 /// resolved URI) that are found while walking the given search paths.
107 ///
108 /// Each path in \p searchPaths is walked recursively, optionally following
109 /// symlinks if \p followSymlinks is true, looking for files that match one of
110 /// the provided \p allowedExtensions. These files' unresolved and resolved URIs
111 /// are returned in the result vector.
112 ///
113 /// This is an alternative to SdrFsHelpersDiscoverNodes for discovery plugins
114 /// that want to search for files that are not meant to be returned by discovery
115 /// themselves, but can be parsed to generate the discovery results.
116 SDR_API
119  const SdrStringVec& searchPaths,
120  const SdrStringVec& allowedExtensions,
121  bool followSymlinks = true
122 );
123 
125 
126 #endif // PXR_USD_SDR_FILESYSTEM_DISCOVERY_HELPERS_H
std::vector< SdrShaderNodeDiscoveryResult > SdrShaderNodeDiscoveryResultVec
std::vector< std::string > SdrStringVec
Definition: declare.h:61
SDR_API bool SdrFsHelpersSplitShaderIdentifier(const TfToken &identifier, TfToken *function, TfToken *name, SdrVersion *version)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
OutGridT const XformOp bool bool
SdrVersion.
Definition: declare.h:67
Definition: token.h:70
GLuint const GLchar * name
Definition: glcorearb.h:786
GT_API const UT_StringHolder version
std::vector< SdrDiscoveryUri > SdrDiscoveryUriVec
A vector of URI/resolved URI structs.
SDR_API SdrDiscoveryUriVec SdrFsHelpersDiscoverFiles(const SdrStringVec &searchPaths, const SdrStringVec &allowedExtensions, bool followSymlinks=true)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::function< bool(const TfToken &identifier, TfToken *function, TfToken *name, SdrVersion *version)> SdrParseIdentifierFn
SDR_API SdrShaderNodeDiscoveryResultVec SdrFsHelpersDiscoverShaderNodes(const SdrStringVec &searchPaths, const SdrStringVec &allowedExtensions, bool followSymlinks=true, const SdrDiscoveryPluginContext *context=nullptr, const SdrParseIdentifierFn &parseIdentifierFn=SdrFsHelpersSplitShaderIdentifier)
#define SDR_API
Definition: api.h:23