1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
27 #include "MEDMEM_Utilities.hxx"
28 #include "MEDMEM_Exception.hxx"
31 using namespace MEDMEM;
42 Function used to duplicate char *
44 char* duplicate( const char *const str ) ;
45 char* duplicate( const char *const str )
47 ASSERT_MED(str!=NULL) ;
48 const size_t length = strlen( str ) ;
49 ASSERT_MED(length>0) ;
50 char *new_str = new char[ 1+length ] ;
52 strcpy( new_str , str ) ;
57 \internal Default Constructor (Should not be used)
59 // ------------------------------------------------------ //
60 MEDEXCEPTION::MEDEXCEPTION( void ): exception() , _text(0)
61 // ------------------------------------------------------ //
63 MESSAGE_MED( "You must user the standard builder : MEDEXCEPTION::MEDEXCEPTION( const char *text )" ) ;
71 Function used to elaborate the text of the MEDEXCEPTION
73 // --------------------------------------------------------------------------------------- //
74 char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
75 // --------------------------------------------------------------------------------------- //
80 const size_t l1 = strlen(text) ;
82 const char* prefix = "MED Exception" ;
83 const size_t l0 = strlen(prefix) ;
87 const size_t l2 = strlen(fileName) ;
89 ASSERT_MED(lineNumber>=1) ;
90 const size_t l3 = 1+int(log10(float(lineNumber))) ;
92 const size_t l4 = l0+l1+l2+l3+10+1 ;
93 newText = new char [ l4 ] ;
94 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
95 ASSERT_MED(newText[l4-1] == '\0' );
100 newText = new char [ l0+l1+3+1 ] ;
101 sprintf( newText , "%s : %s" , prefix, text ) ;
103 ASSERT_MED(newText) ;
110 It will create the text of the MEDEXCEPTION from the different parameters.
111 It will take the form : \n
112 MEDEXCEPTION, fileName, lineNumber and text of the exception
114 // ------------------------------------------------------------------------------------------------ //
115 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
116 exception(), _text( makeText( text , fileName , lineNumber ) )
117 // ------------------------------------------------------------------------------------------------ //
124 If necessary desallocates Memory
127 // ------------------------------------//
128 MEDEXCEPTION::~MEDEXCEPTION() throw ()
129 // ------------------------------------//
136 ASSERT_MED(_text==NULL) ;
141 Copy Constructor : \n
142 Should not be used very often
144 // ----------------------------------------------------------------------- //
145 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
146 // ----------------------------------------------------------------------- //
151 Operator << : put the message to the given stream.
153 // ------------------------------------------------------- //
154 ostream & MEDMEM::operator<<( ostream &os , const MEDEXCEPTION &ex )
155 // ------------------------------------------------------- //
162 Return a char * which contain the message.
164 // ------------------------------------------------- //
165 const char* MEDEXCEPTION::what( void ) const throw ()
166 // ------------------------------------------------- //
172 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
175 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {}
178 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
180 const char *text, const char *fileName/*=0*/,
181 const unsigned int lineNumber/*=0*/
182 ) : MEDEXCEPTION(text, fileName, lineNumber) {}
184 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){}