1 // Copyright (C) 2007-2020 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, or (at your option) any later version.
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
23 // File : DSC_Exception.hxx
24 // Author : Eric Fayolle (EDF)
27 #ifndef DSC_EXCEPTION_HXX
28 #define DSC_EXCEPTION_HXX
30 #include "Utils_SALOME_Exception.hxx"
36 #include "utilities.h"
48 #if defined(_DEBUG_) || defined(_DEBUG)
50 # define LOC(message) (message), __FILE__ , __LINE__ , __FUNCTION__
52 # define LOC(message) (message), __FILE__, __LINE__
55 # define LOC(message) (message)
61 * Class OSS is useful when streaming data through a function
62 * that expect a string as parameter
67 std::ostringstream oss_;
70 explicit OSS() : oss_() {}
73 OSS & operator<<(T obj)
79 operator std::string()
84 // Surtout ne pas �crire le code suivant:
85 // car oss_.str() renvoie une string temporaire
86 // operator const char*()
88 // return oss_.str().c_str();
91 }; /* end class OSS */
94 struct DSC_Exception : public SALOME_Exception {
96 // Attention, en cas de modification des param�tres par d�faut
97 // il est necessaire de les repporter dans la macro DSC_EXCEPTION ci-dessous
98 // Le constructeur de la SALOME_Exception demande une chaine non vide
99 // Du coup on est obliger de la d�sallouer avant d'y mettre la notre
100 // car le what n'est pas virtuel donc il faut que le contenu de SALOME_Exception::_text
102 // Ne pas mettre lineNumber=0 � cause du calcul log dans la SALOME_Exception si fileName est d�fini
103 DSC_Exception( const std::string & text,
104 const char *fileName="",
105 const unsigned int lineNumber=0,
106 const char *funcName="" ):
107 SALOME_Exception(text) ,
109 _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
110 _lineNumber(lineNumber),
111 _exceptionName("DSC_Exception")
113 if (! _filefuncName.empty() )
114 SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
116 SALOME_Exception::_text = makeText(text.c_str(),0,lineNumber) ;
119 oss << _exceptionName ;
120 if (!_filefuncName.empty() ) oss << " in " << _filefuncName;
121 if (_lineNumber) oss << " [" << _lineNumber << "]";
122 oss << " : " << _dscText;
126 virtual const char* what( void ) const noexcept
128 return _what.c_str() ;
131 // L'op�rateur = de SALOME_Exception n'est pas d�fini
132 // probl�me potentiel concernant la recopie de son pointeur _text
134 // Le destructeur de la SALOME_Exception devrait �tre virtuel
135 // sinon pb avec nos attributs de type pointeur.
136 virtual ~DSC_Exception(void) noexcept {};
138 virtual const std::string & getExceptionName() const {return _exceptionName;};
142 std::string setFileFuncName(const char * fileName, const char * funcName) {
146 if ( strcmp(fileName,"") )
147 oss << fileName << "##" << funcName;
152 //DSC_Exception(void) {};
154 std::string _dscText;
155 std::string _filefuncName;
157 std::string _exceptionName;
161 #define DSC_EXCEPTION(Derived) struct Derived : public DSC_Exception { \
162 Derived ( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" \
163 ) : DSC_Exception(text,fileName,lineNumber,funcName) { \
164 _exceptionName = #Derived; \
166 virtual ~Derived(void) noexcept;\
169 //Sert � eviter le probl�me d'identification RTTI des exceptions
170 //Cr�e un unique typeInfo pour tous les biblioth�ques composants SALOME
171 //dans un fichier cxx
172 #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) noexcept {}
174 #endif /* DSC_EXCEPTION_HXX */