CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes
CloseCoutSentry Class Reference

#include <CloseCoutSentry.h>

Public Member Functions

void clear ()
 
 CloseCoutSentry (bool silent=true)
 
FILE * trueStdOut ()
 
 ~CloseCoutSentry ()
 

Static Public Member Functions

static void breakFree ()
 

Static Private Member Functions

static void reallyClear ()
 

Private Attributes

bool silent_
 
bool stdOutIsMine_
 

Static Private Attributes

static int fdErr_ = 0
 
static int fdOut_ = 0
 
static bool open_ = true
 
static FILE * trueStdOut_ = 0
 

Detailed Description

This class redirects cout and cerr to /dev/null when created, and restores them back when destroyed.

Definition at line 7 of file CloseCoutSentry.h.

Constructor & Destructor Documentation

CloseCoutSentry::CloseCoutSentry ( bool  silent = true)

Definition at line 11 of file CloseCoutSentry.cc.

References fdErr_, fdOut_, open_, and silent_.

11  :
12  silent_(silent), stdOutIsMine_(false)
13 {
14  if (silent_) {
15  if (open_) {
16  open_ = false;
17  if (fdOut_ == 0 && fdErr_ == 0) {
18  fdOut_ = dup(1);
19  fdErr_ = dup(2);
20  }
21  freopen("/dev/null", "w", stdout);
22  freopen("/dev/null", "w", stderr);
23  } else {
24  silent_ = false;
25  }
26  }
27 }
static int fdErr_
static bool open_
static int fdOut_
CloseCoutSentry::~CloseCoutSentry ( )

Definition at line 29 of file CloseCoutSentry.cc.

References clear().

30 {
31  clear();
32 }

Member Function Documentation

void CloseCoutSentry::breakFree ( )
static

Definition at line 54 of file CloseCoutSentry.cc.

References reallyClear().

55 {
56  reallyClear();
57 }
static void reallyClear()
void CloseCoutSentry::clear ( void  )
void CloseCoutSentry::reallyClear ( )
staticprivate

Definition at line 43 of file CloseCoutSentry.cc.

References fdErr_, fdOut_, and open_.

Referenced by breakFree(), and clear().

44 {
45  if (fdOut_ != fdErr_) {
46  char buf[50];
47  sprintf(buf, "/dev/fd/%d", fdOut_); freopen(buf, "w", stdout);
48  sprintf(buf, "/dev/fd/%d", fdErr_); freopen(buf, "w", stderr);
49  open_ = true;
50  fdOut_ = fdErr_ = 0;
51  }
52 }
static int fdErr_
static bool open_
static int fdOut_
FILE * CloseCoutSentry::trueStdOut ( )

Definition at line 59 of file CloseCoutSentry.cc.

References fdOut_, open_, stdOutIsMine_, and trueStdOut_.

Referenced by MultiDimFit::doGrid().

60 {
61  if (open_) return stdout;
62  if (trueStdOut_) return trueStdOut_;
63  stdOutIsMine_ = true;
64  char buf[50];
65  sprintf(buf, "/dev/fd/%d", fdOut_); trueStdOut_ = fopen(buf, "w");
66  return trueStdOut_;
67 }
static FILE * trueStdOut_
static bool open_
static int fdOut_

Member Data Documentation

int CloseCoutSentry::fdErr_ = 0
staticprivate

Definition at line 18 of file CloseCoutSentry.h.

Referenced by CloseCoutSentry(), and reallyClear().

int CloseCoutSentry::fdOut_ = 0
staticprivate

Definition at line 18 of file CloseCoutSentry.h.

Referenced by CloseCoutSentry(), reallyClear(), and trueStdOut().

bool CloseCoutSentry::open_ = true
staticprivate

Definition at line 19 of file CloseCoutSentry.h.

Referenced by CloseCoutSentry(), reallyClear(), and trueStdOut().

bool CloseCoutSentry::silent_
private

Definition at line 17 of file CloseCoutSentry.h.

Referenced by clear(), and CloseCoutSentry().

bool CloseCoutSentry::stdOutIsMine_
private

Definition at line 23 of file CloseCoutSentry.h.

Referenced by clear(), and trueStdOut().

FILE * CloseCoutSentry::trueStdOut_ = 0
staticprivate

Definition at line 22 of file CloseCoutSentry.h.

Referenced by clear(), and trueStdOut().