yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// slang-artifact-representation-impl.h 2#ifndef SLANG_ARTIFACT_REPRESENTATION_IMPL_H 3#define SLANG_ARTIFACT_REPRESENTATION_IMPL_H 4 5#include "../core/slang-com-object.h" 6#include "../core/slang-memory-arena.h" 7#include "slang-artifact-representation.h" 8#include "slang-com-helper.h" 9#include "slang-com-ptr.h" 10#include "slang-source-loc.h" 11 12namespace Slang 13{ 14 15/* A representation of an artifact that is held in a file */ 16class OSFileArtifactRepresentation :public ComBaseObject ,public IOSFileArtifactRepresentation 17{ 18public : 19typedef OSFileArtifactRepresentation ThisType ; 20 21SLANG_COM_BASE_IUNKNOWN_ALL 22 23// ICastable 24SLANG_NO_THROW void * SLANG_MCALL castAs (const Guid & guid )SLANG_OVERRIDE ; 25 26// IArtifactRepresentation 27SLANG_NO_THROW SlangResult SLANG_MCALL 28createRepresentation (const Guid & typeGuid ,ICastable ** outCastable )SLANG_OVERRIDE ; 29SLANG_NO_THROW bool SLANG_MCALL exists ()SLANG_OVERRIDE ; 30 31// IPathArtifactRepresentation 32virtual SLANG_NO_THROW const char * SLANG_MCALL getPath () SLANG_OVERRIDE 33{ 34return m_path. getBuffer (); 35} 36virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType () SLANG_OVERRIDE 37{ 38return SLANG_PATH_TYPE_FILE ; 39} 40virtual SLANG_NO_THROW const char * SLANG_MCALL getUniqueIdentity () SLANG_OVERRIDE ; 41 42// IOSFileArtifactRepresentation 43virtual SLANG_NO_THROW Kind SLANG_MCALL getKind () SLANG_OVERRIDE { return m_kind; } 44virtual SLANG_NO_THROW void SLANG_MCALL disown () SLANG_OVERRIDE ; 45virtual SLANG_NO_THROW IOSFileArtifactRepresentation * SLANG_MCALL getLockFile () SLANG_OVERRIDE 46{ 47return m_lockFile; 48} 49 50OSFileArtifactRepresentation( 51Kind kind, 52const UnownedStringSlice & path, 53IOSFileArtifactRepresentation * lockFile) 54: m_kind ( kind ), m_lockFile ( lockFile ), m_path ( path ) 55{ 56} 57 58~ OSFileArtifactRepresentation (); 59 60static ComPtr < IOSFileArtifactRepresentation > create ( 61Kind kind, 62const UnownedStringSlice & path, 63IOSFileArtifactRepresentation * lockFile) 64{ 65return ComPtr < IOSFileArtifactRepresentation > (new ThisType (kind, path, lockFile)); 66} 67 68protected : 69void * getInterface ( const Guid & uuid); 70void * getObject ( const Guid & uuid); 71 72/// True if the file is owned 73bool _isOwned () const { return Index (m_kind) >= Index (Kind::Owned); } 74 75static ISlangMutableFileSystem * _getFileSystem (); 76 77Kind m_kind; 78String m_path; 79String m_uniqueIdentity; 80 81ComPtr < IOSFileArtifactRepresentation > m_lockFile; 82ComPtr < ISlangMutableFileSystem > m_fileSystem; 83}; 84 85class ExtFileArtifactRepresentation : public ComBaseObject, public IExtFileArtifactRepresentation 86{ 87public : 88typedef ExtFileArtifactRepresentation ThisType; 89 90SLANG_COM_BASE_IUNKNOWN_ALL 91 92// ICastable 93SLANG_NO_THROW void * SLANG_MCALL castAs( const Guid & guid) SLANG_OVERRIDE ; 94 95// IArtifactRepresentation 96SLANG_NO_THROW SlangResult SLANG_MCALL 97createRepresentation ( const Guid & typeGuid, ICastable ** outCastable) SLANG_OVERRIDE ; 98SLANG_NO_THROW bool SLANG_MCALL exists () SLANG_OVERRIDE ; 99 100// IPathArtifactRepresentation 101virtual SLANG_NO_THROW const char * SLANG_MCALL getPath () SLANG_OVERRIDE 102{ 103return m_path. getBuffer (); 104} 105virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType () SLANG_OVERRIDE 106{ 107return SLANG_PATH_TYPE_FILE ; 108} 109virtual SLANG_NO_THROW const char * SLANG_MCALL getUniqueIdentity () SLANG_OVERRIDE ; 110 111// IExtFileArtifactRepresentation 112virtual SLANG_NO_THROW ISlangFileSystemExt * SLANG_MCALL getFileSystem () SLANG_OVERRIDE 113{ 114return m_fileSystem; 115} 116 117ExtFileArtifactRepresentation( const UnownedStringSlice & path, ISlangFileSystemExt * fileSystem) 118: m_path (path), m_fileSystem (fileSystem) 119{ 120} 121 122static ComPtr < IExtFileArtifactRepresentation > create ( 123const UnownedStringSlice & path, 124ISlangFileSystemExt * fileSystem) 125{ 126return ComPtr < IExtFileArtifactRepresentation > (new ThisType (path, fileSystem)); 127} 128 129protected : 130void * getInterface ( const Guid & uuid); 131void * getObject ( const Guid & uuid); 132 133String m_uniqueIdentity; 134String m_path; 135ComPtr < ISlangFileSystemExt > m_fileSystem; 136}; 137 138class SourceBlobWithPathInfoArtifactRepresentation : public ComBaseObject, 139public IPathArtifactRepresentation 140{ 141public : 142typedef SourceBlobWithPathInfoArtifactRepresentation ThisType; 143 144SLANG_COM_BASE_IUNKNOWN_ALL 145 146// ICastable 147SLANG_NO_THROW void * SLANG_MCALL castAs( const Guid & guid) SLANG_OVERRIDE ; 148 149// IArtifactRepresentation 150SLANG_NO_THROW SlangResult SLANG_MCALL 151createRepresentation ( const Guid & typeGuid, ICastable ** outCastable) SLANG_OVERRIDE ; 152SLANG_NO_THROW bool SLANG_MCALL exists () SLANG_OVERRIDE { return false; } 153 154// IPathArtifactRepresentation 155virtual SLANG_NO_THROW const char * SLANG_MCALL getPath () SLANG_OVERRIDE 156{ 157return m_pathInfo. getName (). getBuffer (); 158} 159virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType () SLANG_OVERRIDE 160{ 161return SLANG_PATH_TYPE_FILE ; 162} 163virtual SLANG_NO_THROW const char * SLANG_MCALL getUniqueIdentity () SLANG_OVERRIDE 164{ 165return m_pathInfo. hasUniqueIdentity () ? m_pathInfo. uniqueIdentity . getBuffer () : nullptr ; 166} 167 168SourceBlobWithPathInfoArtifactRepresentation( const PathInfo & pathInfo, ISlangBlob * sourceBlob) 169: m_pathInfo (pathInfo), m_blob (sourceBlob) 170{ 171} 172 173static ComPtr < IPathArtifactRepresentation > create ( 174const PathInfo & pathInfo, 175ISlangBlob * sourceBlob) 176{ 177return ComPtr < IPathArtifactRepresentation > (new ThisType (pathInfo, sourceBlob)); 178} 179 180protected : 181void * getInterface ( const Guid & uuid); 182void * getObject ( const Guid & uuid); 183 184PathInfo m_pathInfo; 185ComPtr < ISlangBlob > m_blob; 186}; 187 188/* This allows wrapping any object to be an artifact representation. 189 190NOTE! Only allows casting from a single guid. Passing a RefObject across an ABI boundary remains 191risky! 192*/ 193class ObjectArtifactRepresentation : public ComBaseObject, public IArtifactRepresentation 194{ 195public : 196SLANG_CLASS_GUID ( 0xb9d5af57 , 0x725b , 0x45f8 , { 0xac , 0xed , 0x18 , 0xf4 , 0xa8 , 0x4b , 0xf4 , 0x73 }) 197 198SLANG_COM_BASE_IUNKNOWN_ALL 199 200// ICastable 201SLANG_NO_THROW void * SLANG_MCALL castAs( const Guid & guid) SLANG_OVERRIDE ; 202// IArtifactRepresentation 203SLANG_NO_THROW SlangResult SLANG_MCALL 204createRepresentation ( const Guid & guid, ICastable ** outCastable) SLANG_OVERRIDE 205{ 206SLANG_UNUSED (guid); 207SLANG_UNUSED (outCastable); 208return SLANG_E_NOT_AVAILABLE ; 209} 210SLANG_NO_THROW bool SLANG_MCALL exists () SLANG_OVERRIDE { return m_object; } 211 212ObjectArtifactRepresentation( const Guid & typeGuid, RefObject * obj) 213: m_typeGuid (typeGuid), m_object (obj) 214{ 215} 216 217void * getInterface ( const Guid & uuid); 218void * getObject ( const Guid & uuid); 219 220Guid m_typeGuid; ///< Will return m_object if a cast to m_typeGuid is given 221RefPtr < RefObject > m_object; ///< The object 222}; 223 224} // namespace Slang 225 226#endif