PRISMS-PF Manual
Loading...
Searching...
No Matches
tee_stream.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2025 PRISMS Center at the University of Michigan
2// SPDX-License-Identifier: GNU Lesser General Public Version 2.1
3
4#pragma once
5
6#include <prismspf/config.h>
7
8#include <ostream>
9
11
16class TeeStream : public std::ostream
17{
18public:
19 TeeStream(std::ostream &stream1, std::ostream &stream2)
20 : std::ostream(&tee_buffer)
21 , tee_buffer(stream1, stream2)
22 {}
23
24private:
25 class TeeBuffer : public std::streambuf
26 {
27 public:
28 TeeBuffer(std::ostream &stream1, std::ostream &stream2)
31 {}
32
33 protected:
34 int
35 overflow(int character) override
36 {
37 if (character == EOF)
38 {
39 return static_cast<int>(!EOF);
40 }
41
42 const int result1 = stream1->sputc(static_cast<char_type>(character));
43 const int result2 = stream2->sputc(static_cast<char_type>(character));
44 return result1 == EOF || result2 == EOF ? EOF : character;
45 }
46
47 int
48 sync() override
49 {
50 const int result1 = stream1->pubsync();
51 const int result2 = stream2->pubsync();
52 return result1 == 0 && result2 == 0 ? 0 : -1;
53 }
54
55 private:
56 std::streambuf *stream1;
57 std::streambuf *stream2;
58 };
59
61};
62
Definition tee_stream.h:26
std::streambuf * stream1
Definition tee_stream.h:56
int sync() override
Definition tee_stream.h:48
int overflow(int character) override
Definition tee_stream.h:35
TeeBuffer(std::ostream &stream1, std::ostream &stream2)
Definition tee_stream.h:28
std::streambuf * stream2
Definition tee_stream.h:57
Combined output streams so we can output to terminal and the summary.log with a single statement.
Definition tee_stream.h:17
TeeStream(std::ostream &stream1, std::ostream &stream2)
Definition tee_stream.h:19
TeeBuffer tee_buffer
Definition tee_stream.h:60
@ Value
Use value of the variable as a criterion for refinement.
Definition grid_refiner_criterion.h:31
Definition conditional_ostreams.cc:20
Definition vectorized_operations.h:17