File: mothurout.h

package info (click to toggle)
mothur 1.48.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 13,684 kB
  • sloc: cpp: 161,854; makefile: 122; sh: 31
file content (116 lines) | stat: -rwxr-xr-x 4,575 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef MOTHUROUT_H
#define MOTHUROUT_H

/*
 *  mothurOut.h
 *  Mothur
 *
 *  Created by westcott on 2/25/10.
 *  Copyright 2010 Schloss Lab. All rights reserved.
 *
 */

#include "mothur.h"

/***********************************************/
struct logger {
    
    logger() = default;
    ~logger() = default;
    
    template< class T >
    logger& operator <<( const T& o ) {
        //lock_guard<std::mutex> guard(token);
        cout << o; return *this;
    }
    
    logger& operator<<(ostream& (*m)(ostream&) ) {
        //lock_guard<std::mutex> guard(token);
        cout << m; return *this;
    }
private:
    //std::mutex token;
};
/***********************************************/

class MothurOut {
	
	public:
		static MothurOut* getInstance();
    
        //logger
        bool getDebug()                                 { return debug;                                 }
        void setDebug(bool t)                           { debug = t;                                    }
        void setQuietMode(bool t)                       { quietMode = t;                                }
        int getNumErrors()                              { return numErrors;                             }
        void resetCommandErrors()                       { control_pressed = false; numCommandErrors = 0; numCommandWarnings = 0; silenceWarnings = false;}
        string getLogFileName()                         { return logFileName;                           }
		void setLogFileName(string f, bool append);
        void setHomePath(string);
        string getHomePath()  { return homePath; }
        void setPaths(vector<string>); //environment variable 'PATH' values
        vector<string> getPaths() { return paths; }
    
		void mothurOut(string); //writes to cout and the logfile
		void mothurOutEndLine(); //writes to cout and the logfile
		void mothurOut(string, ofstream&); //writes to the ofstream, cout and the logfile
        void mothurOutJustToScreen(string); //writes to cout
		void mothurOutJustToLog(string);
		void errorOut(exception&, string, string);
		void closeLog();
    
        //globals
        void setRandomSeed(unsigned s)                  { seed = s;                         }
        unsigned getRandomSeed()                        { return seed;                      }
        bool getControl_pressed()                       { return control_pressed;           }
        void setControl_pressed(bool t)                 { control_pressed = t;              }
        bool getChangedSeqNames()                       { return changedSeqNames;           }
        void setChangedSeqNames(bool t)                 { changedSeqNames = t;              }
        bool getChangedGroupNames()                     { return changedGroupNames;         }
        void setChangedGroupNames(bool t)               { changedGroupNames = t;            }
        bool getExecuting()                             { return executing;                 }
        void setExecuting(bool t)                       { executing = t;                    }
    
        vector<vector<vector<char>>> codons;
        set<char> validAminoAcids;
    
	private:
		static MothurOut* _uniqueInstance;
		MothurOut( const MothurOut& ); // Disable copy constructor
		void operator=( const MothurOut& ); // Disable assignment operator
		MothurOut() { 
			control_pressed = false;
            debug = false;
            quietMode = false;
            changedSeqNames = true;
            changedGroupNames = true;
            silenceLog = false;
            silenceWarnings = false; //per command
            numErrors = 0; numWarnings = 0;
            numCommandErrors = 0; numCommandWarnings = 0;
            maxCommandErrors = 10; maxCommandWarnings = 10;
            logFileName = "";
            buffer = "";
            homePath = "";
            outLog = nullptr;
            seed = std::chrono::system_clock::now().time_since_epoch().count();
            
            initialize(); //fills validAminoAcids and codons
		}
		~MothurOut();
		
        void appendLogBuffer(string); //used to store log before we establish the logfilename
        void initialize();

		ofstream* outLog;
        unsigned seed;
        int numErrors, numWarnings, numCommandErrors, numCommandWarnings, maxCommandErrors, maxCommandWarnings;
        string logFileName, buffer, homePath;
        vector<string> paths;
        bool changedSeqNames, changedGroupNames, silenceLog, silenceWarnings, control_pressed, executing, debug, quietMode;
};
/***********************************************/


#endif