TBTK
TBTK::Communicator Class Reference

Base class for classes that can communicate their status during execution. More...

#include <Communicator.h>

Inheritance diagram for TBTK::Communicator:
TBTK::LUSolver TBTK::Model TBTK::Solver::ArnoldiIterator TBTK::Solver::BlockDiagonalizer TBTK::Solver::ChebyshevExpander TBTK::Solver::Diagonalizer TBTK::Solver::LinearEquationSolver TBTK::Models::SquareLattice

Public Member Functions

 Communicator (bool verbose)
 
void setVerbose (bool verbose)
 
bool getVerbose () const
 

Static Public Member Functions

static void setGlobalVerbose (bool globalVerbose)
 
static bool getGlobalVerbose ()
 

Detailed Description

Base class for classes that can communicate their status during execution.

The communicator allows for both the global verbosity and the verbosity of individual objects to be modified. A class that inherits from Communicator is provided with two functions for setting and getting its verbosity. Setting the verbosity to true means the object may output text to the Streams during execution.

The Communicator class also provides two static functions for setting the verbosity globally. If the global verbosity set to false, no information should be written to the Streams even if the individual objects have their verbosity set to true. To respect this behavior, classes that derive from the communicator should enclose any output to Streams with the statement

if(getVerbose() && Streams::getGlobalVerbose()){
//Output to Streams here
//...
}

Note: Error messages should not be muted.

Example

#include "TBTK/Streams.h"
#include "TBTK/TBTK.h"
#include <vector>
using namespace std;
using namespace TBTK;
class MyCommunicator : public Communicator{
public:
MyCommunicator() : Communicator(true){}
void say(const std::string &message){
Streams::out << message << "\n";
}
}
};
int main(){
MyCommunicator myCommunicator;
myCommunicator.setVerbose(false);
myCommunicator.say("Don't say this");
myCommunicator.setVerbose(true);
myCommunicator.say("Say this");
myCommunicator.say("Don't say this");
}

Output

Say this

Constructor & Destructor Documentation

◆ Communicator()

TBTK::Communicator::Communicator ( bool  verbose)

Constructor.

Parameters
verboseFlag indicating whether or not the communicator is verbose

Member Function Documentation

◆ getGlobalVerbose()

bool TBTK::Communicator::getGlobalVerbose ( )
inlinestatic

Get global verbose.

Returns
False if communication is suppressed globally.

◆ getVerbose()

bool TBTK::Communicator::getVerbose ( ) const
inline

Get verbose.

Returns
True if the Communicator is verbose, otherwise false.

◆ setGlobalVerbose()

void TBTK::Communicator::setGlobalVerbose ( bool  globalVerbose)
inlinestatic

Set global verbose.

Parameters
globalVerboseIf set to false, Communicators will not communicate even if they are verbose.

◆ setVerbose()

void TBTK::Communicator::setVerbose ( bool  verbose)
inline

Set verbose.

Parameters
verboseFlag indicating whether or not the Communicator is verbose.

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