$treeview $search $mathjax $extrastylesheet
otsdaq
v2_03_00
$projectbrief
|
$projectbrief
|
$searchbox |
00001 #ifndef __DM_MACROS_H__ 00002 #define __DM_MACROS_H__ 00003 00004 /* 00005 * C++ ASCII output decorator 00006 * 00007 * Copyright (C) 2018 by 00008 * Dario Menasce dario.menasce@cern.ch 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * ---------------------------------------------------------------------- 00021 00022 This macro decorates a cout statement with auxilary information 00023 elements such as line number, file name etc... 00024 The most general form of decoration provides the following elements: 00025 00026 line # function-name file-name date time 00027 user-cout arguments 34 ] [int main(int argc, cha**argv))] [example.cc] [Jun 22 2018] 00028 [10:13:54] Result is 1.2 00029 00030 The following name-spaced variables control the actual output produced: 00031 00032 int DMM::__span__ : controls the width of the function/file name field 00033 (number of character)s 00034 int DMM::__pthr__ : controls the priority level: only cout 00035 statements declared with an equal or above level with respect to the current value of the 00036 DMM::__pthr__ will be printed out bool DMM::__enablePrintouts__ : switches of the 00037 following cout statment (does not produce output bool DMM::__long__ : 00038 shortens the name of the function (removes signature if false) bool DMM::__meth__ 00039 : enables/disables output of the function-name field bool DMM::__file__ : 00040 enables/disables output of the file-name field bool DMM::__date__ : 00041 enables/disables output of the date field bool DMM::__time__ : 00042 enables/disables output of the time field std::string DMM::__c_meth__ : determines the 00043 color of the function-name field 00044 std::string DMM::__c_file__ : determines the color of the file-name field 00045 std::string DMM::__c_date__ : determines the color of the date field 00046 std::string DMM::__c_time__ : determines the color of the time field 00047 00048 To GLOBALLY enable/diable colors, just edit this header file and modify the 00049 #define __USE_COLORS__ true 00050 statement below to false 00051 00052 The list of colors is defined below (variables beginning with AC and ending with _) 00053 00054 Usage example: 00055 00056 #include <DMMacros.h> 00057 00058 int main(int argc, char** argv) 00059 { 00060 00061 int i = 5 ; 00062 double d = 4.6 ; 00063 string s = "Just a regular string" ; 00064 00065 someClassWithAVeryLongName * sc = new someClassWithAVeryLongName() ; 00066 sc->doSomethingInThisClass() ; 00067 00068 DMM::__pthr__ = 0 ; 00069 __PRE__(0,{cout << "A: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s 00070 << " --------------------------------------------------------------" 00071 << endl ;}) 00072 __PRE__(3,{cout << "B: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00073 endl ;}) DMM::__enablePrintouts__ = false ; 00074 __PRE__(0,{cout << "C: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00075 endl ;}) DMM::__enablePrintouts__ = true ; 00076 __PRE__(0,{cout << "D: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00077 endl ;}) DMM::__long__ = true ; DMM::__file__ = true ; 00078 __PRE__(0,{cout << "E: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00079 endl ;}) DMM::__c_meth__ = ACBGreen_; 00080 __PRE__(0,{cout << "F: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00081 endl ;}) DMM::__c_meth__ = ACBGreen_ + ACReverse_; DMM::__meth__ = false ; DMM::__file__ = 00082 false ; DMM::__date__ = true ; DMM::__time__ = true ; 00083 __PRE__(0,{cout << "G: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00084 endl ;}) DMM::__meth__ = false ; DMM::__file__ = true ; DMM::__date__ = false ; 00085 DMM::__time__ = false ; 00086 __PRE__(0,{cout << "H: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00087 endl ;}) DMM::__meth__ = true ; DMM::__file__ = true ; DMM::__date__ = true ; 00088 DMM::__time__ = true ; DMM::__c_file__ = ACBBrown_ + ACReverse_; 00089 __PRE0__( cout << "I: " << i << " " << ACBCyan_ << d << ACPlain_ << " " << s << 00090 endl ; ) 00091 } 00092 00093 Output (except colors...) 00094 00095 17 ] [someClassWithAVeryLongName::so... ] 1 Ctor 00096 23 ] [doSomethingInThisClass ] 2 do whatever needs to be done 00097 39 ] [main ] A: 5 4.6 Just a regular string 00098 -------------------------------------------------------------- 40 ] [main 00099 ] B: 5 4.6 Just a regular string 44 ] [main ] D: 5 4.6 00100 Just a regular string 46 ] [int main(int, char**) ] [main.cc 00101 ] E: 5 4.6 Just a regular string 48 ] [int main(int, char**) ] [main.cc 00102 ] F: 5 4.6 Just a regular string 51 ] [Jun 22 2018] [13:32:26] G: 5 4.6 Just a regular 00103 string 53 ] [main.cc ] H: 5 4.6 Just a regular string 56 00104 ] [int main(int, char**) ] [main.cc ] [Jun 22 00105 2018] [13:32:26] I: 5 4.6 Just a regular string 00106 00107 To see color, type: more DMMacros.h 00108 00109 [0;36m[1m17[0m[1;33m ] 00110 [0m[1;33m[[1;35m[1msomeClassWithAVeryLongName::so[0;31m... [0m[1;33m] [0m1 00111 [0;31m[1mCtor [0;36m[1m23[0m[1;33m ] 00112 [0m[1;33m[[1;35m[1mdoSomethingInThisClass [0m[0m[0m [0m[1;33m] [0m2 00113 [1;32m[1mdo whatever needs to be done [0;36m[1m39[0m[1;33m ] 00114 [0m[1;33m[[1;35m[1mmain [0m[0m[0m [0m[1;33m] [0mA: 00115 5 [0;36m[1m4.6[0m Just a regular string 00116 -------------------------------------------------------------- [0;36m[1m40[0m[1;33m ] 00117 [0m[1;33m[[1;35m[1mmain [0m[0m[0m [0m[1;33m] [0mB: 00118 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m44[0m[1;33m ] 00119 [0m[1;33m[[1;35m[1mmain [0m[0m[0m [0m[1;33m] [0mD: 00120 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m46[0m[1;33m ] 00121 [0m[1;33m[[1;35m[1mint main(int, char**) [0m[0m[0m [0m[1;33m] 00122 [0m[1;33m[[0;36m[1mmain.cc [0m[0m[0m [0m[1;33m] [0mE: 00123 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m48[0m[1;33m ] 00124 [0m[1;33m[[0;32m[1mint main(int, char**) [0m[0m[0m [0m[1;33m] 00125 [0m[1;33m[[0;36m[1mmain.cc [0m[0m[0m [0m[1;33m] [0mF: 00126 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m51[0m[1;33m ] 00127 [0m[1;33m[[1;36m[1mJun 22 2018[0m[1;33m] [0m[1;33m[[1;34m[1m13:44:32[0m[1;33m] 00128 [0mG: 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m53[0m[1;33m ] 00129 [0m[1;33m[[0;36m[1mmain.cc [0m[0m[0m [0m[1;33m] [0mH: 00130 5 [0;36m[1m4.6[0m Just a regular string [0;36m[1m56[0m[1;33m ] 00131 [0m[1;33m[[0;32m[1m[7mint main(int, char**) [0m[0m[0m [0m[1;33m] 00132 [0m[1;33m[[0;33m[1m[7mmain.cc [0m[0m[0m [0m[1;33m] 00133 [0m[1;33m[[1;36m[1mJun 22 2018[0m[1;33m] [0m[1;33m[[1;34m[1m13:44:32[0m[1;33m] 00134 [0mI: 5 [0;36m[1m4.6[0m Just a regular string 00135 */ 00136 00137 #include <iostream> 00138 #include <sstream> 00139 00140 using namespace std; 00141 00142 #define __USE_COLORS__ true 00143 00144 #if __USE_COLORS__ == false 00145 00146 #define ACBlack "" 00147 #define ACBlue "" 00148 #define ACGreen "" 00149 #define ACCyan "" 00150 #define ACRed "" 00151 #define ACPurple "" 00152 #define ACBrown "" 00153 #define ACGray "" 00154 #define ACDarkGray "" 00155 #define ACLightBlue "" 00156 #define ACLightGreen "" 00157 #define ACLightCyan "" 00158 #define ACLightRed "" 00159 #define ACLightPurple "" 00160 #define ACYellow "" 00161 #define ACWhite "" 00162 00163 #define ACPlain "" 00164 #define ACBold "" 00165 #define ACUnderline "" 00166 #define ACBlink "" 00167 #define ACReverse "" 00168 00169 #define ACClear "" 00170 #define ACClearL "" 00171 00172 #define ACCR "" 00173 00174 #define ACSave "" 00175 #define ACRecall "" 00176 00177 #elif __USE_COLORS__ == true 00178 00179 #define ACBlack "\033[0;30m" 00180 #define ACBlue "\033[0;34m" 00181 #define ACGreen "\033[0;32m" 00182 #define ACCyan "\033[0;36m" 00183 #define ACRed "\033[0;31m" 00184 #define ACPurple "\033[0;35m" 00185 #define ACBrown "\033[0;33m" 00186 #define ACGray "\033[0;37m" 00187 #define ACDarkGray "\033[1;30m" 00188 #define ACLightBlue "\033[1;34m" 00189 #define ACLightGreen "\033[1;32m" 00190 #define ACLightCyan "\033[1;36m" 00191 #define ACLightRed "\033[1;31m" 00192 #define ACLightPurple "\033[1;35m" 00193 #define ACYellow "\033[1;33m" 00194 #define ACWhite "\033[1;37m" 00195 00196 #define ACPlain "\033[0m" 00197 #define ACBold "\033[1m" 00198 #define ACUnderline "\033[4m" 00199 #define ACBlink "\033[5m" 00200 #define ACReverse "\033[7m" 00201 00202 #define ACClear "\033[2J" 00203 #define ACClearL "\033[2K" 00204 00205 #define ACCR "\r" 00206 00207 #define ACSave "\033[s" 00208 #define ACRecall "\033[u" 00209 00210 #endif 00211 00212 static std::string ACBlack_ = ACBlack; 00213 static std::string ACBlue_ = ACBlue; 00214 static std::string ACGreen_ = ACGreen; 00215 static std::string ACCyan_ = ACCyan; 00216 static std::string ACRed_ = ACRed; 00217 static std::string ACPurple_ = ACPurple; 00218 static std::string ACBrown_ = ACBrown; 00219 static std::string ACGray_ = ACGray; 00220 static std::string ACDarkGray_ = ACDarkGray; 00221 static std::string ACLightBlue_ = ACLightBlue; 00222 static std::string ACLightGreen_ = ACLightGreen; 00223 static std::string ACLightCyan_ = ACLightCyan; 00224 static std::string ACLightRed_ = ACLightRed; 00225 static std::string ACLightPurple_ = ACLightPurple; 00226 static std::string ACYellow_ = ACYellow; 00227 static std::string ACWhite_ = ACWhite; 00228 00229 static std::string ACPlain_ = ACPlain; 00230 static std::string ACBold_ = ACBold; 00231 static std::string ACUnderline_ = ACUnderline; 00232 static std::string ACBlink_ = ACBlink; 00233 static std::string ACReverse_ = ACReverse; 00234 00235 static std::string ACClear_ = ACClear; 00236 static std::string ACClearL_ = ACClearL; 00237 00238 static std::string ACCR_ = ACCR; 00239 00240 static std::string ACSave_ = ACSave; 00241 static std::string ACRecall_ = ACRecall; 00242 00243 static std::string ACBBlack_ = ACBlack + ACBold_; 00244 static std::string ACBBlue_ = ACBlue + ACBold_; 00245 static std::string ACBGreen_ = ACGreen + ACBold_; 00246 static std::string ACBCyan_ = ACCyan + ACBold_; 00247 static std::string ACBRed_ = ACRed + ACBold_; 00248 static std::string ACBPurple_ = ACPurple + ACBold_; 00249 static std::string ACBBrown_ = ACBrown + ACBold_; 00250 static std::string ACBGray_ = ACGray + ACBold_; 00251 static std::string ACBDarkGray_ = ACDarkGray + ACBold_; 00252 static std::string ACBLightBlue_ = ACLightBlue + ACBold_; 00253 static std::string ACBLightGreen_ = ACLightGreen + ACBold_; 00254 static std::string ACBLightCyan_ = ACLightCyan + ACBold_; 00255 static std::string ACBLightRed_ = ACLightRed + ACBold_; 00256 static std::string ACBLightPurple_ = ACLightPurple + ACBold_; 00257 static std::string ACBYellow_ = ACYellow + ACBold_; 00258 static std::string ACBWhite_ = ACWhite + ACBold_; 00259 00260 namespace DMM 00261 { 00262 static int __span__ = 30; 00263 static int __pthr__ = 0; 00264 static bool __enablePrintouts__ = true; 00265 // static bool __disableColors__ = false ; 00266 static bool __long__ = true; 00267 static bool __meth__ = true; 00268 static bool __file__ = false; 00269 static bool __date__ = false; 00270 static bool __time__ = false; 00271 static std::string __c_file__ = ACBCyan_; 00272 static std::string __c_date__ = ACBLightCyan_; 00273 static std::string __c_time__ = ACBLightBlue_; 00274 static std::string __c_meth__ = ACBLightPurple_; 00275 00276 #define __PRE__(priority, iostream) \ 00277 { \ 00278 if(DMM::__enablePrintouts__) \ 00279 { \ 00280 std::stringstream msg_; \ 00281 std::stringstream ss; \ 00282 std::string toTrim; \ 00283 std::string PF_; \ 00284 std::stringstream PFs_; \ 00285 std::string blanks = ""; \ 00286 int PFSize = 0; \ 00287 int maxL = 30; \ 00288 int msgS; \ 00289 int blankSize; \ 00290 \ 00291 msg_ << ACBCyan_ << __LINE__ << ACPlain << ACYellow << "\t] " << ACPlain; \ 00292 \ 00293 if(DMM::__meth__) \ 00294 { \ 00295 PF_ = __FUNCTION__; \ 00296 if(DMM::__long__) \ 00297 PF_ = __PRETTY_FUNCTION__; \ 00298 PFSize = PF_.size(); \ 00299 if(PFSize >= DMM::__span__) \ 00300 { \ 00301 PFSize = DMM::__span__; \ 00302 } \ 00303 for(int i = 0; i < PFSize; ++i) \ 00304 { \ 00305 PFs_ << PF_[i]; \ 00306 } \ 00307 if(PFSize < DMM::__span__) \ 00308 { \ 00309 for(int i = 0; i < DMM::__span__ + 3 - PFSize; ++i) \ 00310 { \ 00311 PFs_ << " "; \ 00312 } \ 00313 } \ 00314 if(PFSize < (int)PF_.size()) \ 00315 { \ 00316 maxL -= 4; \ 00317 PFs_ << ACRed << "..."; \ 00318 } \ 00319 else \ 00320 { \ 00321 PFs_ << ACPlain << ACPlain << ACPlain; \ 00322 } \ 00323 msgS = PFs_.str().size() + 1; \ 00324 if(msgS <= DMM::__span__) \ 00325 msgS = DMM::__span__; \ 00326 blankSize = maxL - msgS; \ 00327 if(blankSize < 0) \ 00328 blankSize = 3; \ 00329 for(int i = 0; i < blankSize; ++i) \ 00330 { \ 00331 blanks += " "; \ 00332 } \ 00333 PFs_ << blanks; \ 00334 msg_ << ACYellow << "[" << DMM::__c_meth__ << PFs_.str() << ACPlain \ 00335 << ACYellow << "] " << ACPlain; \ 00336 } \ 00337 \ 00338 if(DMM::__file__) \ 00339 { \ 00340 PFs_.str(""); \ 00341 PF_ = __FILE__; \ 00342 PFSize = PF_.size(); \ 00343 if(PFSize >= DMM::__span__) \ 00344 { \ 00345 PFSize = DMM::__span__; \ 00346 } \ 00347 for(int i = 0; i < PFSize; ++i) \ 00348 { \ 00349 PFs_ << PF_[i]; \ 00350 } \ 00351 if(PFSize < DMM::__span__) \ 00352 { \ 00353 for(int i = 0; i < DMM::__span__ + 3 - PFSize; ++i) \ 00354 { \ 00355 PFs_ << " "; \ 00356 } \ 00357 } \ 00358 if(PFSize < (int)PF_.size()) \ 00359 { \ 00360 maxL -= 4; \ 00361 PFs_ << ACRed << "..."; \ 00362 } \ 00363 else \ 00364 { \ 00365 PFs_ << ACPlain << ACPlain << ACPlain; \ 00366 } \ 00367 msgS = PFs_.str().size() + 1; \ 00368 if(msgS <= DMM::__span__) \ 00369 msgS = DMM::__span__; \ 00370 blankSize = maxL - msgS; \ 00371 if(blankSize < 0) \ 00372 blankSize = 3; \ 00373 for(int i = 0; i < blankSize; ++i) \ 00374 { \ 00375 blanks += " "; \ 00376 } \ 00377 PFs_ << blanks; \ 00378 msg_ << ACYellow << "[" << DMM::__c_file__ << PFs_.str() << ACPlain \ 00379 << ACYellow << "] " << ACPlain; \ 00380 } \ 00381 \ 00382 if(DMM::__date__) \ 00383 { \ 00384 msg_ << ACYellow << "[" << DMM::__c_date__ << __DATE__ << ACPlain \ 00385 << ACYellow << "] " << ACPlain; \ 00386 } \ 00387 \ 00388 if(DMM::__time__) \ 00389 { \ 00390 msg_ << ACYellow << "[" << DMM ::__c_time__ << __TIME__ << ACPlain \ 00391 << ACYellow << "] " << ACPlain; \ 00392 } \ 00393 if(priority >= DMM::__pthr__) \ 00394 { \ 00395 std::cout << msg_.str(); \ 00396 iostream; \ 00397 cout << ACPlain; \ 00398 } \ 00399 } \ 00400 } 00401 } // namespace DMM 00402 00403 #define __PRE0__(iostream) __PRE__(0, iostream) 00404 00405 #endif // __DM_MACROS__