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_STRING_SLICE_INDEX_MAP_H 2#define SLANG_CORE_STRING_SLICE_INDEX_MAP_H 3 4#include "slang-basic.h" 5#include "slang-string-slice-pool.h" 6 7namespace Slang 8{ 9 10/* Maps an UnownedStringSlice to an index. All substrings are held internally in a StringSlicePool, 11and so owned by the type. 12*/ 13class StringSliceIndexMap 14{ 15public : 16/// An index that identifies a key value pair. 17typedef Index CountIndex ; 18 19/// Adds a key, value pair. Returns the CountIndex of the pair. 20/// If there is already a value stored for the key it is replaced. 21CountIndex add (const UnownedStringSlice & key ,Index valueIndex ); 22 23/// Finds or adds the slice. If the slice is added the defaultValueIndex is set. 24/// If not the index associated with the slice remains the same. 25/// Returns the CountIndex where the key,value pair are stored 26CountIndex findOrAdd (const UnownedStringSlice & key ,Index defaultValueIndex ); 27 28/// Gets the index associated with the key. Returns -1 if there is no associated index. 29SLANG_FORCE_INLINE Index getValue (const UnownedStringSlice & key ); 30 31/// Get the amount of pairs in the map 32Index getCount ()const {return m_indexMap .getCount (); } 33 34/// Get the slice and the index at the specified index 35SLANG_INLINE KeyValuePair < UnownedStringSlice ,Index > getAt (CountIndex countIndex )const ; 36 37/// Clear the contents of the map 38void clear (); 39 40/// Get the key at the specified index 41UnownedStringSlice getKeyAt (CountIndex index )const 42 { 43return m_pool .getSlice (StringSlicePool ::Handle (index )); 44 } 45/// Get the value at the specified index 46Index & getValueAt (CountIndex index ) {return m_indexMap [index ]; } 47 48/// Get the amount of key,value pairs 49Index getCount () {return m_indexMap .getCount (); } 50 51/// Ctor 52StringSliceIndexMap () 53 :m_pool (StringSlicePool ::Style ::Empty ) 54 { 55 } 56 57protected : 58StringSlicePool m_pool ;///< Pool holds the substrings 59List < Index > m_indexMap ;///< Maps a pool index to the output index 60}; 61 62// --------------------------------------------------------------------------- 63Index StringSliceIndexMap ::getValue (const UnownedStringSlice & key ) 64{ 65const Index poolIndex = m_pool .findIndex (key ); 66return (poolIndex >=0 ) ?m_indexMap [poolIndex ] :-1 ; 67} 68 69// --------------------------------------------------------------------------- 70KeyValuePair < UnownedStringSlice ,Index > StringSliceIndexMap ::getAt (CountIndex countIndex )const 71{ 72KeyValuePair < UnownedStringSlice ,Index > pair ; 73pair .key = m_pool .getSlice (StringSlicePool ::Handle (countIndex )); 74pair .value = m_indexMap [countIndex ]; 75return pair ; 76} 77 78}// namespace Slang 79 80#endif