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(push)
24#pragma warning(disable : 4251 4275)
25#endif
26
36class InputByteStream : public std::istringstream {
37public:
39 SOURCEMETA_CORE_IO_EXPORT
40 InputByteStream(std::initializer_list<std::uint8_t> bytes);
41};
42
55class OutputByteStream : public std::ostringstream {
56public:
58 SOURCEMETA_CORE_IO_EXPORT
59 auto bytes() const -> std::vector<std::byte>;
60};
61
62#if defined(_MSC_VER)
63#pragma warning(pop)
64#endif
65
66} // namespace sourcemeta::core
67
68#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:55