P4C
The P4 Compiler
Loading...
Searching...
No Matches
fdstream.h
1
17
18#ifndef LIB_FDSTREAM_H_
19#define LIB_FDSTREAM_H_
20
21#include <array>
22#include <cstddef>
23#include <cstdio>
24#include <iostream>
25#include <streambuf>
26#include <variant>
27
28namespace P4 {
29
63class FdStream final : public std::iostream {
64 class Buffer final : public std::streambuf {
65 static constexpr std::size_t BUFFER_SIZE = 8192;
66 std::variant<int, FILE *> source;
67 std::array<char, BUFFER_SIZE> inputBuffer{};
68 std::array<char, BUFFER_SIZE> outputBuffer{};
69 int stdioReadError = 0;
70 bool stdioOutputPending = false;
71
72 std::size_t readStdio(FILE *file);
73
74 protected:
75 int_type underflow() override;
76 int_type overflow(int_type c) override;
77 int sync() override;
78
79 public:
80 explicit Buffer(int fd);
81 explicit Buffer(FILE *file);
82 } buffer;
83
84 public:
85 explicit FdStream(int fd);
86 explicit FdStream(FILE *file);
87 ~FdStream() override;
88
89 FdStream(const FdStream &) = delete;
90 FdStream &operator=(const FdStream &) = delete;
91 FdStream(FdStream &&) = delete;
92 FdStream &operator=(FdStream &&) = delete;
93};
94
95} // namespace P4
96
97#endif // LIB_FDSTREAM_H_
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13