Ignore:
Timestamp:
06/13/03 16:42:37 (21 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mbase/MLogManip.h

    r2142 r2173  
    22#define MARS_MLogManip
    33
    4 #include <iomanip.h>
     4#include <iomanip>
    55
    6 // ----------------------------------------------------------------
    7 //                 Definitions of the manipulators
    8 // ----------------------------------------------------------------
     6#include "MLog.h"
    97
    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 -----------------------
    159
    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       }
     10enum MLogManip {
     11    underline
     12};
    2313
    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        }
     14inline 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}
    3121
    32 #endif
    3322
    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 -----------------------------
    4824
    49 // ----------------------------------------------------------------
    50 //                         Debug helper macros
    51 // ----------------------------------------------------------------
     25struct _Debug { int level; };
    5226
    53 //
    54 // Output debug information into the stream
    55 //  - this can only be done by a macro
    56 //
     27inline _Debug debug(int level)
     28{
     29    _Debug d;
     30    d.level = level;
     31    return d;
     32}
     33
     34inline 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
     44struct _EnableDev { MLog::_flags dev; };
     45
     46inline _EnableDev edev(MLog::_flags i)
     47{
     48    _EnableDev e;
     49    e.dev = i;
     50    return e;
     51}
     52
     53inline 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
     63struct _DisableDev { MLog::_flags dev; };
     64
     65inline _DisableDev ddev(MLog::_flags i)
     66{
     67    _DisableDev d;
     68    d.dev = i;
     69    return d;
     70}
     71
     72inline 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
    5782#ifndef __CINT__
    58 //#define dbginf dbg << __FILE__ << " l." << dec << __LINE__ << ": "
    5983#define dbginf __FILE__ << " l." << dec << __LINE__ << ": "
    6084#define all    debug(0) // use this for output in any case
     
    6488#define dbg    debug(4) // use this for debug messages (blue)
    6589#endif
    66 //
    67 // flush the old buffer, set a new debug level
    68 // and output the debug information code
    69 //
    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) << dbginf
    76 #endif
    77 */
    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 */
    9790
    9891#endif
Note: See TracChangeset for help on using the changeset viewer.