yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

Ellie Hermaszewskaformatf65d756bf

master
7.0 KiB226 linesraw
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:
19    typedef OSFileArtifactRepresentation ThisType;
20
21    SLANG_COM_BASE_IUNKNOWN_ALL
22
23    // ICastable
24    SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
25
26    // IArtifactRepresentation
27    SLANG_NO_THROW SlangResult SLANG_MCALL
28    createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE;
29    SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE;
30
31    // IPathArtifactRepresentation
32    virtual SLANG_NO_THROW const char* SLANG_MCALL getPath() SLANG_OVERRIDE
33    {
34        return m_path.getBuffer();
35    }
36    virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType() SLANG_OVERRIDE
37    {
38        return SLANG_PATH_TYPE_FILE;
39    }
40    virtual SLANG_NO_THROW const char* SLANG_MCALL getUniqueIdentity() SLANG_OVERRIDE;
41
42    // IOSFileArtifactRepresentation
43    virtual SLANG_NO_THROW Kind SLANG_MCALL getKind() SLANG_OVERRIDE { return m_kind; }
44    virtual SLANG_NO_THROW void SLANG_MCALL disown() SLANG_OVERRIDE;
45    virtual SLANG_NO_THROW IOSFileArtifactRepresentation* SLANG_MCALL getLockFile() SLANG_OVERRIDE
46    {
47        return m_lockFile;
48    }
49
50    OSFileArtifactRepresentation(
51        Kind kind,
52        const UnownedStringSlice& path,
53        IOSFileArtifactRepresentation* lockFile)
54        : m_kind(kind), m_lockFile(lockFile), m_path(path)
55    {
56    }
57
58    ~OSFileArtifactRepresentation();
59
60    static ComPtr<IOSFileArtifactRepresentation> create(
61        Kind kind,
62        const UnownedStringSlice& path,
63        IOSFileArtifactRepresentation* lockFile)
64    {
65        return ComPtr<IOSFileArtifactRepresentation>(new ThisType(kind, path, lockFile));
66    }
67
68protected:
69    void* getInterface(const Guid& uuid);
70    void* getObject(const Guid& uuid);
71
72    /// True if the file is owned
73    bool _isOwned() const { return Index(m_kind) >= Index(Kind::Owned); }
74
75    static ISlangMutableFileSystem* _getFileSystem();
76
77    Kind m_kind;
78    String m_path;
79    String m_uniqueIdentity;
80
81    ComPtr<IOSFileArtifactRepresentation> m_lockFile;
82    ComPtr<ISlangMutableFileSystem> m_fileSystem;
83};
84
85class ExtFileArtifactRepresentation : public ComBaseObject, public IExtFileArtifactRepresentation
86{
87public:
88    typedef ExtFileArtifactRepresentation ThisType;
89
90    SLANG_COM_BASE_IUNKNOWN_ALL
91
92    // ICastable
93    SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
94
95    // IArtifactRepresentation
96    SLANG_NO_THROW SlangResult SLANG_MCALL
97    createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE;
98    SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE;
99
100    // IPathArtifactRepresentation
101    virtual SLANG_NO_THROW const char* SLANG_MCALL getPath() SLANG_OVERRIDE
102    {
103        return m_path.getBuffer();
104    }
105    virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType() SLANG_OVERRIDE
106    {
107        return SLANG_PATH_TYPE_FILE;
108    }
109    virtual SLANG_NO_THROW const char* SLANG_MCALL getUniqueIdentity() SLANG_OVERRIDE;
110
111    // IExtFileArtifactRepresentation
112    virtual SLANG_NO_THROW ISlangFileSystemExt* SLANG_MCALL getFileSystem() SLANG_OVERRIDE
113    {
114        return m_fileSystem;
115    }
116
117    ExtFileArtifactRepresentation(const UnownedStringSlice& path, ISlangFileSystemExt* fileSystem)
118        : m_path(path), m_fileSystem(fileSystem)
119    {
120    }
121
122    static ComPtr<IExtFileArtifactRepresentation> create(
123        const UnownedStringSlice& path,
124        ISlangFileSystemExt* fileSystem)
125    {
126        return ComPtr<IExtFileArtifactRepresentation>(new ThisType(path, fileSystem));
127    }
128
129protected:
130    void* getInterface(const Guid& uuid);
131    void* getObject(const Guid& uuid);
132
133    String m_uniqueIdentity;
134    String m_path;
135    ComPtr<ISlangFileSystemExt> m_fileSystem;
136};
137
138class SourceBlobWithPathInfoArtifactRepresentation : public ComBaseObject,
139                                                     public IPathArtifactRepresentation
140{
141public:
142    typedef SourceBlobWithPathInfoArtifactRepresentation ThisType;
143
144    SLANG_COM_BASE_IUNKNOWN_ALL
145
146    // ICastable
147    SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
148
149    // IArtifactRepresentation
150    SLANG_NO_THROW SlangResult SLANG_MCALL
151    createRepresentation(const Guid& typeGuid, ICastable** outCastable) SLANG_OVERRIDE;
152    SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE { return false; }
153
154    // IPathArtifactRepresentation
155    virtual SLANG_NO_THROW const char* SLANG_MCALL getPath() SLANG_OVERRIDE
156    {
157        return m_pathInfo.getName().getBuffer();
158    }
159    virtual SLANG_NO_THROW SlangPathType SLANG_MCALL getPathType() SLANG_OVERRIDE
160    {
161        return SLANG_PATH_TYPE_FILE;
162    }
163    virtual SLANG_NO_THROW const char* SLANG_MCALL getUniqueIdentity() SLANG_OVERRIDE
164    {
165        return m_pathInfo.hasUniqueIdentity() ? m_pathInfo.uniqueIdentity.getBuffer() : nullptr;
166    }
167
168    SourceBlobWithPathInfoArtifactRepresentation(const PathInfo& pathInfo, ISlangBlob* sourceBlob)
169        : m_pathInfo(pathInfo), m_blob(sourceBlob)
170    {
171    }
172
173    static ComPtr<IPathArtifactRepresentation> create(
174        const PathInfo& pathInfo,
175        ISlangBlob* sourceBlob)
176    {
177        return ComPtr<IPathArtifactRepresentation>(new ThisType(pathInfo, sourceBlob));
178    }
179
180protected:
181    void* getInterface(const Guid& uuid);
182    void* getObject(const Guid& uuid);
183
184    PathInfo m_pathInfo;
185    ComPtr<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:
196    SLANG_CLASS_GUID(0xb9d5af57, 0x725b, 0x45f8, {0xac, 0xed, 0x18, 0xf4, 0xa8, 0x4b, 0xf4, 0x73})
197
198    SLANG_COM_BASE_IUNKNOWN_ALL
199
200    // ICastable
201    SLANG_NO_THROW void* SLANG_MCALL castAs(const Guid& guid) SLANG_OVERRIDE;
202    // IArtifactRepresentation
203    SLANG_NO_THROW SlangResult SLANG_MCALL
204    createRepresentation(const Guid& guid, ICastable** outCastable) SLANG_OVERRIDE
205    {
206        SLANG_UNUSED(guid);
207        SLANG_UNUSED(outCastable);
208        return SLANG_E_NOT_AVAILABLE;
209    }
210    SLANG_NO_THROW bool SLANG_MCALL exists() SLANG_OVERRIDE { return m_object; }
211
212    ObjectArtifactRepresentation(const Guid& typeGuid, RefObject* obj)
213        : m_typeGuid(typeGuid), m_object(obj)
214    {
215    }
216
217    void* getInterface(const Guid& uuid);
218    void* getObject(const Guid& uuid);
219
220    Guid m_typeGuid;            ///< Will return m_object if a cast to m_typeGuid is given
221    RefPtr<RefObject> m_object; ///< The object
222};
223
224} // namespace Slang
225
226#endif