Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
io_bytestream.h
1#ifndef SOURCEMETA_CORE_IO_BYTESTREAM_H_
2#define SOURCEMETA_CORE_IO_BYTESTREAM_H_
3
4#ifndef SOURCEMETA_CORE_IO_EXPORT
5#include <sourcemeta/core/io_export.h>
6#endif
7
8#include <cstddef> // std::byte
9#include <cstdint> // std::uint8_t
10#include <initializer_list> // std::initializer_list
11#include <sstream> // std::istringstream, std::ostringstream
12#include <vector> // std::vector
13
14namespace sourcemeta::core {
15
16// Exporting individual members rather than the whole class avoids MSVC
17// instantiating std::basic_istringstream / std::basic_ostringstream vbase
18// destructors inside this DLL, which would otherwise clash at link time with
19// consumer translation units that use these iostream types directly
20// (LNK2005).
21// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN
22#if defined(_MSC_VER)
23#pragma warning(disable : 4251 4275)
24#endif
25
35class InputByteStream : public std::istringstream {
36public:
38 SOURCEMETA_CORE_IO_EXPORT
39 InputByteStream(std::initializer_list<std::uint8_t> bytes);
40};
41
54class OutputByteStream : public std::ostringstream {
55public:
57 SOURCEMETA_CORE_IO_EXPORT
58 auto bytes() const -> std::vector<std::byte>;
59};
60
61#if defined(_MSC_VER)
62#pragma warning(default : 4251 4275)
63#endif
64
65} // namespace sourcemeta::core
66
67#endif
SOURCEMETA_CORE_IO_EXPORT InputByteStream(std::initializer_list< std::uint8_t > bytes)
Construct the stream from the given byte values.
SOURCEMETA_CORE_IO_EXPORT auto bytes() const -> std::vector< std::byte >
The accumulated bytes.
Definition io_bytestream.h:54