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

Last change on this file since 958 was 936, checked in by tbretz, 23 years ago
*** empty log message ***
File size: 3.7 KB
Line 
1#ifndef MLOG_H
2#define MLOG_H
3
4//#ifndef MAGIC_H
5//#include "MAGIC.h"
6//#endif
7
8#include <TObject.h>
9
10#include <stdio.h> // tmpname
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 TGListBox;
21
22class MLog : public streambuf, public ostream, public TObject
23{
24public:
25 typedef enum _flags { eStdout = 0x1, eStderr = 0x2, eFile = 0x4, eGui = 0x8 } Flags_t;
26
27private:
28 char fBuffer; //!
29 char fBase[bsz]; //! Buffer to store the data in
30 char *fPPtr; //! Pointer to present position in buffer
31 const char *fEPtr; //! Pointer to end of buffer
32
33 UInt_t fOutputLevel; //! Present output level of the stream
34 UInt_t fDebugLevel; //! Present global debug level
35 UInt_t fDevice; //! Flag to indicate the present streams
36
37 Int_t fGuiLineId;
38
39 ofstream *fout; //! possible file output stream
40 Bool_t fOutAllocated; //! flag if fout is created by MLogging
41 TGListBox *fgui; //! Listbox output
42
43 void Init();
44
45 void WriteBuffer();
46 int sync();
47 int overflow(int i); // i=EOF means not a real overflow
48
49 void AllocateFile(const char *f);
50 void DeallocateFile();
51 void ReallocateFile(const char *f);
52 void CheckFlag(Flags_t chk, int flag);
53
54public:
55 MLog(int i=eStdout);
56 MLog(ofstream &out);
57 MLog(TGListBox &out);
58 MLog(const char *fname, int flag=-1);
59
60 MLog(MLog &log);
61
62 ~MLog()
63 {
64 DeallocateFile();
65 }
66
67 void SetDebugLevel(int i) { fDebugLevel = i; }
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=tmpnam(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(tmpnam(NULL));
124 return *fout;
125 }
126
127 ClassDef(MLog, 0) // This is what we call 'The logging system'
128};
129
130#endif
Note: See TracBrowser for help on using the repository browser.