CLHEP VERSION Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

ZMerrno.cc
Go to the documentation of this file.
1// ----------------------------------------------------------------------
2//
3// ZMerrno.cc -- implementation of the error list mechanism.
4//
5// The following are instantiated here:
6// ZMerrnoList ZMerrno;
7//
8// The following methods of ZMerrnoList are defined here:
9// void write(ZMexception& x);
10// const ZMexception* get(unsigned int k=0);
11// string name(unsigned int k=0);
12// void erase();
13// unsigned int setMax(unsigned int maxNumber);
14//
15// Revision History:
16// 970916 WEB Updated per code review
17// 970917 WEB Updated per code review 2
18// 971113 WEB Updated to conform to standard coding techniques
19// 980615 WEB Added namespace support
20// 980728 WEB Added destructor; fixed other memory leaks
21//
22// ----------------------------------------------------------------------
23
24
26
28
29
30namespace zmex {
31
32
33//********
34//
35// ZMerrno
36//
37//********
38
39ZMerrnoList ZMerrno;
40 // Define the actual ZMerrno instance !!
41
42
43//***************
44//
45// ~ZMerrnoList()
46//
47//***************
48
50
51 while ( size() > 0 ) {
52 const ZMexception * e = errors_.front();
53 errors_.pop_front();
54 delete const_cast<ZMexception *>( e );
55 }
56
57} // ZMerrnoList::~ZMerrnoList()
58
59
60//*************************
61//
62// write( ZMexception & x )
63//
64//*************************
65
67 // copy an exception onto ZMerrno
68
69 ++count_;
70 ++countSinceCleared_;
71
72 if ( max_ <= 0 ) {
73 return;
74 }
75
76 if ( max_ <= size() ) {
77 // Get rid of the oldest.
78 const ZMexception * e = errors_.front();
79 errors_.pop_front();
80 delete const_cast<ZMexception *>( e );
81 }
82
83 errors_.push_back( x.clone() );
84
85} // ZMerrnoList::write()
86
87
88//*******
89//
90// get(k)
91//
92//*******
93
94const ZMexception * ZMerrnoList::get( unsigned int k ) const {
95 // Obtain a const pointer to the exception for the latest-but-k entry
96 // on ZMerrno.
97 // Will be NULL if ZMerrno has been cleared since the last ZMthrow,
98 // and also if k is not less than ZMerrno.size().
99
100 return k < size() ? errors_[size()-1-k]
101 : 0;
102
103} // ZMerrnoList::get()
104
105
106//********
107//
108// name(k)
109//
110//********
111
112std::string ZMerrnoList::name( unsigned int k ) const {
113 // Obtain the mnemonic name of the latest-but-k exception on ZMerrno
114
115 return k < size() ? get(k)->name()
116 : std::string();
117
118} // ZMerrnoList::name()
119
120
121//********
122//
123// erase()
124//
125//********
126
127// Remove the latest entry.
128
130
131 if ( size() > 0 ) {
132 const ZMexception * e = errors_.back();
133 errors_.pop_back();
134 delete const_cast<ZMexception *>( e );
135 }
136
137} // ZMerrnoList::erase()
138
139
140//**********************************
141//
142// setMax (unsigned int maxNumber)
143//
144//**********************************
145
146unsigned int ZMerrnoList::setMax( unsigned int newMax ) {
147 // Set the maximum number of exceptions to be kept in the list.
148 // Zero completely disables the ZMerrno mechanism.
149
150 unsigned int oldMax = max_;
151 // If a reduction, you may have to pop some old entries off:
152 while ( newMax < size() ) {
153 const ZMexception * e = errors_.front();
154 errors_.pop_front();
155 delete const_cast<ZMexception *>( e );
156 }
157 max_ = newMax;
158 return oldMax;
159
160} // ZMerrnoList::setMax()
161
162
163} // namespace zmex
unsigned int setMax(unsigned int limit)
Definition: ZMerrno.cc:146
unsigned int size() const
void write(const ZMexception &x)
Definition: ZMerrno.cc:66
const ZMexception * get(unsigned int k=0) const
Definition: ZMerrno.cc:94
std::string name(unsigned int k=0) const
Definition: ZMerrno.cc:112
virtual ZMexception * clone() const
virtual std::string name() const
Definition: ZMexception.cc:104
ZMerrnoList ZMerrno