DFT-EFE
 
Loading...
Searching...
No Matches
dftefe::utils::ConditionalOStream Class Reference

Provides an interface to print based on whether a certain condition is met or not. Typical use cases include: (a) printing based on different verbosity level (b) printing only from a certain processor while running in parallel. More...

#include <ConditionalOStream.h>

Public Member Functions

 ConditionalOStream (std::ostream &stream, const bool active=true)
 Constructor. More...
 
void setCondition (const bool active)
 Function to set the condition for printing to the output stream associated with this object. More...
 
bool isActive () const
 Function that returns true if printing to the output stream associated with this object is allowed. More...
 
std::ostream & getOStream () const
 Function that returns the underlying ostream object associated with this object. More...
 
template<typename T >
const ConditionalOStreamoperator<< (const T &t) const
 Overload the insertion or << operator. More...
 
const ConditionalOStreamoperator<< (std::ostream &(*p)(std::ostream &)) const
 Overload the insertion or << operator which takes an input function pointer to a manipulator (e.g., std::endl, std::ends, std::flush, etc). See https://cplusplus.com/reference/ostream/ostream/operator%3C%3C/ for a list of manipulators. More...
 

Private Attributes

std::ostream & d_outputStream
 
bool d_activeFlag
 

Detailed Description

Provides an interface to print based on whether a certain condition is met or not. Typical use cases include: (a) printing based on different verbosity level (b) printing only from a certain processor while running in parallel.

Constructor & Destructor Documentation

◆ ConditionalOStream()

dftefe::utils::ConditionalOStream::ConditionalOStream ( std::ostream &  stream,
const bool  active = true 
)

Constructor.

Parameters
[in]streamReference to the ostream object onto which the output is to be written (e.g., std::cout, a file)
[in]activeBoolean to define whether printing to ostream be allowed or not

Member Function Documentation

◆ getOStream()

std::ostream & dftefe::utils::ConditionalOStream::getOStream ( ) const
inline

Function that returns the underlying ostream object associated with this object.

Returns
ostream object associated with this object

◆ isActive()

bool dftefe::utils::ConditionalOStream::isActive ( ) const

Function that returns true if printing to the output stream associated with this object is allowed.

Returns
True if printing to the output stream associated with this object is allowed, else returns false

◆ operator<<() [1/2]

template<class T >
const ConditionalOStream & dftefe::utils::ConditionalOStream::operator<< ( const T &  t) const
inline

Overload the insertion or << operator.

Template Parameters
TTemplate parameter which can be any of the C++ standard datatypes (e.g., bool, int, double, char, string, ...)
Parameters
[in]tValue to be printed

◆ operator<<() [2/2]

const ConditionalOStream & dftefe::utils::ConditionalOStream::operator<< ( std::ostream &(*)(std::ostream &)  p) const
inline

Overload the insertion or << operator which takes an input function pointer to a manipulator (e.g., std::endl, std::ends, std::flush, etc). See https://cplusplus.com/reference/ostream/ostream/operator%3C%3C/ for a list of manipulators.

Parameters
[in]pPointer to a function that takes and returns a stream object. It generally is a manipulator function.

◆ setCondition()

void dftefe::utils::ConditionalOStream::setCondition ( const bool  active)

Function to set the condition for printing to the output stream associated with this object.

Parameters
[in]activeBooleam to define whether printing to ostream be allowed or not
Here is the caller graph for this function:

Member Data Documentation

◆ d_activeFlag

bool dftefe::utils::ConditionalOStream::d_activeFlag
private

◆ d_outputStream

std::ostream& dftefe::utils::ConditionalOStream::d_outputStream
private

The documentation for this class was generated from the following files: