yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
2.0 KiB59 linesraw
1#ifndef SLANG_DIRECTORY_UTIL_H
2#define SLANG_DIRECTORY_UTIL_H
3
4#include "../../source/core/slang-io.h"
5
6class CombinePathVisitor : public Slang::Path::Visitor
7{
8public:
9    virtual void accept(Slang::Path::Type type, const Slang::UnownedStringSlice& filename)
10        SLANG_OVERRIDE
11    {
12        using namespace Slang;
13        const Path::TypeFlags flags = Path::TypeFlags(1) << int(type);
14        if (flags & m_allowedFlags)
15        {
16            m_paths.add(Path::combine(m_directoryPath, filename));
17        }
18    }
19
20    /// Ctor
21    CombinePathVisitor(const Slang::String& directoryPath, Slang::Path::TypeFlags allowedFlags)
22        : m_directoryPath(directoryPath), m_allowedFlags(allowedFlags)
23    {
24    }
25
26    Slang::List<Slang::String> m_paths;
27
28protected:
29    Slang::Path::TypeFlags m_allowedFlags;
30    Slang::String m_directoryPath;
31};
32
33/* A helper class for finding the contents of directories */
34class DirectoryUtil
35{
36public:
37    /// Enumerate subdirectories in the given `directoryPath`, storing in outPaths.
38    /// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
39    static SlangResult findDirectories(
40        const Slang::String& directoryPath,
41        Slang::List<Slang::String>& outPaths);
42
43    /// Enumerate files in the given `directoryPath` that match the provided
44    /// `pattern` as a simplified regex for files to return (e.g., "*.txt")
45    /// Note that the specifics of the pattern matching are *target specific*
46    /// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
47    static SlangResult findFilesMatchingPattern(
48        const Slang::String& directoryPath,
49        const char* pattern,
50        Slang::List<Slang::String>& outPaths);
51
52    /// Enumerate files in the given `directoryPath`, storing in outPaths.
53    /// @return SLANG_OK on success or SLANG_E_NOT_FOUND if directory is not found.
54    static SlangResult findFiles(
55        const Slang::String& directoryPath,
56        Slang::List<Slang::String>& outPaths);
57};
58
59#endif // SLANG_DIRECTORY_UTIL_H