P4C
The P4 Compiler
Loading...
Searching...
No Matches
nullstream.h
1/*
2Copyright 2013-present Barefoot Networks, Inc.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef LIB_NULLSTREAM_H_
18#define LIB_NULLSTREAM_H_
19
20#include <filesystem>
21#include <iostream>
22#include <ostream>
23#include <streambuf>
24
25namespace P4 {
26
27template <class cT, class traits = std::char_traits<cT>>
28class basic_nullbuf final : public std::basic_streambuf<cT, traits> {
29 typename traits::int_type overflow(typename traits::int_type c) {
30 return traits::not_eof(c); // indicate success
31 }
32};
33
34template <class cT, class traits = std::char_traits<cT>>
35class onullstream final : public std::basic_ostream<cT, traits> {
36 public:
37 onullstream() : std::basic_ios<cT, traits>(&m_sbuf), std::basic_ostream<cT, traits>(&m_sbuf) {
38 this->init(&m_sbuf);
39 }
40
41 private:
43};
44
46
47// If nullOnError is 'true', on error a nullstream is returned
48// otherwise a nullptr is returned
49// FIXME: This should return unique_ptr instead to track lifetime
50std::ostream *openFile(const std::filesystem::path &name, bool nullOnError);
51
52} // namespace P4
53
54#endif /* LIB_NULLSTREAM_H_ */
Definition nullstream.h:28
Definition nullstream.h:35
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24