Changeset 2173 for trunk/MagicSoft/Mars/mbase/MLogManip.h
- Timestamp:
- 06/13/03 16:42:37 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/mbase/MLogManip.h
r2142 r2173 2 2 #define MARS_MLogManip 3 3 4 #include <iomanip .h>4 #include <iomanip> 5 5 6 // ---------------------------------------------------------------- 7 // Definitions of the manipulators 8 // ---------------------------------------------------------------- 6 #include "MLog.h" 9 7 10 // 11 // define a general simple macro for manipulator definitions (int) 12 // 13 #define MANIPULATOR0(name) \ 14 extern ostream& ##name(ostream& lout); 8 // --------------------- simple manipulators ----------------------- 15 9 16 #ifndef OMANIP 17 #define MANIPULATOR1(name) \ 18 extern ostream& __omanip_##name(ostream& lout, int i); \ 19 inline omanip<int> ##name(int i) \ 20 { \ 21 return omanip<int>(__omanip_##name, i); \ 22 } 10 enum MLogManip { 11 underline 12 }; 23 13 24 #else 25 #define MANIPULATOR1(name) \ 26 extern ostream& __omanip_##name(ostream& lout, int i); \27 inline OMANIP(int) ##name(int i) \28 { \29 return OMANIP(int)(__omanip_##name, i); \30 14 inline std::ostream &operator<<(std::ostream &lout, MLogManip u) 15 { 16 MLog *log=/*<dynamic_cast>*/(MLog*)lout.rdbuf(); 17 if (log) 18 log->Underline(); 19 return lout; 20 } 31 21 32 #endif33 22 34 // 35 // definitions 36 // 37 MANIPULATOR0(underline); // underline output 38 MANIPULATOR1(debug); // set debug level 39 MANIPULATOR1(device); // set ouput devices 40 MANIPULATOR1(edev); // enable additional output devices 41 MANIPULATOR1(ddev); // disable given output 42 //#ifndef __CINT__ 43 //__DEFINE_IOMANIP_FN1(smanip, int, debug); // set debug level 44 //__DEFINE_IOMANIP_FN1(smanip, int, device); // set ouput devices 45 //__DEFINE_IOMANIP_FN1(smanip, int, edev); // enable additional output devices 46 //__DEFINE_IOMANIP_FN1(smanip, int, ddev); // disable given output 47 //#endif 23 // ----------------------------- debug ----------------------------- 48 24 49 // ---------------------------------------------------------------- 50 // Debug helper macros 51 // ---------------------------------------------------------------- 25 struct _Debug { int level; }; 52 26 53 // 54 // Output debug information into the stream 55 // - this can only be done by a macro 56 // 27 inline _Debug debug(int level) 28 { 29 _Debug d; 30 d.level = level; 31 return d; 32 } 33 34 inline std::ostream &operator<<(std::ostream &lout, _Debug d) 35 { 36 MLog *log=/*<dynamic_cast>*/(MLog*)lout.rdbuf(); 37 if (log) 38 log->SetOutputLevel(d.level); 39 return lout; 40 } 41 42 // ------------------------------- edev ---------------------------- 43 44 struct _EnableDev { MLog::_flags dev; }; 45 46 inline _EnableDev edev(MLog::_flags i) 47 { 48 _EnableDev e; 49 e.dev = i; 50 return e; 51 } 52 53 inline std::ostream &operator<<(std::ostream &lout, _EnableDev e) 54 { 55 MLog *log=/*<dynamic_cast>*/(MLog*)lout.rdbuf(); 56 if (log) 57 log->EnableOutputDevice(e.dev); 58 return lout; 59 } 60 61 // ------------------------------- sdev ---------------------------- 62 63 struct _DisableDev { MLog::_flags dev; }; 64 65 inline _DisableDev ddev(MLog::_flags i) 66 { 67 _DisableDev d; 68 d.dev = i; 69 return d; 70 } 71 72 inline std::ostream &operator<<(std::ostream &lout, _DisableDev d) 73 { 74 MLog *log=/*<dynamic_cast>*/(MLog*)lout.rdbuf(); 75 if (log) 76 log->EnableOutputDevice(d.dev); 77 return lout; 78 } 79 80 // ------------------------------ Macros --------------------------- 81 57 82 #ifndef __CINT__ 58 //#define dbginf dbg << __FILE__ << " l." << dec << __LINE__ << ": "59 83 #define dbginf __FILE__ << " l." << dec << __LINE__ << ": " 60 84 #define all debug(0) // use this for output in any case … … 64 88 #define dbg debug(4) // use this for debug messages (blue) 65 89 #endif 66 //67 // flush the old buffer, set a new debug level68 // and output the debug information code69 //70 // Be careful: Only use them with a MLogging stream facility.71 // Remark: All this is compiled into the code.72 //73 /*74 #ifndef __CINT__75 #define DEBUG(lvl) flush << debug(lvl) << dbginf76 #endif77 */78 /*79 class SMANIP(T) {80 ios& (*fct)(ios&,T) ;81 T arg ;82 public:83 SMANIP(T)(ios& (*f)(ios&, T), T a) :84 fct(f), arg(a) { }85 friend istream& operator>>(istream& i, const SMANIP(T)& m)86 {87 ios* s = &i ;88 (*m.fct)(*s,m.arg) ; return i ;89 }90 friend ostream& operator<<(ostream& o, const SMANIP(T)& m)91 {92 ios* s = &o ;93 (*m.fct)(*s,m.arg) ; return o ;94 }95 } ;96 */97 90 98 91 #endif
Note:
See TracChangeset
for help on using the changeset viewer.