diff options
-rw-r--r-- | .github/workflows/ci.yml (renamed from .github/workflows/macos-ci.yml) | 35 | ||||
-rw-r--r-- | .github/workflows/windows-ci.yml | 41 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | include/cru/common/Exception.hpp | 3 | ||||
-rw-r--r-- | include/cru/common/io/MemoryStream.hpp | 11 | ||||
-rw-r--r-- | src/common/io/MemoryStream.cpp | 6 |
6 files changed, 48 insertions, 50 deletions
diff --git a/.github/workflows/macos-ci.yml b/.github/workflows/ci.yml index f46cd156..670a26ca 100644 --- a/.github/workflows/macos-ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,19 @@ -name: macOS CI +name: CI on: push: - branches: [master] + branches: [main] paths-ignore: - "docs/**" - "**/README.md" pull_request: - branches: [master] + branches: [main] paths-ignore: - "docs/**" - "**/README.md" jobs: - build: + macos-build: name: Build runs-on: macos-latest @@ -40,3 +40,30 @@ jobs: working-directory: build run: | ctest -C Debug -T test --output-on-failure + + windows-build: + name: Build + runs-on: windows-latest + + steps: + - uses: actions/checkout@v2 + + - name: Restore Cache + uses: actions/cache@v2 + with: + path: ~/AppData/Local/vcpkg/archives + key: vcpkg-${{ runner.os }} + + - name: Setup Ninja + uses: ashutoshvarma/setup-ninja@master + with: + version: 1.10.2 + + - name: Run build script + shell: pwsh + run: | + . ./tools/Use-VC.ps1 + Use-VC + mkdir build && cd build + cmake .. -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug + ninja all diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml deleted file mode 100644 index 4a3be7cf..00000000 --- a/.github/workflows/windows-ci.yml +++ /dev/null @@ -1,41 +0,0 @@ -name: Windows CI - -on: - push: - branches: [master] - paths-ignore: - - "docs/**" - - "**/README.md" - pull_request: - branches: [master] - paths-ignore: - - "docs/**" - - "**/README.md" - -jobs: - build: - name: Build - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - name: Restore Cache - uses: actions/cache@v2 - with: - path: ~/AppData/Local/vcpkg/archives - key: vcpkg-${{ runner.os }} - - - name: Setup Ninja - uses: ashutoshvarma/setup-ninja@master - with: - version: 1.10.2 - - - name: Run build script - shell: pwsh - run: | - . ./tools/Use-VC.ps1 - Use-VC - mkdir build && cd build - cmake .. -G Ninja -DCMAKE_BUILD_TYPE:STRING=Debug - ninja all @@ -1,6 +1,6 @@ # CruUI -[](https://github.com/crupest/cru/actions/workflows/macos-ci.yml) +[](https://github.com/crupest/cru/actions/workflows/ci.yml) ## overview diff --git a/include/cru/common/Exception.hpp b/include/cru/common/Exception.hpp index e8395178..cb35469c 100644 --- a/include/cru/common/Exception.hpp +++ b/include/cru/common/Exception.hpp @@ -2,6 +2,9 @@ #include "String.hpp" namespace cru { +#ifdef _MSC_VER +#pragma warning(disable : 4275) +#endif class CRU_BASE_API Exception : public std::exception { public: Exception(); diff --git a/include/cru/common/io/MemoryStream.hpp b/include/cru/common/io/MemoryStream.hpp index 070ef2c6..a1be1354 100644 --- a/include/cru/common/io/MemoryStream.hpp +++ b/include/cru/common/io/MemoryStream.hpp @@ -2,16 +2,19 @@ #include "Stream.hpp" +#include <functional> + namespace cru::io { class CRU_BASE_API MemoryStream : public Stream { public: MemoryStream() = default; - MemoryStream(std::byte* buffer, Index size, bool read_only = false, - bool auto_release = false) + MemoryStream( + std::byte* buffer, Index size, bool read_only = false, + std::function<void(std::byte* buffer, Index size)> release_func = {}) : buffer_(buffer), size_(size), read_only_(read_only), - auto_release_(auto_release) {} + release_func_(std::move(release_func)) {} CRU_DELETE_COPY(MemoryStream) CRU_DELETE_MOVE(MemoryStream) @@ -33,7 +36,7 @@ class CRU_BASE_API MemoryStream : public Stream { std::byte* buffer_ = nullptr; Index size_ = 0; Index position_ = 0; - bool auto_release_ = false; bool read_only_ = false; + std::function<void(std::byte* buffer, Index size)> release_func_; }; } // namespace cru::io diff --git a/src/common/io/MemoryStream.cpp b/src/common/io/MemoryStream.cpp index bd561f5d..481ed962 100644 --- a/src/common/io/MemoryStream.cpp +++ b/src/common/io/MemoryStream.cpp @@ -1,6 +1,12 @@ #include "cru/common/io/MemoryStream.hpp" namespace cru::io { +MemoryStream::~MemoryStream() { + if (release_func_) { + release_func_(buffer_, size_); + } +} + bool MemoryStream::CanSeek() { return true; } Index MemoryStream::Tell() { return position_; } |