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

Exception.cpp

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.cpp
00008    Version  : $Revision: 1.6 $
00009    Author   : $Author: darkeye $
00010    Location : $Source: /cvsroot/darkice/darkice/src/Exception.cpp,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 
00030 /* ============================================================ include files */
00031 
00032 #ifdef HAVE_CONFIG_H
00033 #include "config.h"
00034 #endif
00035 
00036 #ifdef HAVE_STRING_H
00037 #include <string.h>
00038 #else
00039 #error need string.h
00040 #endif
00041 
00042 
00043 #include "Exception.h"
00044 
00045 
00046 /* ===================================================  local data structures */
00047 
00048 
00049 /* ================================================  local constants & macros */
00050 
00051 /*------------------------------------------------------------------------------
00052  *  File identity
00053  *----------------------------------------------------------------------------*/
00054 static const char fileid[] = "$Id: Exception.cpp,v 1.6 2002/05/28 12:35:41 darkeye Exp $";
00055 
00056 
00057 /* ===============================================  local function prototypes */
00058 
00059 
00060 /* =============================================================  module code */
00061 
00062 /*------------------------------------------------------------------------------
00063  *  Constructor
00064  *----------------------------------------------------------------------------*/
00065 Exception :: Exception (    const char            * file,
00066                             unsigned int            line,
00067                             const char            * description1,
00068                             const char            * description2,
00069                             int                     code )          throw ()
00070 {
00071     size_t      len = 0;
00072 
00073     if ( description1 ) {
00074         len += strlen( description1);
00075     }
00076     if ( description2 ) {
00077         len += strlen( description2);
00078     }
00079 
00080     if ( len ) {
00081         char      * str = new char[len+1];
00082 
00083         str[0] = '\0';
00084         if ( description1 ) {
00085             strcat( str, description1);
00086         }
00087         if ( description2 ) {
00088             strcat( str, description2);
00089         }
00090 
00091         init( file, line, str, code);
00092         delete[] str;
00093 
00094     } else {
00095 
00096         init( file, line, 0, code);
00097     }
00098 }
00099 
00100 
00101 /*------------------------------------------------------------------------------
00102  *  Constructor
00103  *----------------------------------------------------------------------------*/
00104 Exception :: Exception (    const char            * file,
00105                             unsigned int            line,
00106                             const char            * description1,
00107                             const char            * description2,
00108                             const char            * description3,
00109                             int                     code )          throw ()
00110 {
00111     size_t      len = 0;
00112 
00113     if ( description1 ) {
00114         len += strlen( description1);
00115     }
00116     if ( description2 ) {
00117         len += strlen( description2);
00118     }
00119     if ( description3 ) {
00120         len += strlen( description3);
00121     }
00122 
00123     if ( len ) {
00124         char      * str = new char[len+1];
00125 
00126         str[0] = '\0';
00127         if ( description1 ) {
00128             strcat( str, description1);
00129         }
00130         if ( description2 ) {
00131             strcat( str, description2);
00132         }
00133         if ( description3 ) {
00134             strcat( str, description3);
00135         }
00136 
00137         init( file, line, str, code);
00138         delete[] str;
00139 
00140     } else {
00141 
00142         init( file, line, 0, code);
00143     }
00144 }
00145 
00146 
00147 /*------------------------------------------------------------------------------
00148  *  Initialize the class
00149  *----------------------------------------------------------------------------*/
00150 void
00151 Exception :: init ( const char            * file,
00152                     unsigned int            line,
00153                     const char            * description  = 0,
00154                     int                     code         = 0 )  throw ()
00155 {
00156     if ( !file ) {
00157         this->file = 0;
00158     } else {
00159         size_t  len;
00160         
00161         len        = strlen( file ) + 1;
00162         this->file = new char[len];
00163         if ( this->file ) {
00164             memcpy( this->file, file, len);
00165         }
00166     }
00167 
00168     if ( !description ) {
00169         this->description = 0;
00170     } else {
00171         size_t  len;
00172         
00173         len               = strlen( description ) + 1;
00174         this->description = new char[len];
00175         if ( this->description ) {
00176             memcpy( this->description, description, len);
00177         }
00178     }
00179 
00180     this->line = line;
00181     this->code = code;
00182 }
00183 
00184 
00185 /*------------------------------------------------------------------------------
00186  *  De-initialize the class
00187  *----------------------------------------------------------------------------*/
00188 void
00189 Exception :: strip ( void )                         throw ()
00190 {
00191     if ( description ) {
00192         delete[] description;
00193     }
00194 
00195     if ( file ) {
00196         delete[] file;
00197     }
00198 }
00199 
00200 
00201 
00202 
00203 /*------------------------------------------------------------------------------
00204  
00205   $Source: /cvsroot/darkice/darkice/src/Exception.cpp,v $
00206 
00207   $Log: Exception.cpp,v $
00208   Revision 1.6  2002/05/28 12:35:41  darkeye
00209   code cleanup: compiles under gcc-c++ 3.1, using -pedantic option
00210 
00211   Revision 1.5  2001/08/30 17:25:56  darkeye
00212   renamed configure.h to config.h
00213 
00214   Revision 1.4  2000/11/11 12:33:13  darkeye
00215   added kdoc-style documentation
00216 
00217   Revision 1.3  2000/11/09 22:05:44  darkeye
00218   added multiple-string constructors
00219 
00220   Revision 1.2  2000/11/05 14:08:27  darkeye
00221   changed builting to an automake / autoconf environment
00222 
00223   Revision 1.1.1.1  2000/11/05 10:05:50  darkeye
00224   initial version
00225 
00226   
00227 ------------------------------------------------------------------------------*/
00228 

Generated on Sat Oct 22 13:17:04 2005 for DarkIce by  doxygen 1.4.4