| 1 | /** \file Verbose.cpp
|
|---|
| 2 | *
|
|---|
| 3 | * Function implementations for the class Verbose.
|
|---|
| 4 | *
|
|---|
| 5 | */
|
|---|
| 6 |
|
|---|
| 7 | #include "Helpers/MemDebug.hpp"
|
|---|
| 8 |
|
|---|
| 9 | #include "Helpers/Info.hpp"
|
|---|
| 10 | #include "Helpers/Verbose.hpp"
|
|---|
| 11 | #include <iostream>
|
|---|
| 12 |
|
|---|
| 13 | using namespace std;
|
|---|
| 14 |
|
|---|
| 15 | /** Prints the tabs according to verbosity stored in the temporary constructed class.
|
|---|
| 16 | * \param &ost stream to extend with tabs
|
|---|
| 17 | * \return &ost stream with tabs
|
|---|
| 18 | */
|
|---|
| 19 | ostream& Verbose::print (ostream &ost) const
|
|---|
| 20 | {
|
|---|
| 21 | for (int i=Verbosity+Info::verbosity;i--;)
|
|---|
| 22 | ost.put('\t');
|
|---|
| 23 | //Log() << Verbose(0) << "Verbose(.) called." << endl;
|
|---|
| 24 | return ost;
|
|---|
| 25 | };
|
|---|
| 26 |
|
|---|
| 27 | /** States whether current output message should be print or not.
|
|---|
| 28 | * Compares Verbose::Verbosity plus Info::verbosity against \a verbosityLevel.
|
|---|
| 29 | * \param verbosityLevel given global level of verbosity
|
|---|
| 30 | * \return true - do output, false - don't
|
|---|
| 31 | */
|
|---|
| 32 | bool Verbose::DoOutput(int verbosityLevel) const
|
|---|
| 33 | {
|
|---|
| 34 | return (verbosityLevel >= Verbosity+Info::verbosity);
|
|---|
| 35 | };
|
|---|
| 36 |
|
|---|
| 37 | /** States whether current error output message should be print or not.
|
|---|
| 38 | * Compares Verbose::Verbosity against \a verbosityLevel.
|
|---|
| 39 | * \param verbosityLevel given global level of verbosity
|
|---|
| 40 | * \return true - do output, false - don't
|
|---|
| 41 | */
|
|---|
| 42 | bool Verbose::DoErrorOutput(int verbosityLevel) const
|
|---|
| 43 | {
|
|---|
| 44 | return (verbosityLevel >= Verbosity);
|
|---|
| 45 | };
|
|---|
| 46 |
|
|---|
| 47 | /** Operator for the Verbose(arg) call.
|
|---|
| 48 | * Constructs temporary a Verbose class object, wherein the verbosity is stored.
|
|---|
| 49 | * Then << is called, which calls Verbose's print which adds the tabs and returns the stream.
|
|---|
| 50 | * \param &ost stream to extend
|
|---|
| 51 | * \param &m pointer to created Verbose object
|
|---|
| 52 | * \return &ost
|
|---|
| 53 | */
|
|---|
| 54 | ostream& operator<<(ostream& ost,const Verbose& m)
|
|---|
| 55 | {
|
|---|
| 56 | return m.print(ost);
|
|---|
| 57 | };
|
|---|
| 58 |
|
|---|
| 59 | /** Prints the tabs according to verbosity stored in the temporary constructed class.
|
|---|
| 60 | * Note that highest bit is set artificially to give number of bits to print
|
|---|
| 61 | * \param &ost stream to extend with tabs
|
|---|
| 62 | * \return &ost stream with tabs
|
|---|
| 63 | */
|
|---|
| 64 | ostream& Binary::print (ostream &ost) const
|
|---|
| 65 | {
|
|---|
| 66 | int bits = 1, counter = 1;
|
|---|
| 67 | while ((bits = 1 << counter) < BinaryNumber)
|
|---|
| 68 | counter++;
|
|---|
| 69 | for (int i=0;i<counter-1;i++) {
|
|---|
| 70 | if ((BinaryNumber & (1 << i)) == 0)
|
|---|
| 71 | ost.put('0');
|
|---|
| 72 | else
|
|---|
| 73 | ost.put('1');
|
|---|
| 74 | }
|
|---|
| 75 | ost.put('b');
|
|---|
| 76 | //Log() << Verbose(0) << "Binary(.) called." << endl;
|
|---|
| 77 | return ost;
|
|---|
| 78 | };
|
|---|
| 79 |
|
|---|
| 80 | /** Operator for the Binary(arg) call.
|
|---|
| 81 | * Constructs temporary a Verbose class object, wherein the Binary is stored.
|
|---|
| 82 | * Then << is called, which calls Binary's print which adds the tabs and returns the stream.
|
|---|
| 83 | * \param &ost stream to extend
|
|---|
| 84 | * \param &m pointer to created Binary object
|
|---|
| 85 | * \return &ost
|
|---|
| 86 | */
|
|---|
| 87 | ostream& operator<<(ostream& ost,const Binary& m)
|
|---|
| 88 | {
|
|---|
| 89 | return m.print(ost);
|
|---|
| 90 | };
|
|---|