Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
conditional_ostream.h
1 // ---------------------------------------------------------------------
2 // @f$Id: conditional_ostream.h 30036 2013-07-18 16:55:32Z maier @f$
3 //
4 // Copyright (C) 2004 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__conditional_ostream_h
18 #define __deal2__conditional_ostream_h
19 
20 #include <deal.II/base/config.h>
21 
22 #include <ostream>
23 
24 DEAL_II_NAMESPACE_OPEN
25 
26 
87 {
88 public:
96  ConditionalOStream (std::ostream &stream,
97  const bool active = true);
98 
109  void set_condition (const bool active);
110 
114  bool is_active() const;
115 
120  std::ostream &get_stream () const;
121 
130  template <typename T>
131  const ConditionalOStream &
132  operator << (const T &t) const;
133 
148  const ConditionalOStream &
149  operator<< (std::ostream& (*p) (std::ostream &)) const;
150 
151 private:
156  std::ostream &output_stream;
157 
163 };
164 
165 
166 // --------------------------- inline and template functions -----------
167 
168 template <class T>
169 inline
170 const ConditionalOStream &
172 {
173  if (active_flag == true)
174  output_stream << t;
175 
176  return *this;
177 }
178 
179 
180 inline
181 const ConditionalOStream &
182 ConditionalOStream::operator<< (std::ostream& (*p) (std::ostream &)) const
183 {
184  if (active_flag == true)
185  output_stream << p;
186 
187  return *this;
188 }
189 
190 
191 inline
192 std::ostream &
194 {
195  return output_stream;
196 }
197 
198 
199 DEAL_II_NAMESPACE_CLOSE
200 
201 #endif
std::ostream & output_stream
ConditionalOStream(std::ostream &stream, const bool active=true)
void set_condition(const bool active)
std::ostream & get_stream() const
const ConditionalOStream & operator<<(const T &t) const
bool is_active() const