CLHEP 2.0.4.7 Reference Documentation
   
CLHEP Home Page     CLHEP Documentation     CLHEP Bug Reports

ZMerrno.cc

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------
00002 //
00003 // ZMerrno.cc -- implementation of the error list mechanism.
00004 //
00005 // The following are instantiated here:
00006 //      ZMerrnoList ZMerrno;
00007 //
00008 // The following methods of ZMerrnoList are defined here:
00009 //      void write(ZMexception& x);
00010 //      const ZMexception* get(unsigned int k=0);
00011 //      string name(unsigned int k=0);
00012 //      void erase();
00013 //      unsigned int setMax(unsigned int maxNumber);
00014 //
00015 // Revision History:
00016 //   970916     WEB     Updated per code review
00017 //   970917     WEB     Updated per code review 2
00018 //   971113     WEB     Updated to conform to standard coding techniques
00019 //   980615     WEB     Added namespace support
00020 //   980728     WEB     Added destructor; fixed other memory leaks
00021 //
00022 // ----------------------------------------------------------------------
00023 
00024 
00025 #include "CLHEP/Exceptions/ZMerrno.h"
00026 
00027 #include "CLHEP/Exceptions/ZMexception.h"
00028 
00029 
00030 namespace zmex  {
00031 
00032 
00033 //********
00034 //
00035 // ZMerrno
00036 //
00037 //********
00038 
00039 ZMerrnoList ZMerrno;
00040   // Define the actual ZMerrno instance !!
00041 
00042 
00043 //***************
00044 //
00045 // ~ZMerrnoList()
00046 //
00047 //***************
00048 
00049 ZMerrnoList::~ZMerrnoList() {
00050 
00051   while ( size() > 0 )  {
00052     const ZMexception * e = errors_.front();
00053     errors_.pop_front();
00054     delete const_cast<ZMexception *>( e );
00055   }
00056 
00057 }  // ZMerrnoList::~ZMerrnoList()
00058 
00059 
00060 //*************************
00061 //
00062 // write( ZMexception & x )
00063 //
00064 //*************************
00065 
00066 void ZMerrnoList::write( const ZMexception & x ) {
00067   // copy an exception onto ZMerrno
00068 
00069   ++count_;
00070   ++countSinceCleared_;
00071 
00072   if ( max_ <= 0 ) {
00073     return;
00074   }
00075 
00076   if ( max_ <= size() ) {
00077     // Get rid of the oldest.
00078     const ZMexception * e = errors_.front();
00079     errors_.pop_front();
00080     delete const_cast<ZMexception *>( e );
00081   }
00082 
00083   errors_.push_back( x.clone() );
00084 
00085 }  // ZMerrnoList::write()
00086 
00087 
00088 //*******
00089 //
00090 // get(k)
00091 //
00092 //*******
00093 
00094 const ZMexception * ZMerrnoList::get( unsigned int k ) const {
00095   // Obtain a const pointer to the exception for the latest-but-k entry
00096   // on ZMerrno.
00097   // Will be NULL if ZMerrno has been cleared since the last ZMthrow,
00098   // and also if k is not less than ZMerrno.size().
00099 
00100   return  k < size() ? errors_[size()-1-k]
00101                      : 0;
00102 
00103 }  // ZMerrnoList::get()
00104 
00105 
00106 //********
00107 //
00108 // name(k)
00109 //
00110 //********
00111 
00112 std::string ZMerrnoList::name( unsigned int k ) const {
00113   // Obtain the mnemonic name of the latest-but-k exception on ZMerrno
00114 
00115   return  k < size() ? get(k)->name()
00116                      : std::string();
00117 
00118 }  // ZMerrnoList::name()
00119 
00120 
00121 //********
00122 //
00123 // erase()
00124 //
00125 //********
00126 
00127 // Remove the latest entry.
00128 
00129 void ZMerrnoList::erase() {
00130 
00131   if ( size() > 0 )  {
00132     const ZMexception * e = errors_.back();
00133     errors_.pop_back();
00134     delete const_cast<ZMexception *>( e );
00135   }
00136 
00137 }  // ZMerrnoList::erase()
00138 
00139 
00140 //**********************************
00141 //
00142 //  setMax (unsigned int maxNumber)
00143 //
00144 //**********************************
00145 
00146 unsigned int ZMerrnoList::setMax( unsigned int newMax ) {
00147   // Set the maximum number of exceptions to be kept in the list.
00148   // Zero completely disables the ZMerrno mechanism.
00149 
00150   unsigned int oldMax = max_;
00151   // If a reduction, you may have to pop some old entries off:
00152   while ( newMax < size() ) {
00153     const ZMexception * e = errors_.front();
00154     errors_.pop_front();
00155     delete const_cast<ZMexception *>( e );
00156   }
00157   max_ = newMax;
00158   return oldMax;
00159 
00160 }  // ZMerrnoList::setMax()
00161 
00162 
00163 }  // namespace zmex

Generated on Thu Jul 1 22:02:31 2010 for CLHEP by  doxygen 1.4.7