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
22 // File : DSC_Exception.hxx
23 // Author : Eric Fayolle (EDF)
26 #ifndef DSC_EXCEPTION_HXX
27 #define DSC_EXCEPTION_HXX
29 #include "Utils_SALOME_Exception.hxx"
35 #include "utilities.h"
47 #if defined(_DEBUG_) || defined(_DEBUG)
49 # define LOC(message) (message), __FILE__ , __LINE__ , __FUNCTION__
51 # define LOC(message) (message), __FILE__, __LINE__
54 # define LOC(message) (message)
60 * Class OSS is useful when streaming data through a function
61 * that expect a string as parameter
66 std::ostringstream oss_;
69 explicit OSS() : oss_() {}
72 OSS & operator<<(T obj)
78 operator std::string()
83 // Surtout ne pas écrire le code suivant:
84 // car oss_.str() renvoie une string temporaire
85 // operator const char*()
87 // return oss_.str().c_str();
90 }; /* end class OSS */
94 // Cette fonction provient de Utils_SALOME_Exception
95 // Solution pas très élégante mais contrainte par les manques de la classe SALOME_Exception
96 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber);
98 struct DSC_Exception : public SALOME_Exception {
100 // Attention, en cas de modification des paramètres par défaut
101 // il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous
102 // Le constructeur de la SALOME_Exception demande une chaine non vide
103 // Du coup on est obliger de la désallouer avant d'y mettre la notre
104 // car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text
106 // Ne pas mettre lineNumber=0 à cause du calcul log dans la SALOME_Exception si fileName est défini
107 DSC_Exception( const std::string & text,
108 const char *fileName="",
109 const unsigned int lineNumber=0,
110 const char *funcName="" ):
111 SALOME_Exception(text.c_str()) ,
113 _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
114 _lineNumber(lineNumber),
115 _exceptionName("DSC_Exception")
117 // Mise en cohérence avec l'exception SALOME (à revoir)
118 delete [] ((char*)SALOME_Exception::_text);
119 if (! _filefuncName.empty() )
120 SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
122 SALOME_Exception::_text = makeText(text.c_str(),0,lineNumber) ;
125 oss << _exceptionName ;
126 if (!_filefuncName.empty() ) oss << " in " << _filefuncName;
127 if (_lineNumber) oss << " [" << _lineNumber << "]";
128 oss << " : " << _dscText;
132 virtual const char* what( void ) const throw ()
134 return _what.c_str() ;
137 // L'opérateur = de SALOME_Exception n'est pas défini
138 // problème potentiel concernant la recopie de son pointeur _text
140 // Le destructeur de la SALOME_Exception devrait être virtuel
141 // sinon pb avec nos attributs de type pointeur.
142 virtual ~DSC_Exception(void) throw() {};
144 virtual const std::string & getExceptionName() const {return _exceptionName;};
148 std::string setFileFuncName(const char * fileName, const char * funcName) {
152 if ( strcmp(fileName,"") )
153 oss << fileName << "##" << funcName;
158 //DSC_Exception(void) {};
160 std::string _dscText;
161 std::string _filefuncName;
162 std::string _exceptionName;
167 #define DSC_EXCEPTION(Derived) struct Derived : public DSC_Exception { \
168 Derived ( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" \
169 ) : DSC_Exception(text,fileName,lineNumber,funcName) { \
170 _exceptionName = #Derived; \
172 virtual ~Derived(void) throw();\
175 //Sert à eviter le problème d'identification RTTI des exceptions
176 //Crée un unique typeInfo pour tous les bibliothèques composants SALOME
177 //dans un fichier cxx
178 #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) throw() {};
180 #endif /* DSC_EXCEPTION_HXX */