Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

Exception.h

Go to the documentation of this file.
00001 /*------------------------------------------------------------------------------
00002 
00003    Copyright (c) 2000 Tyrell Corporation. All rights reserved.
00004 
00005    Tyrell DarkIce
00006 
00007    File     : Exception.h
00008    Version  : $Revision: 1.6 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/Exception.h,v $
00011    
00012    Copyright notice:
00013 
00014     This program is free software; you can redistribute it and/or
00015     modify it under the terms of the GNU General Public License  
00016     as published by the Free Software Foundation; either version 2
00017     of the License, or (at your option) any later version.
00018    
00019     This program is distributed in the hope that it will be useful,
00020     but WITHOUT ANY WARRANTY; without even the implied warranty of 
00021     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
00022     GNU General Public License for more details.
00023    
00024     You should have received a copy of the GNU General Public License
00025     along with this program; if not, write to the Free Software
00026     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 
00028 ------------------------------------------------------------------------------*/
00029 #ifndef EXCEPTION_H
00030 #define EXCEPTION_H
00031 
00032 #ifndef __cplusplus
00033 #error This is a C++ include file
00034 #endif
00035 
00036 
00037 /* ============================================================ include files */
00038 
00039 #include <iostream>
00040 
00041 
00042 /* ================================================================ constants */
00043 
00044 
00045 /* =================================================================== macros */
00046 
00047 
00048 /* =============================================================== data types */
00049 
00065 class Exception
00066 {
00067     private:
00068 
00072         char          * file;
00073 
00077         unsigned int    line;
00078 
00082         char          * description;
00083 
00087         int             code;
00088 
00097         void
00098         init (  const char            * file,
00099                 unsigned int            line,
00100                 const char            * description,
00101                 int                     code )              throw ();
00102 
00106         void
00107         strip ()                                            throw ();
00108 
00109 
00110     protected:
00111 
00112 
00113     public:
00114 
00118         inline
00119         Exception ( void )                                  throw ()
00120         {
00121             init( 0, 0, 0, 0);
00122         }
00123 
00127         inline
00128         Exception ( const Exception &   e )                 throw ()
00129         {
00130             init( e.file, e.line, e.description, e.code);
00131         }
00132 
00139         inline
00140         Exception ( const char            * description,
00141                     int                     code = 0 )      throw ()
00142         {
00143             init( 0, 0, description, code);
00144         }
00145 
00154         inline
00155         Exception ( const char            * file,
00156                     unsigned int            line,
00157                     const char            * description  = 0,
00158                     int                     code = 0 )          throw ()
00159         {
00160             init( file, line, description, code);
00161         }
00162 
00174         Exception ( const char            * file,
00175                     unsigned int            line,
00176                     const char            * description1,
00177                     const char            * description2,
00178                     int                     code = 0 )          throw ();
00179 
00192         Exception ( const char            * file,
00193                     unsigned int            line,
00194                     const char            * description1,
00195                     const char            * description2,
00196                     const char            * description3,
00197                     int                     code = 0 )          throw ();
00198 
00202         inline
00203         ~Exception ( void )                                 throw ()
00204         {
00205             strip();
00206         }
00207 
00214         inline Exception &
00215         operator= ( const Exception &   e )                 throw ()
00216         {
00217             if ( this != &e ) {
00218                 strip();
00219                 init( e.file, e.line, e.description, e.code);
00220             }
00221 
00222             return *this;
00223         }
00224 
00230         inline const char *
00231         getDescription( void ) const                        throw ()
00232         {
00233             return description;
00234         }
00235 
00243         inline unsigned int
00244         getLine ( void ) const                              throw ()
00245         {
00246             return line;
00247         }
00248 
00254         inline const char *
00255         getFile ( void ) const                              throw ()
00256         {
00257             return file;
00258         }
00259 
00265         inline int
00266         getCode ( void ) const                              throw ()
00267         {
00268             return code;
00269         }
00270 };
00271 
00272 
00273 /* ================================================= external data structures */
00274 
00275 
00276 /* ====================================================== function prototypes */
00277 
00285 inline std::ostream &
00286 operator<< (        std::ostream &      os,
00287                     const Exception &   e )
00288 {
00289     os << e.getFile() << ":" << e.getLine() << ": "
00290        << e.getDescription() << " [" << e.getCode() << "]";
00291 
00292     return os;
00293 }
00294 
00295 
00296 
00297 #endif  /* EXCEPTION_H */
00298 
00299 
00300 /*------------------------------------------------------------------------------
00301  
00302   $Source: /cvsroot/darkice/darkice/src/Exception.h,v $
00303 
00304   $Log: Exception.h,v $
00305   Revision 1.6  2002/05/28 12:35:41  darkeye
00306   code cleanup: compiles under gcc-c++ 3.1, using -pedantic option
00307 
00308   Revision 1.5  2000/11/17 15:33:54  darkeye
00309   bug fix: ostream << operator overload didn't return the ostream
00310 
00311   Revision 1.4  2000/11/11 12:33:13  darkeye
00312   added kdoc-style documentation
00313 
00314   Revision 1.3  2000/11/09 22:05:44  darkeye
00315   added multiple-string constructors
00316 
00317   Revision 1.2  2000/11/05 14:08:27  darkeye
00318   changed builting to an automake / autoconf environment
00319 
00320   Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
00321   initial version
00322 
00323   
00324 ------------------------------------------------------------------------------*/
00325 

Generated on Fri May 19 15:36:48 2006 for DarkIce by  doxygen 1.4.4