include/deal.II/base/conditional_ostream.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: conditional_ostream.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //---------------------------------------------------------------------------
00012 #ifndef __deal2__conditional_ostream_h
00013 #define __deal2__conditional_ostream_h
00014 
00015 #include <deal.II/base/config.h>
00016 
00017 #ifdef HAVE_STD_OSTREAM_HEADER
00018 #  include <ostream>
00019 #else
00020 #  include <iostream>
00021 #endif
00022 
00023 DEAL_II_NAMESPACE_OPEN
00024 
00025 
00085 class ConditionalOStream
00086 {
00087   public:
00095     ConditionalOStream (std::ostream &stream,
00096                         const bool    active = true);
00097 
00108     void set_condition (const bool active);
00109 
00113     bool is_active() const;
00114 
00119     std::ostream & get_stream () const;
00120 
00129     template <typename T>
00130     const ConditionalOStream &
00131     operator << (const T &t) const;
00132 
00147     const ConditionalOStream &
00148     operator<< (std::ostream& (*p) (std::ostream&)) const;
00149 
00150   private:
00155     std::ostream  &output_stream;
00156 
00161     bool active_flag;
00162 };
00163 
00164 
00165 // --------------------------- inline and template functions -----------
00166 
00167 template <class T>
00168 inline
00169 const ConditionalOStream &
00170 ConditionalOStream::operator<< (const T& t) const
00171 {
00172   if (active_flag == true)
00173     output_stream << t;
00174 
00175   return *this;
00176 }
00177 
00178 
00179 inline
00180 const ConditionalOStream &
00181 ConditionalOStream::operator<< (std::ostream& (*p) (std::ostream&)) const
00182 {
00183   if (active_flag == true)
00184     output_stream << p;
00185 
00186   return *this;
00187 }
00188 
00189 
00190 inline
00191 std::ostream &
00192 ConditionalOStream::get_stream () const
00193 {
00194   return output_stream;
00195 }
00196 
00197 
00198 DEAL_II_NAMESPACE_CLOSE
00199 
00200 #endif
00201 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Tue May 22 2012 12:06:04 by doxygen 1.7.3