HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
filesystemDiscovery.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_H
9 #define PXR_USD_SDR_FILESYSTEM_DISCOVERY_H
10 
11 /// \file sdr/filesystemDiscovery.h
12 
13 #include "pxr/pxr.h"
15 #include "pxr/usd/sdr/api.h"
17 #include <functional>
18 
20 
22 
23 /// \class _SdrFilesystemDiscoveryPlugin
24 ///
25 /// Discovers shader nodes on the filesystem. The provided search paths are
26 /// walked to find files that have certain extensions. If a file with a
27 /// matching extension is found, it is turned into a
28 /// `SdrShaderNodeDiscoveryResult` and will be parsed into a node when its
29 /// information is accessed.
30 ///
31 /// Parameters for this plugin are specified via environment variables (which
32 /// must be set before the library is loaded):
33 ///
34 /// PXR_SDR_FS_PLUGIN_SEARCH_PATHS - The paths that should be searched,
35 /// recursively, for files that represent nodes. Paths should be separated by
36 /// either a ':' or a ';' depending on your platform (it should mimic the PATH
37 /// env var on your platform). See ARCH_PATH_LIST_SEP.
38 ///
39 /// PXR_SDR_FS_PLUGIN_ALLOWED_EXTS - The extensions on files that define nodes.
40 /// Do not include the leading ".". Extensions should be separated by a colon.
41 ///
42 /// PXR_SDR_FS_PLUGIN_FOLLOW_SYMLINKS - Whether symlinks should be followed
43 /// while walking the search paths. Set to "true" (case sensitive) if they
44 /// should be followed.
46 public:
47  /// A filter for discovered nodes. If the function returns false
48  /// then the discovered node is discarded. Otherwise the function
49  /// can modify the discovery result.
50  using Filter = std::function<bool(SdrShaderNodeDiscoveryResult&)>;
51 
52  /// Constructor.
53  SDR_API
55 
56  /// DiscoverShaderNodes() will pass each result to the given function for
57  /// modification. If the function returns false then the result is
58  /// discarded.
59  SDR_API
61 
62  /// Destructor
63  SDR_API
65 
66  /// Discover all of the nodes that appear within the the search paths
67  /// provided and match the extensions provided.
68  SDR_API
70  const Context&) override;
71 
72  /// Gets the paths that this plugin is searching for nodes in.
73  SDR_API
74  const SdrStringVec& GetSearchURIs() const override { return _searchPaths; }
75 
76 private:
77  /// The paths (abs) indicating where the plugin should search for nodes.
78  SdrStringVec _searchPaths;
79 
80  /// The extensions (excluding leading '.') that signify a valid node file.
81  /// The extension will be used as the `type` member in the resulting
82  /// `SdrShaderNodeDiscoveryResult` instance.
83  SdrStringVec _allowedExtensions;
84 
85  /// Whether or not to follow symlinks while scanning directories for files.
86  bool _followSymlinks;
87 
88  // The filter to run on the results.
89  Filter _filter;
90 };
91 
93 
94 #endif // PXR_USD_SDR_FILESYSTEM_DISCOVERY_H
std::vector< SdrShaderNodeDiscoveryResult > SdrShaderNodeDiscoveryResultVec
std::vector< std::string > SdrStringVec
Definition: declare.h:61
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_AND_REF_PTRS(_SdrFilesystemDiscoveryPlugin)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
SDR_API SdrShaderNodeDiscoveryResultVec DiscoverShaderNodes(const Context &) override
SDR_API const SdrStringVec & GetSearchURIs() const override
Gets the paths that this plugin is searching for nodes in.
SDR_API _SdrFilesystemDiscoveryPlugin()
Constructor.
SDR_API ~_SdrFilesystemDiscoveryPlugin()
Destructor.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
Context provides a wrapper around the Core library context object.
Definition: ImfContext.h:30
std::function< bool(SdrShaderNodeDiscoveryResult &)> Filter
#define SDR_API
Definition: api.h:23
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297