yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
3.7 KiB134 linesraw
1// slang-command-line.h
2#ifndef SLANG_COMMAND_LINE_H
3#define SLANG_COMMAND_LINE_H
4
5#include "slang-list.h"
6#include "slang-string.h"
7
8namespace Slang
9{
10
11struct ExecutableLocation
12{
13    typedef ExecutableLocation ThisType;
14
15    enum Type
16    {
17        Unknown, ///< Not specified
18        Path,    ///< The executable is set as a path (ie won't be searched for)
19        Name,    ///< The executable is passed as a name which will be searched for
20    };
21
22    /// Set the executable path.
23    /// NOTE! On some targets the executable path *must* include an extension to be able to start as
24    /// a process
25    void setPath(const String& path)
26    {
27        m_type = Type::Path;
28        m_pathOrName = path;
29    }
30
31    /// Set a filename (such that the path will be looked up)
32    void setName(const String& filename)
33    {
34        m_type = Type::Name;
35        m_pathOrName = filename;
36    }
37
38    void set(Type type, const String& pathOrName)
39    {
40        m_type = type;
41        m_pathOrName = pathOrName;
42    }
43
44    /// Set the executable path from a base directory and an executable name (no suffix such as
45    /// '.exe' needed)
46    void set(const String& dir, const String& name);
47
48    /// Determines if it's a name or a path when it sets
49    void set(const String& nameOrPath);
50
51    /// Append as text to out.
52    void append(StringBuilder& out) const;
53
54    /// Reset state to be same as ctor
55    void reset()
56    {
57        m_type = Type::Unknown;
58        m_pathOrName = String();
59    }
60
61    /// Equality means exactly the same definition.
62    /// *NOT* that exactly the same executable is specified
63    bool operator==(const ThisType& rhs) const
64    {
65        return m_type == rhs.m_type && m_pathOrName == rhs.m_pathOrName;
66    }
67    bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
68
69    ExecutableLocation() {}
70    ExecutableLocation(const String& dir, const String& name) { set(dir, name); }
71    ExecutableLocation(Type type, const String& pathOrName)
72        : m_type(type), m_pathOrName(pathOrName)
73    {
74    }
75
76    explicit ExecutableLocation(const String& nameOrPath) { set(nameOrPath); }
77
78    Type m_type = Type::Unknown;
79    String m_pathOrName;
80};
81
82struct CommandLine
83{
84    typedef CommandLine ThisType;
85
86    /// Add args - assumed unescaped
87    void addArg(const String& in) { m_args.add(in); }
88    void addArgs(const String* args, Int argsCount)
89    {
90        for (Int i = 0; i < argsCount; ++i)
91            addArg(args[i]);
92    }
93
94    void addArgIfNotFound(const String& in);
95
96    /// Find the index of an arg which is exact match for slice
97    SLANG_INLINE Index findArgIndex(const UnownedStringSlice& slice) const
98    {
99        return m_args.indexOf(slice);
100    }
101
102    /// For handling args where the switch is placed directly in front of the path
103    void addPrefixPathArg(
104        const char* prefix,
105        const String& path,
106        const char* pathPostfix = nullptr);
107
108    /// Get the total number of args
109    SLANG_FORCE_INLINE Index getArgCount() const { return m_args.getCount(); }
110
111    /// Reset to the initial state
112    void reset() { *this = CommandLine(); }
113
114    /// Append the args
115    void appendArgs(StringBuilder& out) const;
116
117    /// Append the command line to out
118    void append(StringBuilder& out) const;
119    /// convert into a string
120    String toString() const;
121
122    /// Convert just the args to string
123    String toStringArgs() const;
124
125    /// Set an executable location
126    void setExecutableLocation(const ExecutableLocation& loc) { m_executableLocation = loc; }
127
128    ExecutableLocation m_executableLocation; ///< The executable location
129    List<String> m_args;                     ///< The arguments (Stored *unescaped*)
130};
131
132} // namespace Slang
133
134#endif // SLANG_COMMAND_LINE_H