Reference documentation for deal.II version 8.5.1
conditional_ostream.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2004 - 2015 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 at
12 // the top level of the deal.II distribution.
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 
84 {
85 public:
91  ConditionalOStream (std::ostream &stream,
92  const bool active = true);
93 
99  void set_condition (const bool active);
100 
104  bool is_active() const;
105 
109  std::ostream &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
149 const ConditionalOStream &
151 {
152  if (active_flag == true)
153  output_stream << t;
154 
155  return *this;
156 }
157 
158 
159 inline
160 const ConditionalOStream &
161 ConditionalOStream::operator<< (std::ostream& (*p) (std::ostream &)) const
162 {
163  if (active_flag == true)
164  output_stream << p;
165 
166  return *this;
167 }
168 
169 
170 inline
171 std::ostream &
173 {
174  return output_stream;
175 }
176 
177 
178 DEAL_II_NAMESPACE_CLOSE
179 
180 #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