Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef ERRSTREAM_HH
#define ERRSTREAM_HH
//------------------------------------------------------------------------
//
// Description:
// Class ErrStream :
// This class encapsulates the ostream class and provives a
// way to "trap" messages by using "endmsg". This class is
// sub-classes by OstErrLogger/OstLogStream. When an "endmsg"
// is processed, the message is considered finished. "endmsg"
// is distinct from "endl" and '\n'.
//
// **********************************************************************
//
// Proper use:
// ErrStream should not be used directly. It should be
// accessed through the ErrLog interface.
//
// ErrMsg(warning) << "some resource not available" << endmsg;
//
// It is important to end all error messages with "endmsg".
// If a user does not finish an error message with "endmsg",
// a warning will be printed that looks like:
//
// *** ErrLogger Warning ***
// The ErrStream was previously used without
// endmsg being called to end the error message
// Please see ErrLogger/ErrStream.hh for more
// information.
//
// Error Location: ErrLogTest.cc::47
// *** ErrLogger Warning Finished ***
//
// If you see the above warning, you need to end your error
// message with << endmsg;, as described above.
//
// ***********************************************************************
//
// Environment:
// Software developed for the BaBar Detector at the SLAC B-Factory.
//
// Author List:
// Scott Metzler Original author
// $Id: ErrStream.hh,v 1.1.1.1 2005/03/29 17:04:19 steinke Exp $
//
// Copyright Information:
// Copyright (C) 1998-2004 California Institute of Technology
//
//------------------------------------------------------------------------
//-----------------
// C/C++ Headers --
//-----------------
#include <string>
//-------------------------------
// Collaborating Class Headers --
//-------------------------------
#include "ErrLogger/ErrLog.hh"
//------------------------------------
// Collaborating Class Declarations --
//------------------------------------
#include <iosfwd>
// ---------------------
// -- Class Interface --
// ---------------------
class ErrStream {
protected:
ErrStream( std::ostream*, ErrLog* );
ErrStream( const ErrStream& );
public:
virtual ~ErrStream() {}
void activate() {_self = this;}
// set this ErrStream object as the current one
// conversion operator
operator std::ostream&() { return *_myOstream; }
ErrLog::Severity severity() const { return _severity; }
const char* facility() const { return _facility.c_str(); }
int code() const { return _code; }
protected:
static ErrStream* activeStream() { return _self; }
// virtual methods
virtual void doEndmsg( ) = 0;
// helper functions
virtual void setStream( std::ostream* os ) { _myOstream = os; }
bool inUse() const { return _inUse; }
void setInUse(bool use) { _inUse = use; }
ErrLog* logger() { return _myLogger; }
void loggerEndmsg( const char* text ) { logger()->doEndmsg( text, *this ); }
// Set message parameters to keep around for endmsg. The facility string
// is copied to avoid pointer validity issues.
void setParameters( ErrLog::Severity severity,
const char* facility,
int code );
// This is a pass-through function for subclasses to use so that they
// can benefit from ErrStream's friendship with ErrLog.
void defaultTermination()
{ ErrLog::_defaultTermination( severity(), code() ); }
// friend relationships needed to implement "endmsg"
friend std::ostream& operator<<( std::ostream& os, void (*fp)(ErrStream& es) );
friend void endmsg( ErrStream& es );
friend class ErrLog;
// static variables
static ErrStream* _self;
static bool _inUse;
// member variables
std::ostream* _myOstream;
ErrLog* _myLogger;
ErrLog::Severity _severity;
std::string _facility;
int _code;
private:
// Disable assignment operator.
ErrStream& operator=( const ErrStream& );
};
#endif // ERRSTREAM_HH