| 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 | 
 | 
|---|
| 8 | /** \file Verbose.cpp
 | 
|---|
| 9 |  *
 | 
|---|
| 10 |  * Function implementations for the class Verbose.
 | 
|---|
| 11 |  *
 | 
|---|
| 12 |  */
 | 
|---|
| 13 | 
 | 
|---|
| 14 | // include config.h
 | 
|---|
| 15 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 16 | #include <config.h>
 | 
|---|
| 17 | #endif
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include "MemDebug.hpp"
 | 
|---|
| 20 | 
 | 
|---|
| 21 | #include "Info.hpp"
 | 
|---|
| 22 | #include "Verbose.hpp"
 | 
|---|
| 23 | #include <iostream>
 | 
|---|
| 24 | 
 | 
|---|
| 25 | using namespace std;
 | 
|---|
| 26 | 
 | 
|---|
| 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 | {
 | 
|---|
| 33 |   for (int i=Verbosity+Info::verbosity;i--;)
 | 
|---|
| 34 |     ost.put('\t');
 | 
|---|
| 35 |   //Log() << Verbose(0) << "Verbose(.) called." << endl;
 | 
|---|
| 36 |   return ost;
 | 
|---|
| 37 | };
 | 
|---|
| 38 | 
 | 
|---|
| 39 | /** States whether current output message should be print or not.
 | 
|---|
| 40 |  * Compares Verbose::Verbosity plus Info::verbosity against \a verbosityLevel.
 | 
|---|
| 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 | {
 | 
|---|
| 46 |   return (verbosityLevel >= Verbosity+Info::verbosity);
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 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 | };
 | 
|---|
| 58 | 
 | 
|---|
| 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 | {
 | 
|---|
| 68 |   return m.print(ost);
 | 
|---|
| 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 | {
 | 
|---|
| 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');
 | 
|---|
| 88 |   //Log() << Verbose(0) << "Binary(.) called." << endl;
 | 
|---|
| 89 |   return ost;
 | 
|---|
| 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 | {
 | 
|---|
| 101 |   return m.print(ost);
 | 
|---|
| 102 | };
 | 
|---|