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