TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
debug_stream.hpp
Go to the documentation of this file.
1// Copyright (c) 2014-2018 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2014-2018 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2018 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Olivier Parcollet, Nils Wentzell
19
24
25#pragma once
26
27#include <functional>
28#include <ostream>
29
30namespace triqs::utility {
31
44 std::ostream *out; // NOLINT
45 std::function<bool()> condition;
46
47 public:
54 debug_stream(std::ostream *out_, std::function<bool()> condition) : out(out_), condition(condition) {}
55
60 debug_stream(std::ostream *out_) : out(out_) {}
61
69 template <class T> debug_stream &operator<<([[maybe_unused]] T const &x) {
70#ifdef TRIQS_DEBUG
71 if (condition && condition()) (*out) << x;
72#endif
73 return *this;
74 }
75
77 using CoutType = std::basic_ostream<char, std::char_traits<char>>;
78
81
88 debug_stream &operator<<([[maybe_unused]] StandardEndLine manip) {
89#ifdef TRIQS_DEBUG
90 if (condition && condition()) manip(*out);
91#endif
92 return *this;
93 }
94 };
95
96} // namespace triqs::utility
debug_stream & operator<<(T const &x)
Write an object to the underlying ostream if the condition() holds and TRIQS_DEBUG is defined.
debug_stream & operator<<(StandardEndLine manip)
Overload of operator<<() that accepts manipulators like std::endl.
debug_stream(std::ostream *out_)
Construct a debug stream without a condition.
debug_stream(std::ostream *out_, std::function< bool()> condition)
Construct a debug stream with a condition predicate.
CoutType &(*)(CoutType &) StandardEndLine
Type of standard manipulators like std::endl.
std::basic_ostream< char, std::char_traits< char > > CoutType
Output stream type.