CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
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
25#include "CLHEP/Exceptions/ZMerrno.h"
26
27#include "CLHEP/Exceptions/ZMexception.h"
28
29#include <string>
30
31namespace zmex {
32
33
34//********
35//
36// ZMerrno
37//
38//********
39
41 // Define the actual ZMerrno instance !!
42
43
44//***************
45//
46// ~ZMerrnoList()
47//
48//***************
49
51
52 while ( size() > 0 ) {
53 const ZMexception * e = errors_.front();
54 errors_.pop_front();
55 delete const_cast<ZMexception *>( e );
56 }
57
58} // ZMerrnoList::~ZMerrnoList()
59
60
61//*************************
62//
63// write( ZMexception & x )
64//
65//*************************
66
68 // copy an exception onto ZMerrno
69
70 ++count_;
71 ++countSinceCleared_;
72
73 if ( max_ <= 0 ) {
74 return;
75 }
76
77 if ( max_ <= size() ) {
78 // Get rid of the oldest.
79 const ZMexception * e = errors_.front();
80 errors_.pop_front();
81 delete const_cast<ZMexception *>( e );
82 }
83
84 errors_.push_back( x.clone() );
85
86} // ZMerrnoList::write()
87
88
89//*******
90//
91// get(k)
92//
93//*******
94
95const ZMexception * ZMerrnoList::get( unsigned int k ) const {
96 // Obtain a const pointer to the exception for the latest-but-k entry
97 // on ZMerrno.
98 // Will be NULL if ZMerrno has been cleared since the last ZMthrow,
99 // and also if k is not less than ZMerrno.size().
100
101 return k < size() ? errors_[size()-1-k]
102 : 0;
103
104} // ZMerrnoList::get()
105
106
107//********
108//
109// name(k)
110//
111//********
112
113std::string ZMerrnoList::name( unsigned int k ) const {
114 // Obtain the mnemonic name of the latest-but-k exception on ZMerrno
115
116 return k < size() ? get(k)->name()
117 : std::string();
118
119} // ZMerrnoList::name()
120
121
122//********
123//
124// erase()
125//
126//********
127
128// Remove the latest entry.
129
131
132 if ( size() > 0 ) {
133 const ZMexception * e = errors_.back();
134 errors_.pop_back();
135 delete const_cast<ZMexception *>( e );
136 }
137
138} // ZMerrnoList::erase()
139
140
141//**********************************
142//
143// setMax (unsigned int maxNumber)
144//
145//**********************************
146
147unsigned int ZMerrnoList::setMax( unsigned int newMax ) {
148 // Set the maximum number of exceptions to be kept in the list.
149 // Zero completely disables the ZMerrno mechanism.
150
151 unsigned int oldMax = max_;
152 // If a reduction, you may have to pop some old entries off:
153 while ( newMax < size() ) {
154 const ZMexception * e = errors_.front();
155 errors_.pop_front();
156 delete const_cast<ZMexception *>( e );
157 }
158 max_ = newMax;
159 return oldMax;
160
161} // ZMerrnoList::setMax()
162
163
164} // namespace zmex
unsigned int setMax(unsigned int limit)
Definition: ZMerrno.cc:147
unsigned int size() const
void write(const ZMexception &x)
Definition: ZMerrno.cc:67
const ZMexception * get(unsigned int k=0) const
Definition: ZMerrno.cc:95
std::string name(unsigned int k=0) const
Definition: ZMerrno.cc:113
virtual ZMexception * clone() const
Definition: ZMexception.h:439
virtual std::string name() const
Definition: ZMexception.cc:106
Definition: ZMerrno.h:52
ZMerrnoList ZMerrno
Definition: ZMerrno.cc:40