yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-name-value.cpp 2 3#include "slang-name-value.h" 4 5#include "slang-char-util.h" 6#include "slang-string-util.h" 7 8namespace Slang 9{ 10 11/* static */ ValueInt NameValueUtil ::findValue ( 12const ConstArrayView < NameValue >& opts , 13const UnownedStringSlice & slice , 14ValueInt defaultValue ) 15{ 16for (const auto & opt :opts ) 17 { 18if (UnownedStringSlice (opt .name )== slice ) 19 { 20return opt .value ; 21 } 22 } 23return defaultValue ; 24} 25 26/* static */ ValueInt NameValueUtil ::findValue ( 27const ConstArrayView < NamesValue >& opts , 28const UnownedStringSlice & slice , 29ValueInt defaultValue ) 30{ 31for (const auto & opt :opts ) 32 { 33UnownedStringSlice names (opt .names ); 34 35if (StringUtil ::indexOfInSplit (names ,',' ,slice ) >=0 ) 36 { 37return opt .value ; 38 } 39 } 40return defaultValue ; 41} 42 43/* static */ ValueInt NameValueUtil ::findValue ( 44const ConstArrayView < NamesDescriptionValue >& opts , 45const UnownedStringSlice & slice , 46ValueInt defaultValue ) 47{ 48for (const auto & opt :opts ) 49 { 50UnownedStringSlice names (opt .names ); 51if (StringUtil ::indexOfInSplit (names ,',' ,slice ) >=0 ) 52 { 53return opt .value ; 54 } 55 } 56return defaultValue ; 57} 58 59/* static */ UnownedStringSlice NameValueUtil ::findName ( 60const ConstArrayView < NameValue >& opts , 61ValueInt value , 62const UnownedStringSlice & defaultName ) 63{ 64for (const auto & opt :opts ) 65 { 66if (opt .value == value ) 67 { 68return UnownedStringSlice (opt .name ); 69 } 70 } 71return defaultName ; 72} 73 74/* static */ UnownedStringSlice NameValueUtil ::findName ( 75const ConstArrayView < NamesValue >& opts , 76ValueInt value , 77const UnownedStringSlice & defaultName ) 78{ 79for (const auto & opt :opts ) 80 { 81if (opt .value == value ) 82 { 83// Get the first name 84return StringUtil ::getAtInSplit (UnownedStringSlice (opt .names ),',' ,0 ); 85 } 86 } 87 88return defaultName ; 89} 90 91/* static */ UnownedStringSlice NameValueUtil ::findName ( 92const ConstArrayView < NamesDescriptionValue >& opts , 93ValueInt value , 94const UnownedStringSlice & defaultName ) 95{ 96for (const auto & opt :opts ) 97 { 98if (opt .value == value ) 99 { 100// Get the first name 101return StringUtil ::getAtInSplit (UnownedStringSlice (opt .names ),',' ,0 ); 102 } 103 } 104 105return defaultName ; 106} 107 108 109/* static */ UnownedStringSlice NameValueUtil ::findDescription ( 110const ConstArrayView < NamesDescriptionValue >& opts , 111ValueInt value , 112const UnownedStringSlice & defaultDescription ) 113{ 114for (const auto & opt :opts ) 115 { 116if (opt .value == value && opt .description ) 117 { 118return UnownedStringSlice (opt .description ); 119 } 120 } 121 122return defaultDescription ; 123} 124 125/* static */ void NameValueUtil ::appendNames ( 126NameKind kind , 127const ConstArrayView < NameValue >& opts , 128List < UnownedStringSlice >& out ) 129{ 130SLANG_UNUSED (kind ); 131for (auto & opt :opts ) 132 { 133out .add (UnownedStringSlice (opt .name )); 134 } 135} 136 137static void _appendNames ( 138NameValueUtil ::NameKind kind , 139const char * names , 140List < UnownedStringSlice >& out ) 141{ 142if (kind == NameValueUtil ::NameKind ::All ) 143 { 144StringUtil ::appendSplit (UnownedStringSlice (names ),',' ,out ); 145 } 146else 147 { 148out .add (StringUtil ::getAtInSplit (UnownedStringSlice (names ),',' ,0 )); 149 } 150} 151 152/* static */ void NameValueUtil ::appendNames ( 153NameKind kind , 154const ConstArrayView < NamesValue >& opts , 155List < UnownedStringSlice >& out ) 156{ 157for (auto & opt :opts ) 158 { 159_appendNames (kind ,opt .names ,out ); 160 } 161} 162 163/* static */ void NameValueUtil ::appendNames ( 164NameKind kind , 165const ConstArrayView < NamesDescriptionValue >& opts , 166List < UnownedStringSlice >& out ) 167{ 168for (auto & opt :opts ) 169 { 170_appendNames (kind ,opt .names ,out ); 171 } 172} 173 174/* static */ List < UnownedStringSlice > NameValueUtil ::getNames ( 175NameKind kind , 176const ConstArrayView < NameValue >& opts ) 177{ 178List < UnownedStringSlice > names ; 179appendNames (kind ,opts ,names ); 180return names ; 181} 182 183/* static */ List < UnownedStringSlice > NameValueUtil ::getNames ( 184NameKind kind , 185const ConstArrayView < NamesValue >& opts ) 186{ 187List < UnownedStringSlice > names ; 188appendNames (kind ,opts ,names ); 189return names ; 190} 191 192/* static */ List < UnownedStringSlice > NameValueUtil ::getNames ( 193NameKind kind , 194const ConstArrayView < NamesDescriptionValue >& opts ) 195{ 196List < UnownedStringSlice > names ; 197appendNames (kind ,opts ,names ); 198return names ; 199} 200 201}// namespace Slang