/usr/include/deal.II/base/conditional_ostream.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | //---------------------------------------------------------------------------
// $Id: conditional_ostream.h 21358 2010-06-24 23:38:14Z bangerth $
// Version: $Name$
//
// Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__conditional_ostream_h
#define __deal2__conditional_ostream_h
#include <base/config.h>
#ifdef HAVE_STD_OSTREAM_HEADER
# include <ostream>
#else
# include <iostream>
#endif
DEAL_II_NAMESPACE_OPEN
/**
* A class that allows printing to an output stream, e.g. @p std::cout,
* depending on the ConditionalOStream object being active (default)
* or not. The condition of this object can be changed by
* set_condition() and in the constructor. This class is used in the
* step-17, step-18,
* step-33, and step-35
* tutorial programs.
*
* This class is mostly useful in parallel computations. Ordinarily, you would
* use @p std::cout to print messages like what the program is presently
* doing, or the number of degrees of freedom in each step. However, in
* parallel programs, this means that each of the MPI processes write to the
* screen, which yields many repetitions of the same text. To avoid it, one
* would have to have a designated process, say the one with MPI process
* number zero, do the output, and guard each write statement with an
* if-condition. This becomes cumbersome and clutters up the code. Rather than
* doing so, the present class can be used: objects of its type act just like
* a standard output stream, but they only print something based on a
* condition that can be set to, for example, <tt>mpi_process==0</tt>, so that
* only one process has a true condition and in all other processes writes to
* this object just disappear in nirvana.
*
* The usual usage of this class is as follows:
*
* @code
* ConditionalOStream pout(std::cout, this_mpi_process==0);
*
* // all processes print following
* // information to standard output
* std::cout << "Reading parameter file on process "
* << this_mpi_process << std::endl;
*
* // following is printed by
* // process 0 only
* pout << "Solving ..." << std::endl;
* solve();
* pout << "done" << std::endl;
* @endcode
*
* Here, `Reading parameter file on process xy' is printed by each
* process separately. In contrast to that, `Solving ...' and `done'
* is printed to standard output only once, namely by process 0.
*
* This class is not derived from ostream. Therefore
* @code
* system_matrix.print_formatted(pout);
* @endcode
* is <em>not</em> possible. Instead use the is_active() funtion for a
* work-around:
*
* @code
* if (pout.is_active())
* system_matrix.print_formatted(cout);
* @endcode
*
* @ingroup textoutput
* @author Ralf Hartmann, Wolfgang Bangerth, 2004
*/
class ConditionalOStream
{
public:
/**
* Constructor. Set the stream to which
* we want to write, and the condition
* based on which writes are actually
* forwarded. Per default the condition
* of an object is active.
*/
ConditionalOStream (std::ostream &stream,
const bool active = true);
/**
* Depending on the
* <tt>active</tt> flag set the
* condition of this stream to
* active (true) or non-active
* (false). An object of this
* class prints to <tt>cout</tt>
* if and only if its condition
* is active.
*/
void set_condition (const bool active);
/**
* Return the condition of the object.
*/
bool is_active() const;
/**
* Output a constant something through
* this stream. This function must be @p
* const so that member objects of this
* type can also be used from @p const
* member functions of the surrounding
* class.
*/
template <typename T>
const ConditionalOStream &
operator << (const T &t) const;
/**
* Treat ostream manipulators. This
* function must be @p const so that
* member objects of this type can also
* be used from @p const member functions
* of the surrounding class.
*
* Note that compilers want to see this
* treated differently from the general
* template above since functions like @p
* std::endl are actually overloaded and
* can't be bound directly to a template
* type.
*/
const ConditionalOStream &
operator<< (std::ostream& (*p) (std::ostream&)) const;
private:
/**
* Reference to the stream we
* want to write to.
*/
std::ostream &output_stream;
/**
* Stores the actual condition
* the object is in.
*/
bool active_flag;
};
// --------------------------- inline and template functions -----------
template <class T>
inline
const ConditionalOStream &
ConditionalOStream::operator<< (const T& t) const
{
if (active_flag == true)
output_stream << t;
return *this;
}
inline
const ConditionalOStream &
ConditionalOStream::operator<< (std::ostream& (*p) (std::ostream&)) const
{
if (active_flag == true)
output_stream << p;
return *this;
}
DEAL_II_NAMESPACE_CLOSE
#endif
|