Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGRedirectOutputGuard.h
Go to the documentation of this file.
1 // @(#)root/gui:$Id$
2 // Author: G. Ganis 10/10/2005
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TGRedirectOutputGuard
13 #define ROOT_TGRedirectOutputGuard
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TGRedirectOutputGuard //
18 // //
19 // This class provides output redirection to a TGTextView in guaranteed //
20 // exception safe way. Use like this: //
21 // { //
22 // TGRedirectOutputGuard guard(textview); //
23 // ... // do something //
24 // guard.Update(); //
25 // ... // do something else //
26 // } //
27 // when guard goes out of scope, Update() is called to flush what left //
28 // on the screed and the output is automatically redirected again to //
29 // the standard units. //
30 // The exception mechanism takes care of calling the dtors //
31 // of local objects so it is exception safe. //
32 // Optionally the output can also be saved into a file: //
33 // { //
34 // TGRedirectOutputGuard guard(textview, file, mode); //
35 // ... // do something //
36 // } //
37 // //
38 //////////////////////////////////////////////////////////////////////////
39 
40 #include "TString.h"
41 
42 class TGTextView;
43 
44 class TGRedirectOutputGuard {
45 
46 private:
47  TString fLogFile;
48  Bool_t fTmpFile;
49  TGTextView *fTextView;
50  FILE *fLogFileRead;
51 
52 private:
53  TGRedirectOutputGuard(const TGRedirectOutputGuard&); // Not implemented.
54  TGRedirectOutputGuard &operator=(const TGRedirectOutputGuard&); // Not implemented.
55 
56 public:
57  TGRedirectOutputGuard(TGTextView *tv,
58  const char *flog = 0, const char *mode = "a");
59  virtual ~TGRedirectOutputGuard();
60 
61  void Update(); // Update window with file content
62 
63  ClassDef(TGRedirectOutputGuard,0) // Exception safe output redirection
64 };
65 
66 #endif