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_IMPLICIT_DIRECTORY_COLLECTOR_H 2#define SLANG_CORE_IMPLICIT_DIRECTORY_COLLECTOR_H 3 4#include "slang-basic.h" 5#include "slang-string-slice-index-map.h" 6 7namespace Slang 8{ 9 10/* This class helps to find the contents and/or existence of an implicit directory.This finds the 11contents of a directory. 12 13This is achieved by using a path prefix that any contained path must at least match. If the 14remainder of the path contains a folder 15- detectable because it's not a leaf and so contains a delimiter - that directory is added. As a 16sub folder may contain many files, and the directory itself may also be defined, it is necessary to 17dedup. The deduping is handled by the StringSliceIndexMap. */ 18class ImplicitDirectoryCollector 19{ 20public : 21enum class State 22 { 23None ,///< Neither the directory or content have been found 24DirectoryExists ,///< The directory exists 25HasContent ,///< If it has content, the directory must exist 26 }; 27 28/// Get the current state 29State getState ()const 30 { 31return (m_map .getCount ()> 0 ) ?State ::HasContent 32 : (m_directoryExists ?State ::DirectoryExists :State ::None ); 33 } 34/// True if collector at least has the specified state 35bool hasState (State state ) {return Index (getState ()) >=Index (state ); } 36 37/// Set that it exists 38void setDirectoryExists (bool directoryExists ) {m_directoryExists = directoryExists ; } 39/// Get if it exists (implicitly or explicitly) 40bool getDirectoryExists ()const {return m_directoryExists || m_map .getCount ()> 0 ; } 41 42/// True if the path matches the prefix 43bool hasPrefix (const UnownedStringSlice & path )const 44 { 45return path .startsWith (m_prefix .getUnownedSlice ()); 46 } 47 48/// True if the directory has content 49bool hasContent ()const {return m_map .getCount ()> 0 ; } 50 51/// Gets the remainder or path after the prefix 52UnownedStringSlice getRemainder (const UnownedStringSlice & path )const 53 { 54SLANG_ASSERT (hasPrefix (path )); 55return UnownedStringSlice (path .begin ()+ m_prefix .getLength (),path .end ()); 56 } 57 58/// Add a remaining path 59void addRemainingPath (SlangPathType pathType ,const UnownedStringSlice & inPathRemainder ); 60/// Add a path 61void addPath (SlangPathType pathType ,const UnownedStringSlice & canonicalPath ); 62/// Enumerate the contents 63SlangResult enumerate (FileSystemContentsCallBack callback ,void * userData ); 64 65/// Ctor 66ImplicitDirectoryCollector (const String & canonicalPath ,bool directoryExists = false); 67 68static bool isRootPath (const UnownedStringSlice & path ); 69 70protected : 71StringSliceIndexMap m_map ; 72String m_prefix ; 73bool m_directoryExists ; 74}; 75 76}// namespace Slang 77 78#endif