yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1#include "slang-implicit-directory-collector.h" 2 3#include "slang-io.h" 4 5namespace Slang 6{ 7 8// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ImplicitDirectoryCollector !!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 9 10ImplicitDirectoryCollector ::ImplicitDirectoryCollector ( 11const String & canonicalPath , 12bool directoryExists ) 13 :m_directoryExists (directoryExists ) 14{ 15if (!isRootPath (canonicalPath .getUnownedSlice ())) 16 { 17StringBuilder buffer ; 18buffer <<canonicalPath ; 19buffer .append ('/' ); 20m_prefix = buffer .produceString (); 21 } 22} 23 24/* static */ bool ImplicitDirectoryCollector ::isRootPath (const UnownedStringSlice & path ) 25{ 26const auto length = path .getLength (); 27if (length == 0 ) 28 { 29return true; 30 } 31else if (length == 1 ) 32 { 33const auto c = path [0 ]; 34return c == '.' || Path ::isDelimiter (c ); 35 } 36return false; 37} 38 39void ImplicitDirectoryCollector ::addRemainingPath ( 40SlangPathType pathType , 41const UnownedStringSlice & inPathRemainder ) 42{ 43// If it's zero length we probably don't want to add it 44if (inPathRemainder .getLength ()== 0 ) 45 { 46// It's empty so don't add normal way - implies the directory exists 47m_directoryExists = true; 48return ; 49 } 50 51UnownedStringSlice pathRemainder (inPathRemainder ); 52const Index slashIndex = pathRemainder .indexOf ('/' ); 53 54// If we have a following / that means it's an implicit directory. 55if (slashIndex >=0 ) 56 { 57pathType = SLANG_PATH_TYPE_DIRECTORY ; 58pathRemainder = 59UnownedStringSlice (pathRemainder .begin (),pathRemainder .begin ()+ slashIndex ); 60 } 61 62const Index countIndex = m_map .findOrAdd (pathRemainder ,pathType ); 63SLANG_UNUSED (countIndex ); 64// Make sure they are the same type 65SLANG_ASSERT (SlangPathType (m_map .getValueAt (countIndex ))== pathType ); 66} 67 68void ImplicitDirectoryCollector ::addPath ( 69SlangPathType pathType , 70const UnownedStringSlice & canonicalPath ) 71{ 72if (canonicalPath != toSlice ("." )&& hasPrefix (canonicalPath )) 73 { 74UnownedStringSlice remainder = getRemainder (canonicalPath ); 75addRemainingPath (pathType ,remainder ); 76 } 77} 78 79SlangResult ImplicitDirectoryCollector ::enumerate ( 80FileSystemContentsCallBack callback , 81void * userData ) 82{ 83const Int count = m_map .getCount (); 84 85for (Index i = 0 ;i < count ;++ i ) 86 { 87const auto & pair = m_map .getAt (i ); 88 89UnownedStringSlice path = pair .key ; 90SlangPathType pathType = SlangPathType (pair .value ); 91 92// Note *is* 0 terminated in the pool 93// Let's check tho 94SLANG_ASSERT (path .begin ()[path .getLength ()]== 0 ); 95callback (pathType ,path .begin (),userData ); 96 } 97 98return getDirectoryExists () ?SLANG_OK :SLANG_E_NOT_FOUND ; 99} 100 101}// namespace Slang