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

Last change on this file since 1689 was 1666, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 3.8 KB
Line 
1#ifndef MARS_MLog
2#define MARS_MLog
3
4#ifndef ROOT_TObject
5#include <TObject.h>
6#endif
7
8#include <iostream.h> // base classes for MLog
9
10#define bsz 160 // two standard lines
11
12enum ELogBits {
13 kHasChanged = BIT(14) // if gui has changed
14};
15
16
17class TGListBox;
18
19class MLog : public streambuf, public ostream, public TObject
20{
21public:
22 typedef enum _flags { eStdout = 0x1, eStderr = 0x2, eFile = 0x4, eGui = 0x8 } Flags_t;
23
24private:
25 char fBuffer; //!
26 char fBase[bsz]; //! Buffer to store the data in
27 char *fPPtr; //! Pointer to present position in buffer
28 const char *fEPtr; //! Pointer to end of buffer
29
30 UInt_t fOutputLevel; //! Present output level of the stream
31 UInt_t fDebugLevel; //! Present global debug level
32 UInt_t fDevice; //! Flag to indicate the present streams
33
34 Bool_t fIsNull; //! Switch output completely off
35
36 Int_t fGuiLineId;
37
38 ofstream *fout; //! possible file output stream
39 Bool_t fOutAllocated; //! flag if fout is created by MLogging
40 TGListBox *fgui; //! Listbox output
41
42 void Init();
43
44 void WriteBuffer();
45 int sync();
46 int overflow(int i); // i=EOF means not a real overflow
47
48 void AllocateFile(const char *f);
49 void DeallocateFile();
50 void ReallocateFile(const char *f);
51 void CheckFlag(Flags_t chk, int flag);
52
53public:
54 MLog(int i=eStdout);
55 MLog(ofstream &out);
56 MLog(TGListBox &out);
57 MLog(const char *fname, int flag=-1);
58
59 MLog(MLog &log);
60
61 ~MLog()
62 {
63 DeallocateFile();
64 }
65
66 void SetDebugLevel(int i) { fDebugLevel = i; }
67 int GetDebugLevel() const { return fDebugLevel; }
68 void SetOutputLevel(int i) { fOutputLevel = i; }
69 void SetOutputDevice(int i) { fDevice = i; }
70 void EnableOutputDevice(Flags_t f) { fDevice |= f; }
71 void DisableOutputDevice(Flags_t f) { fDevice &= ~f; }
72 void operator=(ofstream &out) { SetOutputFile(out); }
73 void operator=(TGListBox *out) { SetOutputGui(out); }
74
75 Bool_t IsOutputDeviceEnabled(int i) const { return fDevice & i; }
76
77 void SetOutputGui(TGListBox *out, int flag=-1)
78 {
79 fgui = out;
80 CheckFlag(eGui, flag);
81 }
82
83 void SetOutputFile(ofstream &out, int flag=-1)
84 {
85 //
86 // Set new output file by a given stream. The new output
87 // file is not deleted automatically. If no flag is specified
88 // the state of the file-device stream is unchanged.
89 // if the a flag is specified the state is changed
90 // in correspondance to the flag
91 //
92 DeallocateFile();
93 fout = &out;
94 CheckFlag(eFile, flag);
95 }
96
97 void SetOutputFile(const char *f=NULL, int flag=-1)
98 {
99 //
100 // Set new output file by name. The new output file must
101 // not be deleted by the user. If no flag is specified
102 // the state of the file-device stream is unchanged.
103 // if the a flag is specified the state is changed
104 // in correspondance to the flag
105 //
106 ReallocateFile(f);
107 CheckFlag(eFile, flag);
108 }
109
110 ofstream &GetOutputFile()
111 {
112 //
113 // Get the file output stream from MLogging
114 // if no file output stream is existing yet it will be created.
115 // For the creating a C-Temporary file name is used.
116 // if the stream is created here the user must not delete it
117 //
118 // What a pitty, but it seems, that there is now way to ask
119 // an ofstream for the corresponding file name. Elsewhise
120 // I would implement a GetFileName-function, too.
121 //
122 if (!fout)
123 ReallocateFile(NULL);
124 return *fout;
125 }
126
127 void SetNullOutput(Bool_t n=kTRUE) { fIsNull = n; }
128
129 ClassDef(MLog, 0) // This is what we call 'The logging system'
130};
131
132#endif
Note: See TracBrowser for help on using the repository browser.