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 /// \note
14 /// All Ndr objects are deprecated in favor of the corresponding Sdr objects
15 /// in this file. All existing pxr/usd/ndr implementations will be moved to
16 /// pxr/usd/sdr.
17 
18 #include "pxr/pxr.h"
19 #include "pxr/usd/sdr/api.h"
20 #include "pxr/usd/sdr/declare.h"
23 
24 #include <functional>
25 
27 
29 
30 /// \file filesystemDiscoveryHelpers.h
31 ///
32 /// Provides utilities that the default filesystem discovery plugin uses. If
33 /// a custom filesystem discovery plugin is needed, these can be used to fill
34 /// in a large chunk of the functionality.
35 ///
36 
37 /// Type of a function that can be used to parse a discovery result's identifier
38 /// into its family, name, and version.
39 using SdrParseIdentifierFn = std::function<
40  bool (const TfToken &identifier,
41  TfToken *family,
42  TfToken *name,
44 
45 /// Given a shader's \p identifier token, computes the corresponding
46 /// SdrShaderNode's family name, implementation name and shader version
47 /// (as SdrVersion).
48 ///
49 /// * \p family is the prefix of \p identifier up to and not
50 /// including the first underscore.
51 /// * \p version is the suffix of \p identifier comprised of one or
52 /// two integers representing the major and minor version numbers.
53 /// * \p name is the string we get by joining
54 /// <i>family</i> with everything that's in between <i>family</i>
55 /// and <i>version</i> with an underscore.
56 ///
57 /// Returns true if \p identifier is valid and was successfully split
58 /// into the different components.
59 ///
60 /// \note The python version of this function returns a tuple containing
61 /// (famiyName, implementationName, version).
62 SDR_API
63 bool
65  const TfToken &identifier,
66  TfToken *family,
67  TfToken *name,
69 
70 /// Returns a vector of discovery results that have been found while walking
71 /// the given search paths.
72 ///
73 /// Each path in \p searchPaths is walked recursively, optionally following
74 /// symlinks if \p followSymlinks is true, looking for files that match one of
75 /// the provided \p allowedExtensions. These files are represented in the
76 /// discovery results that are returned.
77 ///
78 /// The identifier for each discovery result is the base name of the represented
79 /// file with the extension removed. The \p parseIdentifierFn is used to parse
80 /// the family, name, and version from the identifier that will set in the
81 /// file's discovery result. By default, SdrFsHelpersSplitShaderIdentifier is
82 /// used to parse the identifier, but the family/name/version parsing behavior
83 /// can be changed by passing a custom parseIdentifierFn. Any identifiers that
84 /// cannot be parsed by whatever the parseIdentifierFn will be considered
85 /// invalid and not added as a discovery result. Note that the version for
86 /// every discovery result returned by this function will be naively marked as
87 /// being default even if multiple versions with the same name are found.
88 SDR_API
91  const SdrStringVec& searchPaths,
92  const SdrStringVec& allowedExtensions,
93  bool followSymlinks = true,
94  const SdrDiscoveryPluginContext* context = nullptr,
95  const SdrParseIdentifierFn &parseIdentifierFn =
97 );
98 
99 /// Struct for holding a URI and its resolved URI for a file discovered
100 /// by SdrFsHelpersDiscoverFiles
102 {
103  std::string uri;
104  std::string resolvedUri;
105 };
106 
107 /// A vector of URI/resolved URI structs.
108 using SdrDiscoveryUriVec = std::vector<SdrDiscoveryUri>;
109 
110 /// Returns a vector of discovered URIs (as both the unresolved URI and the
111 /// resolved URI) that are found while walking the given search paths.
112 ///
113 /// Each path in \p searchPaths is walked recursively, optionally following
114 /// symlinks if \p followSymlinks is true, looking for files that match one of
115 /// the provided \p allowedExtensions. These files' unresolved and resolved URIs
116 /// are returned in the result vector.
117 ///
118 /// This is an alternative to SdrFsHelpersDiscoverNodes for discovery plugins
119 /// that want to search for files that are not meant to be returned by discovery
120 /// themselves, but can be parsed to generate the discovery results.
121 SDR_API
124  const SdrStringVec& searchPaths,
125  const SdrStringVec& allowedExtensions,
126  bool followSymlinks = true
127 );
128 
130 
131 #endif // PXR_USD_SDR_FILESYSTEM_DISCOVERY_HELPERS_H
std::vector< SdrShaderNodeDiscoveryResult > SdrShaderNodeDiscoveryResultVec
std::vector< std::string > SdrStringVec
Definition: declare.h:67
std::function< bool(const TfToken &identifier, TfToken *family, TfToken *name, SdrVersion *version)> SdrParseIdentifierFn
SDR_API bool SdrFsHelpersSplitShaderIdentifier(const TfToken &identifier, TfToken *family, TfToken *name, SdrVersion *version)
OutGridT const XformOp bool bool
SdrVersion.
Definition: declare.h:73
Definition: token.h:70
SDR_API SdrDiscoveryUriVec SdrFsHelpersDiscoverFiles(const SdrStringVec &searchPaths, const SdrStringVec &allowedExtensions, bool followSymlinks=true)
GLuint const GLchar * name
Definition: glcorearb.h:786
GT_API const UT_StringHolder version
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::vector< SdrDiscoveryUri > SdrDiscoveryUriVec
A vector of URI/resolved URI structs.
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