P4C
The P4 Compiler
Loading...
Searching...
No Matches
nullstream.h
1/*
2 * SPDX-FileCopyrightText: 2013 Barefoot Networks, Inc.
3 * Copyright 2013-present Barefoot Networks, Inc.
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
8#ifndef LIB_NULLSTREAM_H_
9#define LIB_NULLSTREAM_H_
10
11#include <filesystem>
12#include <iostream>
13#include <memory>
14#include <ostream>
15#include <streambuf>
16
17namespace P4 {
18
19template <class cT, class traits = std::char_traits<cT>>
20class basic_nullbuf final : public std::basic_streambuf<cT, traits> {
21 typename traits::int_type overflow(typename traits::int_type c) {
22 return traits::not_eof(c); // indicate success
23 }
24};
25
26template <class cT, class traits = std::char_traits<cT>>
27class onullstream final : public std::basic_ostream<cT, traits> {
28 public:
29 onullstream() : std::basic_ios<cT, traits>(&m_sbuf), std::basic_ostream<cT, traits>(&m_sbuf) {
30 this->init(&m_sbuf);
31 }
32
33 private:
35};
36
37typedef onullstream<char> nullstream;
38
39// If nullOnError is 'true', on error a nullstream is returned
40// otherwise a nullptr is returned
41std::unique_ptr<std::ostream> openFile(const std::filesystem::path &name, bool nullOnError);
42
43} // namespace P4
44
45#endif /* LIB_NULLSTREAM_H_ */
Definition nullstream.h:20
Definition nullstream.h:27
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13