File conditionalstream.h
File List > code_source > templat > include > TempLat > util > conditionaloutput > conditionalstream.h
Go to the documentation of this file
#ifndef TEMPLAT_UTIL_CONDITIONALOUTPUT_CONDITIONALSTREAM_H
#define TEMPLAT_UTIL_CONDITIONALOUTPUT_CONDITIONALSTREAM_H
/* This file is part of TempLat, available at https://cosmolattice.github.io/templat .
Copyright 2021-2026 The TempLat authors, see AUTHORS.md.
Released under the MIT license, see LICENSE.md. */
// File info: Main contributor(s): Wessel Valkenburg, Year: 2019
#include <sstream>
namespace TempLat
{
class ConditionalStream
{
public:
// Put public methods here. These should change very little over time.
ConditionalStream(std::ostream &stream_, bool enabled_) : stream(stream_), enabled(enabled_) {}
template <typename T> ConditionalStream &operator<<(const T &t)
{
if (enabled) {
stream << t;
}
return *this;
}
void Enable() { enabled = true; }
void Disable() { enabled = false; }
private:
/* Put all member variables and private methods here. These may change arbitrarily. */
std::ostream &stream;
bool enabled;
};
} // namespace TempLat
#endif