| [bcf653] | 1 | /*
 | 
|---|
 | 2 |  * Project: MoleCuilder
 | 
|---|
 | 3 |  * Description: creates and alters molecular systems
 | 
|---|
 | 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
 | 5 |  * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
| [bbbad5] | 8 | /** \file Verbose.cpp
 | 
|---|
 | 9 |  *
 | 
|---|
 | 10 |  * Function implementations for the class Verbose.
 | 
|---|
 | 11 |  *
 | 
|---|
 | 12 |  */
 | 
|---|
| [f66195] | 13 | 
 | 
|---|
| [bf3817] | 14 | // include config.h
 | 
|---|
 | 15 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 16 | #include <config.h>
 | 
|---|
 | 17 | #endif
 | 
|---|
 | 18 | 
 | 
|---|
| [112b09] | 19 | #include "Helpers/MemDebug.hpp"
 | 
|---|
 | 20 | 
 | 
|---|
| [952f38] | 21 | #include "Helpers/Info.hpp"
 | 
|---|
 | 22 | #include "Helpers/Verbose.hpp"
 | 
|---|
| [5e8e02] | 23 | #include <iostream>
 | 
|---|
| [14de469] | 24 | 
 | 
|---|
| [bbbad5] | 25 | using namespace std;
 | 
|---|
 | 26 | 
 | 
|---|
| [14de469] | 27 | /** Prints the tabs according to verbosity stored in the temporary constructed class.
 | 
|---|
 | 28 |  * \param &ost stream to extend with tabs
 | 
|---|
 | 29 |  * \return &ost stream with tabs
 | 
|---|
 | 30 |  */
 | 
|---|
 | 31 | ostream& Verbose::print (ostream &ost) const
 | 
|---|
 | 32 | {
 | 
|---|
| [8725ed] | 33 |   for (int i=Verbosity+Info::verbosity;i--;)
 | 
|---|
| [042f82] | 34 |     ost.put('\t');
 | 
|---|
| [e138de] | 35 |   //Log() << Verbose(0) << "Verbose(.) called." << endl;
 | 
|---|
| [042f82] | 36 |   return ost;
 | 
|---|
| [14de469] | 37 | };
 | 
|---|
 | 38 | 
 | 
|---|
| [06c7a3] | 39 | /** States whether current output message should be print or not.
 | 
|---|
| [90f680] | 40 |  * Compares Verbose::Verbosity plus Info::verbosity against \a verbosityLevel.
 | 
|---|
| [06c7a3] | 41 |  * \param verbosityLevel given global level of verbosity
 | 
|---|
 | 42 |  * \return true - do output, false - don't
 | 
|---|
 | 43 |  */
 | 
|---|
 | 44 | bool Verbose::DoOutput(int verbosityLevel) const
 | 
|---|
 | 45 | {
 | 
|---|
| [8725ed] | 46 |   return (verbosityLevel >= Verbosity+Info::verbosity);
 | 
|---|
| [06c7a3] | 47 | };
 | 
|---|
 | 48 | 
 | 
|---|
| [90f680] | 49 | /** States whether current error output message should be print or not.
 | 
|---|
 | 50 |  * Compares Verbose::Verbosity against \a verbosityLevel.
 | 
|---|
 | 51 |  * \param verbosityLevel given global level of verbosity
 | 
|---|
 | 52 |  * \return true - do output, false - don't
 | 
|---|
 | 53 |  */
 | 
|---|
 | 54 | bool Verbose::DoErrorOutput(int verbosityLevel) const
 | 
|---|
 | 55 | {
 | 
|---|
 | 56 |   return (verbosityLevel >= Verbosity);
 | 
|---|
 | 57 | };
 | 
|---|
| [06c7a3] | 58 | 
 | 
|---|
| [14de469] | 59 | /** Operator for the Verbose(arg) call.
 | 
|---|
 | 60 |  * Constructs temporary a Verbose class object, wherein the verbosity is stored.
 | 
|---|
 | 61 |  * Then << is called, which calls Verbose's print which adds the tabs and returns the stream.
 | 
|---|
 | 62 |  * \param &ost stream to extend
 | 
|---|
 | 63 |  * \param &m pointer to created Verbose object
 | 
|---|
 | 64 |  * \return &ost
 | 
|---|
 | 65 |  */ 
 | 
|---|
 | 66 | ostream& operator<<(ostream& ost,const Verbose& m)
 | 
|---|
 | 67 | {
 | 
|---|
| [042f82] | 68 |   return m.print(ost);
 | 
|---|
| [14de469] | 69 | };
 | 
|---|
 | 70 | 
 | 
|---|
 | 71 | /** Prints the tabs according to verbosity stored in the temporary constructed class.
 | 
|---|
 | 72 |  * Note that highest bit is set artificially to give number of bits to print
 | 
|---|
 | 73 |  * \param &ost stream to extend with tabs
 | 
|---|
 | 74 |  * \return &ost stream with tabs
 | 
|---|
 | 75 |  */
 | 
|---|
 | 76 | ostream& Binary::print (ostream &ost) const
 | 
|---|
 | 77 | {
 | 
|---|
| [042f82] | 78 |   int bits = 1, counter = 1;
 | 
|---|
 | 79 |   while ((bits = 1 << counter) < BinaryNumber)
 | 
|---|
 | 80 |     counter++;
 | 
|---|
 | 81 |   for (int i=0;i<counter-1;i++) {
 | 
|---|
 | 82 |     if ((BinaryNumber & (1 << i)) == 0)
 | 
|---|
 | 83 |       ost.put('0');
 | 
|---|
 | 84 |      else
 | 
|---|
 | 85 |       ost.put('1');
 | 
|---|
 | 86 |   }
 | 
|---|
 | 87 |   ost.put('b');
 | 
|---|
| [e138de] | 88 |   //Log() << Verbose(0) << "Binary(.) called." << endl;
 | 
|---|
| [042f82] | 89 |   return ost;
 | 
|---|
| [14de469] | 90 | };
 | 
|---|
 | 91 | 
 | 
|---|
 | 92 | /** Operator for the Binary(arg) call.
 | 
|---|
 | 93 |  * Constructs temporary a Verbose class object, wherein the Binary is stored.
 | 
|---|
 | 94 |  * Then << is called, which calls Binary's print which adds the tabs and returns the stream.
 | 
|---|
 | 95 |  * \param &ost stream to extend
 | 
|---|
 | 96 |  * \param &m pointer to created Binary object
 | 
|---|
 | 97 |  * \return &ost
 | 
|---|
 | 98 |  */ 
 | 
|---|
 | 99 | ostream& operator<<(ostream& ost,const Binary& m)
 | 
|---|
 | 100 | {
 | 
|---|
| [042f82] | 101 |   return m.print(ost);
 | 
|---|
| [14de469] | 102 | };
 | 
|---|