OGS
FlushStdoutGuard.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
4#pragma once
5
6namespace
7{
12{
13public:
15 explicit FlushStdoutGuard(bool const flush) : _flush(flush)
16 {
17 if (!flush)
18 {
19 return;
20 }
21
22 std::cout << std::flush;
23 }
24
27 {
28 if (!_flush)
29 {
30 return;
31 }
32
33 using namespace pybind11::literals;
34 pybind11::print("end"_a = "", "flush"_a = true);
35 }
36
37private:
39 const bool _flush;
40};
41} // anonymous namespace
~FlushStdoutGuard()
Optionally flushes Python's stdout after running Python code.
FlushStdoutGuard(bool const flush)
Optionally flushes C++ stdout before running Python code.