yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-command-line.h 2#ifndef SLANG_COMMAND_LINE_H 3#define SLANG_COMMAND_LINE_H 4 5#include "slang-list.h" 6#include "slang-string.h" 7 8namespace Slang 9{ 10 11struct ExecutableLocation 12{ 13typedef ExecutableLocation ThisType ; 14 15enum Type 16 { 17Unknown ,///< Not specified 18Path ,///< The executable is set as a path (ie won't be searched for) 19Name ,///< The executable is passed as a name which will be searched for 20 }; 21 22/// Set the executable path. 23/// NOTE! On some targets the executable path *must* include an extension to be able to start as 24/// a process 25void setPath (const String & path ) 26 { 27m_type = Type ::Path ; 28m_pathOrName = path ; 29 } 30 31/// Set a filename (such that the path will be looked up) 32void setName (const String & filename ) 33 { 34m_type = Type ::Name ; 35m_pathOrName = filename ; 36 } 37 38void set (Type type ,const String & pathOrName ) 39 { 40m_type = type ; 41m_pathOrName = pathOrName ; 42 } 43 44/// Set the executable path from a base directory and an executable name (no suffix such as 45/// '.exe' needed) 46void set (const String & dir ,const String & name ); 47 48/// Determines if it's a name or a path when it sets 49void set (const String & nameOrPath ); 50 51/// Append as text to out. 52void append (StringBuilder & out )const ; 53 54/// Reset state to be same as ctor 55void reset () 56 { 57m_type = Type ::Unknown ; 58m_pathOrName = String (); 59 } 60 61/// Equality means exactly the same definition. 62/// *NOT* that exactly the same executable is specified 63bool operator == (const ThisType & rhs )const 64 { 65return m_type == rhs .m_type && m_pathOrName == rhs .m_pathOrName ; 66 } 67bool operator != (const ThisType & rhs )const {return !(* this == rhs ); } 68 69ExecutableLocation () {} 70ExecutableLocation (const String & dir ,const String & name ) {set (dir ,name ); } 71ExecutableLocation (Type type ,const String & pathOrName ) 72 :m_type (type ),m_pathOrName (pathOrName ) 73 { 74 } 75 76explicit ExecutableLocation (const String & nameOrPath ) {set (nameOrPath ); } 77 78Type m_type = Type ::Unknown ; 79String m_pathOrName ; 80}; 81 82struct CommandLine 83{ 84typedef CommandLine ThisType ; 85 86/// Add args - assumed unescaped 87void addArg (const String & in ) {m_args .add (in ); } 88void addArgs (const String * args ,Int argsCount ) 89 { 90for (Int i = 0 ;i < argsCount ;++ i ) 91addArg (args [i ]); 92 } 93 94void addArgIfNotFound (const String & in ); 95 96/// Find the index of an arg which is exact match for slice 97SLANG_INLINE Index findArgIndex (const UnownedStringSlice & slice )const 98 { 99return m_args .indexOf (slice ); 100 } 101 102/// For handling args where the switch is placed directly in front of the path 103void addPrefixPathArg ( 104const char * prefix , 105const String & path , 106const char * pathPostfix = nullptr ); 107 108/// Get the total number of args 109SLANG_FORCE_INLINE Index getArgCount ()const {return m_args .getCount (); } 110 111/// Reset to the initial state 112void reset () {* this = CommandLine (); } 113 114/// Append the args 115void appendArgs (StringBuilder & out )const ; 116 117/// Append the command line to out 118void append (StringBuilder & out )const ; 119/// convert into a string 120String toString ()const ; 121 122/// Convert just the args to string 123String toStringArgs ()const ; 124 125/// Set an executable location 126void setExecutableLocation (const ExecutableLocation & loc ) {m_executableLocation = loc ; } 127 128ExecutableLocation m_executableLocation ;///< The executable location 129List < String > m_args ;///< The arguments (Stored *unescaped*) 130}; 131 132}// namespace Slang 133 134#endif // SLANG_COMMAND_LINE_H