reportsystem.cpp
Go to the documentation of this file.
1 /* *****************************************************************************
2 
3  trimAl v2.0: a tool for automated alignment trimming in large-scale
4  phylogenetics analyses.
5 
6  readAl v2.0: a tool for automated alignment conversion among different
7  formats.
8 
9  2009-2019
10  Fernandez-Rodriguez V. (victor.fernandez@bsc.es)
11  Capella-Gutierrez S. (salvador.capella@bsc.es)
12  Gabaldon, T. (tgabaldon@crg.es)
13 
14  This file is part of trimAl/readAl.
15 
16  trimAl/readAl are free software: you can redistribute it and/or modify
17  it under the terms of the GNU General Public License as published by
18  the Free Software Foundation, the last available version.
19 
20  trimAl/readAl are distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  You should have received a copy of the GNU General Public License
26  along with trimAl/readAl. If not, see <http://www.gnu.org/licenses/>.
27 
28 ***************************************************************************** */
29 
31 #include "reportsystem.h"
32 
34 
36  // Create a timer that will report times upon its destruction
37  // which means the end of the current scope.
38  StartTiming("void reporting::reportManager::PrintCodesAndMessages() ");
39  switch (Level) {
40  case VerboseLevel::NONE:
41  std::cout << "[VerboseLevel] None" << std::endl;
42  break;
43  case VerboseLevel::INFO:
44  std::cout << "[VerboseLevel] Info" << std::endl;
45  break;
47  std::cout << "[VerboseLevel] Warning" << std::endl;
48  break;
50  std::cout << "[VerboseLevel] Error" << std::endl;
51  break;
52  }
53 
54  for (int i = 1; i < InfoCode::__MAXINFO; i++) {
55  report((InfoCode) i);
56  }
57 
58  for (int i = 1; i < WarningCode::__MAXWARNING; i++) {
60  }
61 
62  for (int i = 1; i < ErrorCode::__MAXERROR; i++) {
64  }
65 }
66 
67 void reporting::reportManager::report(ErrorCode message, std::string *vars) {
68  // Create a timer that will report times upon its destruction
69  // which means the end of the current scope.
70  StartTiming("void reporting::reportManager::report(ErrorCode message, std::string *vars) ");
71  if (Level > VerboseLevel::ERROR) {
72  delete[] vars;
73  } else {
74  if (vars == nullptr) {
75  std::cerr << "[ERROR " << std::setw(3) << std::setfill('0') << message << "] " << ErrorMessages.at(message) << std::endl << std::setfill(' ');
76  return;
77  }
78 
79  std::string s(ErrorMessages.at(message));
80 
81  std::string FindWord = "[tag]";
82 
83  int counter = 0;
84 
85  std::size_t index;
86  while ((index = s.find(FindWord)) != std::string::npos)
87  s.replace(index, FindWord.length(), vars[counter++]);
88 
89  std::cerr << "[ERROR " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
90 
91  delete[] vars;
92  }
93 }
94 
95 void reporting::reportManager::report(ErrorCode message, const char *vars) {
96  // Create a timer that will report times upon its destruction
97  // which means the end of the current scope.
98  StartTiming("void reporting::reportManager::report(ErrorCode message, char *vars) ");
99  if (Level > VerboseLevel::ERROR) return;
100 
101  if (vars == nullptr) {
102  std::cerr << "[ERROR " << std::setw(3) << std::setfill('0') << message << "] " << ErrorMessages.at(message) << std::endl << std::setfill(' ');
103  return;
104  }
105 
106  std::string s(ErrorMessages.at(message));
107 
108  std::string FindWord = "[tag]";
109 
110  std::string Vars = vars;
111 
112  std::size_t index;
113  while ((index = s.find(FindWord)) != std::string::npos)
114  s.replace(index, FindWord.length(), Vars);
115 
116  std::cerr << "[ERROR " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
117 
118 }
119 
120 void reporting::reportManager::report(WarningCode message, std::string *vars) {
121  // Create a timer that will report times upon its destruction
122  // which means the end of the current scope.
123  StartTiming("void reporting::reportManager::report(WarningCode message, std::string *vars) ");
125  delete[] vars;
126  } else {
127  if (vars == nullptr) {
128  std::cout << "[WARNING " << std::setw(3) << std::setfill('0') << message << "] " << WarningMessages.at(message) << std::endl << std::setfill(' ');
129  return;
130  }
131 
132  std::string s(WarningMessages.at(message));
133 
134  std::string FindWord = "[tag]";
135 
136  int counter = 0;
137 
138  std::size_t index;
139  while ((index = s.find(FindWord)) != std::string::npos)
140  s.replace(index, FindWord.length(), vars[counter++]);
141 
142  std::cout << "[WARNING " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
143 
144  delete[] vars;
145  }
146 }
147 
148 void reporting::reportManager::report(WarningCode message, const char *vars) {
149  // Create a timer that will report times upon its destruction
150  // which means the end of the current scope.
151  StartTiming("void reporting::reportManager::report(WarningCode message, char *vars) ");
152  if (Level > VerboseLevel::WARNING) return;
153 
154  if (vars == nullptr) {
155  std::cout << "[WARNING " << std::setw(3) << std::setfill('0') << message << "] " << WarningMessages.at(message) << std::endl << std::setfill(' ');
156  return;
157  }
158 
159  std::string s(WarningMessages.at(message));
160 
161  std::string FindWord = "[tag]";
162 
163  std::string Vars = vars;
164 
165  std::size_t index;
166  while ((index = s.find(FindWord)) != std::string::npos)
167  s.replace(index, FindWord.length(), Vars);
168 
169  std::cout << "[WARNING " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
170 
171 }
172 
173 void reporting::reportManager::report(InfoCode message, std::string *vars) {
174  // Create a timer that will report times upon its destruction
175  // which means the end of the current scope.
176  StartTiming("void reporting::reportManager::report(InfoCode message, std::string *vars) ");
177  if (Level > VerboseLevel::INFO) {
178  delete[] vars;
179  } else {
180  if (vars == nullptr) {
181  std::cout << "[INFO " << std::setw(3) << std::setfill('0') << message << "] " << InfoMessages.at(message) << std::endl << std::setfill(' ');
182  return;
183  }
184 
185  std::string s(InfoMessages.at(message));
186 
187  std::string FindWord = "[tag]";
188 
189  int counter = 0;
190 
191  std::size_t index;
192  while ((index = s.find(FindWord)) != std::string::npos)
193  s.replace(index, FindWord.length(), vars[counter++]);
194 
195  std::cout << "[INFO " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
196 
197  delete[] vars;
198  }
199 }
200 
201 void reporting::reportManager::report(InfoCode message, const char *vars) {
202  // Create a timer that will report times upon its destruction
203  // which means the end of the current scope.
204  StartTiming("void reporting::reportManager::report(InfoCode message, char *vars) ");
205  if (Level > VerboseLevel::INFO) return;
206 
207  if (vars == nullptr) {
208  std::cout << "[INFO " << std::setw(3) << std::setfill('0') << message << "] " << InfoMessages.at(message) << std::endl << std::setfill(' ');
209  return;
210  }
211 
212  std::string s(InfoMessages.at(message));
213 
214  std::string FindWord = "[tag]";
215 
216  std::string Vars = vars;
217 
218  std::size_t index;
219  while ((index = s.find(FindWord)) != std::string::npos)
220  s.replace(index, FindWord.length(), Vars);
221 
222  std::cout << "[INFO " << std::setw(3) << std::setfill('0') << message << "] " << s << std::endl << std::setfill(' ');
223 
224 }
static const std::map< WarningCode, const char * > WarningMessages
Definition: reportsystem.h:370
Class that allows us to centralize all the reporting messages that should be used to inform the user ...
Definition: reportsystem.h:354
void report(WarningCode message, std::string *vars=nullptr)
Method to report a Warning. It will be displayed if Level is equal or higher to VerboseLevel::WARNI...
1 = Info, warning and error messages
Definition: reportsystem.h:47
void report(InfoCode message, const char *vars)
Method to report an Info message. It will be displayed if Level is equal or higher to VerboseLevel::...
#define StartTiming(name)
3 = Only error messages
Definition: reportsystem.h:51
4 = No output messages
Definition: reportsystem.h:53
void report(WarningCode message, const char *vars)
Method to report a Warning. It will be displayed if Level is equal or higher to VerboseLevel::WARNIN...
Internal classes to handle reporting to user in several ways. The reporting system is made so a devel...
Definition: reportsystem.h:307
VerboseLevel Level
Level of Verbosity. The report system won&#39;t output messages that are lower than the current level...
Definition: reportsystem.h:377
VerboseLevel
VerboseLevel used to report messages.
Definition: reportsystem.h:44
void PrintCodesAndMessages()
Method to print all Info, Warning and Error codes and their respective message. This method is useful...
static const std::map< InfoCode, const char * > InfoMessages
Definition: reportsystem.h:369
2 = Error and warning messages
Definition: reportsystem.h:49
void report(ErrorCode message, const char *vars)
Method to report an Error. It will be displayed if Level is equal or higher to VerboseLevel::ERROR.
ErrorCode
Definition: reportsystem.h:56
reporting::reportManager debug
void report(InfoCode message, std::string *vars=nullptr)
Method to report an Info message. It will be displayed if Level is equal or higher to VerboseLevel:...
WarningCode
Definition: reportsystem.h:266
static const std::map< ErrorCode, const char * > ErrorMessages
Definition: reportsystem.h:371
void report(ErrorCode message, std::string *vars=nullptr)
Method to report an Error. It will be displayed if Level is equal or higher to VerboseLevel::ERROR...
InfoCode
Definition: reportsystem.h:291