source: trunk/MagicSoft/Mars/mbase/MLog.h@ 2058

Last change on this file since 2058 was 2058, checked in by tbretz, 21 years ago
*** empty log message ***
File size: 4.9 KB
Line 
1#ifndef MARS_MLog
2#define MARS_MLog
3
4#ifndef ROOT_TObject
5#include <TObject.h>
6#endif
7#ifndef ROOT_TString
8#include <TString.h>
9#endif
10
11#include <iostream.h> // base classes for MLog
12
13#define bsz 160 // two standard lines
14
15enum ELogBits {
16 kHasChanged = BIT(14) // if gui has changed
17};
18
19
20class TGTextView;
21
22class MLog : public streambuf, public ostream, public TObject
23{
24public:
25 typedef enum _flags {
26 eStdout = 0x001,
27 eStderr = 0x002,
28 eFile = 0x004,
29 eGui = 0x008,
30 eNoColors = 0x400 //BIT(15)
31 } Flags_t;
32
33private:
34 static const char kESC;
35 static const char *const kEsc;
36 static const char *const kReset;
37 static const char *const kRed;
38 static const char *const kGreen;
39 static const char *const kYellow;
40 static const char *const kUnderline;
41 static const char *const kBlink;
42 static const char *const kBright;
43 static const char *const kDark;
44
45 char fBuffer; //!
46 char fBase[bsz+1]; //! Buffer to store the data in
47 char *fPPtr; //! Pointer to present position in buffer
48 const char *fEPtr; //! Pointer to end of buffer
49
50 UInt_t fOutputLevel; //! Present output level of the stream
51 UInt_t fDebugLevel; //! Present global debug level
52 UInt_t fDevice; //! Flag to indicate the present streams
53
54 Bool_t fIsNull; //! Switch output completely off
55
56 ofstream *fout; //! possible file output stream
57 Bool_t fOutAllocated; //! flag if fout is created by MLogging
58 TGTextView *fgui; //! Text View output
59
60 Bool_t fIsDirectGui; //! Pipe text directly to the GUI (for single threaded environments)
61 TString **fGuiLines; //! Lines to pipe to gui
62 Int_t fNumLines; //!
63 TString fGuiLine; //!
64
65#ifdef _REENTRANT
66 void *fMuxGui; //! Mutex locking access of TGListBox
67#endif
68
69 void Init();
70
71 void WriteBuffer();
72 int sync();
73 int overflow(int i); // i=EOF means not a real overflow
74
75 void AllocateFile(const char *f);
76 void DeallocateFile();
77 void ReallocateFile(const char *f);
78 void CheckFlag(Flags_t chk, int flag);
79 void Output(ostream &out, int len);
80
81public:
82 MLog(int i=eStdout);
83 MLog(ofstream &out);
84 MLog(TGTextView &out);
85 MLog(const char *fname, int flag=-1);
86
87 MLog(MLog &log);
88 ~MLog();
89
90 void Lock();
91 void UnLock();
92
93 void EnableDirectGui() { fIsDirectGui = kTRUE; }
94 void DisableDirectGui() { fIsDirectGui = kFALSE; }
95 void UpdateGui();
96
97 void Underline();
98
99 void SetDebugLevel(int i) { fDebugLevel = i; }
100 int GetDebugLevel() const { return fDebugLevel; }
101 void SetOutputLevel(int i) { fOutputLevel = i; }
102 void SetOutputDevice(int i) { fDevice = i; }
103 void EnableOutputDevice(Flags_t f) { fDevice |= f; }
104 void DisableOutputDevice(Flags_t f) { fDevice &= ~f; }
105 void operator=(ofstream &out) { SetOutputFile(out); }
106 void operator=(TGTextView *out) { SetOutputGui(out); }
107
108 Bool_t IsOutputDeviceEnabled(int i) const { return fDevice & i; }
109
110 void SetOutputGui(TGTextView *out, int flag=-1)
111 {
112 fgui = out;
113 CheckFlag(eGui, flag);
114 }
115
116 void SetOutputFile(ofstream &out, int flag=-1)
117 {
118 //
119 // Set new output file by a given stream. The new output
120 // file is not deleted automatically. If no flag is specified
121 // the state of the file-device stream is unchanged.
122 // if the a flag is specified the state is changed
123 // in correspondance to the flag
124 //
125 DeallocateFile();
126 fout = &out;
127 CheckFlag(eFile, flag);
128 }
129
130 void SetOutputFile(const char *f=NULL, int flag=-1)
131 {
132 //
133 // Set new output file by name. The new output file must
134 // not be deleted by the user. If no flag is specified
135 // the state of the file-device stream is unchanged.
136 // if the a flag is specified the state is changed
137 // in correspondance to the flag
138 //
139 ReallocateFile(f);
140 CheckFlag(eFile, flag);
141 }
142
143 ofstream &GetOutputFile()
144 {
145 //
146 // Get the file output stream from MLogging
147 // if no file output stream is existing yet it will be created.
148 // For the creating a C-Temporary file name is used.
149 // if the stream is created here the user must not delete it
150 //
151 // What a pitty, but it seems, that there is now way to ask
152 // an ofstream for the corresponding file name. Elsewhise
153 // I would implement a GetFileName-function, too.
154 //
155 if (!fout)
156 ReallocateFile(NULL);
157 return *fout;
158 }
159
160 void SetNullOutput(Bool_t n=kTRUE) { fIsNull = n; }
161
162 void SetNoColors(Bool_t flag=kTRUE) { flag ? SetBit(eNoColors) : ResetBit(eNoColors); }
163
164 ClassDef(MLog, 0) // This is what we call 'The logging system'
165};
166
167#endif
Note: See TracBrowser for help on using the repository browser.