summaryrefslogtreecommitdiff
path: root/source/slang-record-replay/record/output-stream.cpp
blob: 00cbf814aa19d3feed861a09f282d89807199acb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "output-stream.h"
#include "../util/record-utility.h"

namespace SlangRecord
{
    FileOutputStream::FileOutputStream(const Slang::String& fileName, bool append)
    {
        Slang::FileMode fileMode = append ? Slang::FileMode::Append : Slang::FileMode::Create;
        Slang::FileAccess fileAccess = Slang::FileAccess::Write;
        Slang::FileShare fileShare = Slang::FileShare::None;

        SlangResult res = m_fileStream.init(fileName, fileMode, fileAccess, fileShare);

        if (res != SLANG_OK)
        {
            SlangRecord::slangRecordLog(SlangRecord::LogLevel::Error, "Failed to open file %s\n", fileName.getBuffer());
            std::abort();
        }
    }

    FileOutputStream::~FileOutputStream()
    {
        m_fileStream.close();
    }

    void FileOutputStream::write(const void* data, size_t len)
    {
        SLANG_RECORD_CHECK(m_fileStream.write(data, len));
    }

    MemoryStream::MemoryStream()
        : m_memoryStream(Slang::FileAccess::Write)
    { }

    void FileOutputStream::flush()
    {
        SLANG_RECORD_CHECK(m_fileStream.flush());
    }

    void MemoryStream::write(const void* data, size_t len)
    {
        SLANG_RECORD_CHECK(m_memoryStream.write(data, len));
    }

    void MemoryStream::flush()
    {
        // This call will reset the underlying buffer to size 0,
        // and reset the write position to 0.
        m_memoryStream.setContent(nullptr, 0);
    }
}