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

CLHEP/Exceptions/ZMexHandler.h
Go to the documentation of this file.
1 #ifndef ZMEXHANDLER_H
2 #define ZMEXHANDLER_H
3 
4 
5 // ----------------------------------------------------------------------
6 //
7 // ZMexHandler.h - interface class declarations for the ZOOM Exception
8 // Handler base class and the basic handlers:
9 // ZMexThrowAlways
10 // ZMexIgnoreAlways
11 // ZMexThrowErrors
12 // ZMexIgnoreNextN
13 // ZMexHandleViaParent
14 // These can be used as examples if custom handlers are desired.
15 //
16 // Revision History:
17 // 970909 MF Initial version
18 // 970916 WEB Updated per code review
19 // 970917 WEB Updated per code review 2
20 // 970923 WEB Updated per code review 4
21 // 971008 WEB ZMutility is the new name for the Utility package
22 // 971112 WEB Updated for conformance to standard and the zoom
23 // compatability headers
24 // 980615 WEB Added namespace support
25 // 990318 MF Modified intializer list orders to avoid warnings
26 // 000217 WEB Improve C++ standards compliance
27 // 000503 WEB Avoid global using
28 // 031105 LG Get rid of all ZMutility references
29 //
30 // ----------------------------------------------------------------------
31 
32 #ifndef STRING_INCLUDED
33  #define STRING_INCLUDED
34  #include <string>
35 #endif
36 
37 #ifndef ZMHANDLETO_H
38  #include "CLHEP/RefCount/ZMhandleTo.h"
39 #endif
40 
41 #ifndef ZMEXSEVERITY_H
43 #endif
44 
45 #ifndef ZMEXACTION_H
47 #endif
48 
49 
50 namespace zmex {
51 
52 
53 class ZMexception;
54 
55 
56 //********************
57 //
58 // ZMexHandlerBehavior
59 //
60 //********************
61 
63  // Handler behavior interface definition
64 
65 public:
67  const std::string aname = "ZMexHandlerBehavior"
68  ) : name_( aname ) { }
69 
70  virtual ~ZMexHandlerBehavior() { }
71 
72  virtual ZMexHandlerBehavior * clone() const {
73  return new ZMexHandlerBehavior( *this );
74  }
75 
76  virtual std::string name() const { return name_; }
77  virtual ZMexAction takeCareOf( const ZMexception & x ) { return ZMexThrowIt; }
78 
79 protected:
80  /*virtual void handleLog( ZMexception & x, const int limit );*/
81  ZMexAction standardHandling( const ZMexception & x, bool willThrow );
82 
83 private:
84  const std::string name_;
85 
86 }; // ZMexHandlerBehavior
87 
88 
89 
90 //************
91 //
92 // ZMexHandler
93 //
94 //************
95 
96 class ZMexHandler : public ZMhandleTo< ZMexHandlerBehavior > {
97  // Handler interface
98 
99 public:
101  const ZMexHandlerBehavior & behaviorWanted
102  ) :
103  ZMhandleTo<ZMexHandlerBehavior>( behaviorWanted )
104  { }
105 
106  virtual ~ZMexHandler() { }
107 
108  std::string name() const {
109  return rep_->name();
110  }
111 
112  virtual ZMexAction takeCareOf( const ZMexception & x ) {
113  return rep_->takeCareOf(x);
114  }
115 
116  int setLogLimit( ZMexSeverity s, int limit ) {
117  int lim = ZMexSeverityLimit[ s ];
118  ZMexSeverityLimit[ s ] = limit;
119  return lim;
120  }
121 
122 }; // ZMexHandler
123 
124 
125 
126 //****************
127 //
128 // ZMexThrowAlways
129 //
130 //****************
131 
133 
134 public:
135  ZMexThrowAlways() : ZMexHandlerBehavior( "ZMexThrowAlways" ) { }
136  virtual ZMexThrowAlways * clone() const;
137  virtual ZMexAction takeCareOf( const ZMexception & x );
138 };
139 
140 
141 //****************
142 //
143 // ZMexThrowErrors
144 //
145 //****************
146 
148 
149 public:
150  ZMexThrowErrors() : ZMexHandlerBehavior( "ZMexThrowErrors" ) { }
151  virtual ZMexThrowErrors * clone() const;
152  virtual ZMexAction takeCareOf( const ZMexception & x );
153 };
154 
155 
156 //*****************
157 //
158 // ZMexIgnoreAlways
159 //
160 //*****************
161 
163 
164 public:
165  ZMexIgnoreAlways() : ZMexHandlerBehavior( "ZMexIgnoreAlways" ) { }
166  virtual ZMexIgnoreAlways * clone() const;
167  virtual ZMexAction takeCareOf( const ZMexception & x );
168 };
169 
170 
171 //*****************
172 //
173 // ZMexIgnoreNextN
174 //
175 //*****************
176 
178 
179 public:
181  ZMexHandlerBehavior( "ZMexIgnoreNextN" ),
182  countDown_( n )
183  { }
184  virtual ZMexIgnoreNextN * clone() const;
185  virtual ZMexAction takeCareOf( const ZMexception & x );
186 
187 private:
188  int countDown_;
189 };
190 
191 
192 //******************
193 //
194 // ZMexHandleViaParent
195 //
196 //******************
197 
199 public:
201  virtual ZMexHandleViaParent * clone() const;
202  virtual ZMexAction takeCareOf( const ZMexception & x );
203 };
204 
205 
206 } // namespace zmex
207 
208 
209 #define ZMEXHANDLER_ICC
210 #include "CLHEP/Exceptions/ZMexHandler.icc"
211 #undef ZMEXHANDLER_ICC
212 
213 
214 #endif // ZMEXHANDLER_H