diff options
Diffstat (limited to 'source/core')
| -rw-r--r-- | source/core/slang-castable-list-impl.cpp | 19 | ||||
| -rw-r--r-- | source/core/slang-castable-list-impl.h | 6 | ||||
| -rw-r--r-- | source/core/slang-io.cpp | 16 | ||||
| -rw-r--r-- | source/core/slang-io.h | 3 |
4 files changed, 43 insertions, 1 deletions
diff --git a/source/core/slang-castable-list-impl.cpp b/source/core/slang-castable-list-impl.cpp index 56f8c7cae..dcc58e37b 100644 --- a/source/core/slang-castable-list-impl.cpp +++ b/source/core/slang-castable-list-impl.cpp @@ -3,7 +3,24 @@ namespace Slang { - /* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! CastableUtil !!!!!!!!!!!!!!!!!!!!!!!!!!! */ + +/* static */ComPtr<ICastable> CastableUtil::getCastable(ISlangUnknown* unk) +{ + SLANG_ASSERT(unk); + ComPtr<ICastable> castable; + if (SLANG_SUCCEEDED(unk->queryInterface(ICastable::getTypeGuid(), (void**)castable.writeRef()))) + { + SLANG_ASSERT(castable); + } + else + { + castable = new UnknownCastableAdapter(unk); + } + return castable; +} + +/* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! UnknownCastableAdapter !!!!!!!!!!!!!!!!!!!!!!!!!!! */ void* UnknownCastableAdapter::castAs(const Guid& guid) { diff --git a/source/core/slang-castable-list-impl.h b/source/core/slang-castable-list-impl.h index b578e8de4..2ce124ce7 100644 --- a/source/core/slang-castable-list-impl.h +++ b/source/core/slang-castable-list-impl.h @@ -79,6 +79,12 @@ protected: List<ICastable*> m_list; }; +struct CastableUtil +{ + /// Given an unk return as an unk + static ComPtr<ICastable> getCastable(ISlangUnknown* unk); +}; + } // namespace Slang #endif diff --git a/source/core/slang-io.cpp b/source/core/slang-io.cpp index 17cd60160..a6e97057b 100644 --- a/source/core/slang-io.cpp +++ b/source/core/slang-io.cpp @@ -1,3 +1,5 @@ +#define _CRT_SECURE_NO_WARNINGS 1 + #include "slang-io.h" #include "slang-exception.h" @@ -925,6 +927,20 @@ namespace Slang return SLANG_OK; } + /* static */SlangResult File::writeNativeText(const String& path, const void* data, size_t size) + { + FILE* file = fopen(path.getBuffer(), "w"); + if (!file) + { + return SLANG_FAIL; + } + + const auto count = fwrite(data, size, 1, file); + fclose(file); + + return (count == 1) ? SLANG_OK : SLANG_FAIL; + } + String URI::getPath() const { Index startIndex = uri.indexOf("://"); diff --git a/source/core/slang-io.h b/source/core/slang-io.h index 4de246289..aa4ccae42 100644 --- a/source/core/slang-io.h +++ b/source/core/slang-io.h @@ -21,6 +21,9 @@ namespace Slang static SlangResult writeAllText(const String& fileName, const String& text); + /// Write as text in native form for the target (so typically may change line endings ) + static SlangResult writeNativeText(const String& filename, const void* data, size_t size); + static SlangResult writeAllBytes(const String& fileName, const void* data, size_t size); static SlangResult remove(const String& fileName); |
