ROOT logo
// @(#)root/base:$Id: TRedirectOutputGuard.h 20877 2007-11-19 11:17:07Z rdm $
// Author: G. Ganis   10/10/2005

/*************************************************************************
 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TRedirectOutputGuard
#define ROOT_TRedirectOutputGuard

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// TRedirectOutputGuard                                                 //
//                                                                      //
// This class provides output redirection to a file in a guaranteed     //
// exception safe way. Use like this:                                   //
// {                                                                    //
//    TRedirectOutputGuard guard(filelog, mode);                        //
//    ... // do something                                               //
// }                                                                    //
// when guard goes out of scope output is automatically redirected to   //
// the standard units in the TRedirectOutputGuard destructor.           //
// The exception mechanism takes care of calling the dtors              //
// of local objects so it is exception safe.                            //
// The 'mode' options follow the fopen write modes convention; default  //
// is "a".                                                              //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#ifndef ROOT_TSystem
#include "TSystem.h"
#endif

class TRedirectOutputGuard {

 public:
   TRedirectOutputGuard(const char *fout, const char *mode = "a")
                                   { gSystem->RedirectOutput(fout, mode); }
   virtual ~TRedirectOutputGuard() { gSystem->RedirectOutput(0); }

   ClassDef(TRedirectOutputGuard,0)  // Exception safe output redirection
};

#endif
 TRedirectOutputGuard.h:1
 TRedirectOutputGuard.h:2
 TRedirectOutputGuard.h:3
 TRedirectOutputGuard.h:4
 TRedirectOutputGuard.h:5
 TRedirectOutputGuard.h:6
 TRedirectOutputGuard.h:7
 TRedirectOutputGuard.h:8
 TRedirectOutputGuard.h:9
 TRedirectOutputGuard.h:10
 TRedirectOutputGuard.h:11
 TRedirectOutputGuard.h:12
 TRedirectOutputGuard.h:13
 TRedirectOutputGuard.h:14
 TRedirectOutputGuard.h:15
 TRedirectOutputGuard.h:16
 TRedirectOutputGuard.h:17
 TRedirectOutputGuard.h:18
 TRedirectOutputGuard.h:19
 TRedirectOutputGuard.h:20
 TRedirectOutputGuard.h:21
 TRedirectOutputGuard.h:22
 TRedirectOutputGuard.h:23
 TRedirectOutputGuard.h:24
 TRedirectOutputGuard.h:25
 TRedirectOutputGuard.h:26
 TRedirectOutputGuard.h:27
 TRedirectOutputGuard.h:28
 TRedirectOutputGuard.h:29
 TRedirectOutputGuard.h:30
 TRedirectOutputGuard.h:31
 TRedirectOutputGuard.h:32
 TRedirectOutputGuard.h:33
 TRedirectOutputGuard.h:34
 TRedirectOutputGuard.h:35
 TRedirectOutputGuard.h:36
 TRedirectOutputGuard.h:37
 TRedirectOutputGuard.h:38
 TRedirectOutputGuard.h:39
 TRedirectOutputGuard.h:40
 TRedirectOutputGuard.h:41
 TRedirectOutputGuard.h:42
 TRedirectOutputGuard.h:43
 TRedirectOutputGuard.h:44
 TRedirectOutputGuard.h:45
 TRedirectOutputGuard.h:46
 TRedirectOutputGuard.h:47
 TRedirectOutputGuard.h:48