1 // Copyright (C) 2007-2008 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 )" ) ;
70 Function used to elaborate the text of the MEDEXCEPTION
72 // --------------------------------------------------------------------------------------- //
73 char *makeText( const char *text, const char *fileName, const unsigned int lineNumber )
74 // --------------------------------------------------------------------------------------- //
79 const size_t l1 = strlen(text) ;
81 const char* prefix = "MED Exception" ;
82 const size_t l0 = strlen(prefix) ;
86 const size_t l2 = strlen(fileName) ;
88 ASSERT_MED(lineNumber>=1) ;
89 const size_t l3 = 1+int(log10(float(lineNumber))) ;
91 const size_t l4 = l0+l1+l2+l3+10+1 ;
92 newText = new char [ l4 ] ;
93 sprintf( newText , "%s in %s [%u] : %s" , prefix, fileName, lineNumber, text ) ;
94 ASSERT_MED(newText[l4-1] == '\0' );
99 newText = new char [ l0+l1+3+1 ] ;
100 sprintf( newText , "%s : %s" , prefix, text ) ;
102 ASSERT_MED(newText) ;
108 It will create the text of the MEDEXCEPTION from the different parameters.
109 It will take the form : \n
110 MEDEXCEPTION, fileName, lineNumber and text of the exception
112 // ------------------------------------------------------------------------------------------------ //
113 MEDEXCEPTION::MEDEXCEPTION( const char *text, const char *fileName, const unsigned int lineNumber ) :
114 exception(), _text( makeText( text , fileName , lineNumber ) )
115 // ------------------------------------------------------------------------------------------------ //
122 If necessary desallocates Memory
125 // ------------------------------------//
126 MEDEXCEPTION::~MEDEXCEPTION() throw ()
127 // ------------------------------------//
134 ASSERT_MED(_text==NULL) ;
139 Copy Constructor : \n
140 Should not be used very often
142 // ----------------------------------------------------------------------- //
143 MEDEXCEPTION::MEDEXCEPTION( const MEDEXCEPTION &ex ): _text(duplicate(ex._text))
144 // ----------------------------------------------------------------------- //
149 Operator << : put the message to the given stream.
151 // ------------------------------------------------------- //
152 ostream & MEDMEM::operator<<( ostream &os , const MEDEXCEPTION &ex )
153 // ------------------------------------------------------- //
160 Return a char * which contain the message.
162 // ------------------------------------------------- //
163 const char* MEDEXCEPTION::what( void ) const throw ()
164 // ------------------------------------------------- //
170 // -------------------- class MED_DRIVER_NOT_FOUND_EXCEPTION
173 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION(const MED_DRIVER_NOT_FOUND_EXCEPTION &ex ):MEDEXCEPTION ( ex ) {};
176 MED_DRIVER_NOT_FOUND_EXCEPTION::MED_DRIVER_NOT_FOUND_EXCEPTION
178 const char *text, const char *fileName/*=0*/,
179 const unsigned int lineNumber/*=0*/
180 ) : MEDEXCEPTION(text, fileName, lineNumber) {};
182 MED_DRIVER_NOT_FOUND_EXCEPTION::~MED_DRIVER_NOT_FOUND_EXCEPTION() throw (){};