Reference documentation for deal.II version Git 5f32ffafa8 2019-10-18 00:26:50 -0600
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
conditional_ostream.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_conditional_ostream_h
17 #define dealii_conditional_ostream_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <ostream>
22 
23 DEAL_II_NAMESPACE_OPEN
24 
25 
82 {
83 public:
89  ConditionalOStream(std::ostream &stream, const bool active = true);
90 
96  void
97  set_condition(const bool active);
98 
102  bool
103  is_active() const;
104 
108  std::ostream &
109  get_stream() const;
110 
116  template <typename T>
117  const ConditionalOStream &
118  operator<<(const T &t) const;
119 
129  const ConditionalOStream &
130  operator<<(std::ostream &(*p)(std::ostream &)) const;
131 
132 private:
136  std::ostream &output_stream;
137 
142 };
143 
144 
145 // --------------------------- inline and template functions -----------
146 
147 template <class T>
148 inline const ConditionalOStream &
150 {
151  if (active_flag == true)
152  output_stream << t;
153 
154  return *this;
155 }
156 
157 
158 inline const ConditionalOStream &
159 ConditionalOStream::operator<<(std::ostream &(*p)(std::ostream &)) const
160 {
161  if (active_flag == true)
162  output_stream << p;
163 
164  return *this;
165 }
166 
167 
168 inline std::ostream &
170 {
171  return output_stream;
172 }
173 
174 
175 DEAL_II_NAMESPACE_CLOSE
176 
177 #endif
std::ostream & output_stream
ConditionalOStream(std::ostream &stream, const bool active=true)
void set_condition(const bool active)
const ConditionalOStream & operator<<(const T &t) const
std::ostream & get_stream() const