ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TRedirectOutputGuard.h
Go to the documentation of this file.
1 // @(#)root/base:$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_TRedirectOutputGuard
13 #define ROOT_TRedirectOutputGuard
14 
15 //////////////////////////////////////////////////////////////////////////
16 // //
17 // TRedirectOutputGuard //
18 // //
19 // This class provides output redirection to a file in a guaranteed //
20 // exception safe way. Use like this: //
21 // { //
22 // TRedirectOutputGuard guard(filelog, mode); //
23 // ... // do something //
24 // } //
25 // when guard goes out of scope output is automatically redirected to //
26 // the standard units in the TRedirectOutputGuard destructor. //
27 // The exception mechanism takes care of calling the dtors //
28 // of local objects so it is exception safe. //
29 // The 'mode' options follow the fopen write modes convention; default //
30 // is "a". //
31 // //
32 //////////////////////////////////////////////////////////////////////////
33 
34 #ifndef ROOT_TSystem
35 #include "TSystem.h"
36 #endif
37 
39 
40  public:
41  TRedirectOutputGuard(const char *fout, const char *mode = "a")
42  { gSystem->RedirectOutput(fout, mode); }
44 
45  ClassDef(TRedirectOutputGuard,0) // Exception safe output redirection
46 };
47 
48 #endif
#define ClassDef(name, id)
Definition: Rtypes.h:254
R__EXTERN TSystem * gSystem
Definition: TSystem.h:545
virtual Int_t RedirectOutput(const char *name, const char *mode="a", RedirectHandle_t *h=0)
Redirect standard output (stdout, stderr) to the specified file.
Definition: TSystem.cxx:1625
TRedirectOutputGuard(const char *fout, const char *mode="a")