1 // MED MEDMEM : MED files in memory
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MEDMEM_Exception.cxx
35 #include "utilities.h"
36 #include "MEDMEM_Exception.hxx"
48 Function used to duplicate char *
50 const char* duplicate( const char *const str ) ;
51 const char* duplicate( const char *const str )
54 const size_t length = strlen( str ) ;
56 char *new_str = new char[ 1+length ] ;
58 strcpy( new_str , str ) ;
63 \internal Default Constructor (Should not be used)
65 // ------------------------------------------------------ //
66 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
67 // ------------------------------------------------------ //
69 MESSAGE( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
76 Function used to elaborate the text of the MEDEXCEPTION
78 // --------------------------------------------------------------------------------------- //
79 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
80 // --------------------------------------------------------------------------------------- //
85 const size_t l1 = strlen(text) ;
87 const char* prefix = "MED Exception" ;
88 const size_t l0 = strlen(prefix) ;
92 const size_t l2 = strlen(fileName) ;
94 ASSERT(lineNumber>=1) ;
95 const size_t l3 = 1+int(log10(float(lineNumber))) ;
97 const size_t l4 = l0+l1+l2+l3+10+1 ;
98 newText = new char [ l4 ] ;
99 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
100 ASSERT(newText[l4-1] == '\0' );
105 newText = new char [ l0+l1+3+1 ] ;
106 sprintf( newText , "%s : %s" , prefix, text ) ;
114 It will create the text of the MEDEXCEPTION from the different parameters.
115 It will take the form : \n
116 MEDEXCEPTION, fileName, lineNumber and text of the exception
118 // ------------------------------------------------------------------------------------------------ //
119 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
120 exception(), _text( makeText( text , fileName , lineNumber ) )
121 // ------------------------------------------------------------------------------------------------ //
128 If necessary desallocates Memory
131 // ------------------------------------//
132 MEDEXCEPTION::~MEDEXCEPTION() throw ()
133 // ------------------------------------//
138 char *& txt = (char*)_text ;
141 ASSERT(_text==NULL) ;
146 Copy Constructor : \n
147 Should not be used very often
149 // ----------------------------------------------------------------------- //
150 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
151 // ----------------------------------------------------------------------- //
156 Operator << : put the message to the given stream.
158 // ------------------------------------------------------- //
159 ostream & operator<<( ostream &os , const MEDEXCEPTION &ex )
160 // ------------------------------------------------------- //
167 Return a char * which contain the message.
169 // ------------------------------------------------- //
170 const char* MEDEXCEPTION::what( void ) const throw ()
171 // ------------------------------------------------- //
177 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
180 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
183 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
185 const char *text, const char *fileName/*=0*/,
186 const unsigned int lineNumber/*=0*/
187 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
189 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};