P4C
The P4 Compiler
Loading...
Searching...
No Matches
nullstream.h
1
/*
2
Copyright 2013-present Barefoot Networks, Inc.
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
8
http://www.apache.org/licenses/LICENSE-2.0
9
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations 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
25
namespace
P4
{
26
27
template
<
class
cT,
class
traits = std::
char
_traits<cT>>
28
class
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
34
template
<
class
cT,
class
traits = std::
char
_traits<cT>>
35
class
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
:
42
basic_nullbuf<cT, traits>
m_sbuf;
43
};
44
45
typedef
onullstream<char>
nullstream
;
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
50
std::ostream *openFile(
const
std::filesystem::path &name,
bool
nullOnError);
51
52
}
// namespace P4
53
54
#endif
/* LIB_NULLSTREAM_H_ */
P4::basic_nullbuf
Definition
nullstream.h:28
P4::onullstream
Definition
nullstream.h:35
P4
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition
applyOptionsPragmas.cpp:24
lib
nullstream.h
Generated by
1.12.0