yum-mirror/slang

Making it easier to work with shaders

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

Ellie Hermaszewskaformatf65d756bf

master
3.9 KiB125 linesraw
1#ifndef SLANG_CORE_NAME_VALUE_H
2#define SLANG_CORE_NAME_VALUE_H
3
4#include "slang-array-view.h"
5#include "slang-basic.h"
6
7namespace Slang
8{
9
10// When associating values with names we use this type
11typedef int32_t ValueInt;
12
13struct NameValue
14{
15    ValueInt value;
16    const char* name;
17};
18
19struct NamesValue
20{
21    ValueInt value;
22    const char* names; ///< Can hold comma delimited list of names
23};
24
25struct NamesDescriptionValue
26{
27    ValueInt value;
28    const char* names; ///< Can hold comma delimited list of names
29    const char*
30        description; ///< Optional description, can hold null ptr or empty string if not defined
31};
32
33struct NameValueUtil
34{
35    enum class NameKind
36    {
37        First, ///< Only the first name if there is more than one
38        All,   ///< All valid associated names
39    };
40
41    /// Use the default type to infer the actual type desired
42    template<typename T>
43    static T findValue(
44        const ConstArrayView<NameValue>& opts,
45        const UnownedStringSlice& slice,
46        T defaultValue)
47    {
48        return (T)findValue(opts, slice, ValueInt(defaultValue));
49    }
50    template<typename T>
51    static T findValue(
52        const ConstArrayView<NamesValue>& opts,
53        const UnownedStringSlice& slice,
54        T defaultValue)
55    {
56        return (T)findValue(opts, slice, ValueInt(defaultValue));
57    }
58    template<typename T>
59    static T findValue(
60        const ConstArrayView<NamesDescriptionValue>& opts,
61        const UnownedStringSlice& slice,
62        T defaultValue)
63    {
64        return (T)findValue(opts, slice, ValueInt(defaultValue));
65    }
66
67    /// Given a slice finds the associated value. If no entry is found, defaultValue is returned
68    static ValueInt findValue(
69        const ConstArrayView<NameValue>& opts,
70        const UnownedStringSlice& slice,
71        ValueInt defaultValue = -1);
72    static ValueInt findValue(
73        const ConstArrayView<NamesValue>& opts,
74        const UnownedStringSlice& slice,
75        ValueInt defaultValue = -1);
76    static ValueInt findValue(
77        const ConstArrayView<NamesDescriptionValue>& opts,
78        const UnownedStringSlice& slice,
79        ValueInt defaultValue = -1);
80
81    /// Given a value find the name. If there are multiple names, returns the first name
82    static UnownedStringSlice findName(
83        const ConstArrayView<NameValue>& opts,
84        ValueInt value,
85        const UnownedStringSlice& defaultName = UnownedStringSlice());
86    static UnownedStringSlice findName(
87        const ConstArrayView<NamesValue>& opts,
88        ValueInt value,
89        const UnownedStringSlice& defaultName = UnownedStringSlice());
90    static UnownedStringSlice findName(
91        const ConstArrayView<NamesDescriptionValue>& opts,
92        ValueInt value,
93        const UnownedStringSlice& defaultName = UnownedStringSlice());
94
95    /// Append all the names from opts to out
96    static void appendNames(
97        NameKind kind,
98        const ConstArrayView<NameValue>& opts,
99        List<UnownedStringSlice>& out);
100    static void appendNames(
101        NameKind kind,
102        const ConstArrayView<NamesValue>& opts,
103        List<UnownedStringSlice>& out);
104    static void appendNames(
105        NameKind kind,
106        const ConstArrayView<NamesDescriptionValue>& opts,
107        List<UnownedStringSlice>& out);
108
109    /// Return the list of all valid names
110    static List<UnownedStringSlice> getNames(NameKind kind, const ConstArrayView<NameValue>& opts);
111    static List<UnownedStringSlice> getNames(NameKind kind, const ConstArrayView<NamesValue>& opts);
112    static List<UnownedStringSlice> getNames(
113        NameKind kind,
114        const ConstArrayView<NamesDescriptionValue>& opts);
115
116    /// Get the description
117    static UnownedStringSlice findDescription(
118        const ConstArrayView<NamesDescriptionValue>& opts,
119        ValueInt value,
120        const UnownedStringSlice& defaultDescription = UnownedStringSlice());
121};
122
123} // namespace Slang
124
125#endif