summaryrefslogtreecommitdiffstats
path: root/source/slang-record-replay/record/output-stream.h
blob: e0eb95ed22eae5b6254b6c8e32fd9caf86650ae4 (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
#ifndef OUTPUT_STREAM_H
#define OUTPUT_STREAM_H

#include "../../core/slang-stream.h"
#include "../../core/slang-string.h"

namespace SlangRecord
{
class OutputStream : public Slang::RefObject
{
public:
    virtual ~OutputStream() {}
    virtual void write(const void* data, size_t len) = 0;
    virtual void flush() {}
};

class FileOutputStream : public OutputStream
{
public:
    FileOutputStream(const Slang::String& fileName, bool append = false);
    virtual ~FileOutputStream() override;
    virtual void write(const void* data, size_t len) override;
    virtual void flush() override;

private:
    Slang::FileStream m_fileStream;
};

// The reason we inherit from OwnedMemoryStream instead of declaring it
// as a member is because OwnedMemoryStream lacks some of the functionality
// of operating on the underlying buffer directly.
class MemoryStream : public OutputStream
{
public:
    MemoryStream();
    virtual ~MemoryStream() {}
    virtual void write(const void* data, size_t len) override;
    virtual void flush() override;
    const void* getData() { return m_memoryStream.getContents().getBuffer(); }
    size_t getSizeInBytes() { return m_memoryStream.getContents().getCount(); }

private:
    Slang::OwnedMemoryStream m_memoryStream;
};
} // namespace SlangRecord
#endif // OUTPUT_STREAM_H