00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef DSC_EXCEPTION_HXX
00027 #define DSC_EXCEPTION_HXX
00028
00029 #include "Utils_SALOME_Exception.hxx"
00030 #include <string>
00031 #include <iostream>
00032 #include <sstream>
00033 #include <memory>
00034
00035 #include "utilities.h"
00036
00037 #ifndef WIN32
00038 extern "C"
00039 {
00040 #endif
00041 #include <string.h>
00042 #ifndef WIN32
00043 }
00044 #endif
00045
00046
00047 #if defined(_DEBUG_) || defined(_DEBUG)
00048 # ifdef __GNUC__
00049 # define LOC(message) (message), __FILE__ , __LINE__ , __FUNCTION__
00050 # else
00051 # define LOC(message) (message), __FILE__, __LINE__
00052 # endif
00053 #else
00054 # define LOC(message) (message)
00055 #endif
00056
00057
00058 #ifndef SWIG
00059
00063 class OSS
00064 {
00065 private:
00066 std::ostringstream oss_;
00067
00068 public:
00069 explicit OSS() : oss_() {}
00070
00071 template <class T>
00072 OSS & operator<<(T obj)
00073 {
00074 oss_ << obj;
00075 return *this;
00076 }
00077
00078 operator std::string()
00079 {
00080 return oss_.str();
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090 };
00091 #endif
00092
00093
00094
00095
00096 const char *makeText( const char *text, const char *fileName, const unsigned int lineNumber);
00097
00098 struct DSC_Exception : public SALOME_Exception {
00099
00100
00101
00102
00103
00104
00105
00106
00107 DSC_Exception( const std::string & text,
00108 const char *fileName="",
00109 const unsigned int lineNumber=0,
00110 const char *funcName="" ):
00111 SALOME_Exception(text.c_str()) ,
00112 _dscText(text),
00113 _filefuncName(setFileFuncName(fileName?fileName:"",funcName?funcName:"")),
00114 _lineNumber(lineNumber),
00115 _exceptionName("DSC_Exception")
00116 {
00117
00118 delete [] ((char*)SALOME_Exception::_text);
00119 if (! _filefuncName.empty() )
00120 SALOME_Exception::_text = makeText(text.c_str(),_filefuncName.c_str(),lineNumber) ;
00121 else
00122 SALOME_Exception::_text = makeText(text.c_str(),0,lineNumber) ;
00123
00124 OSS oss ;
00125 oss << _exceptionName ;
00126 if (!_filefuncName.empty() ) oss << " in " << _filefuncName;
00127 if (_lineNumber) oss << " [" << _lineNumber << "]";
00128 oss << " : " << _dscText;
00129 _what = oss;
00130 }
00131
00132 virtual const char* what( void ) const throw ()
00133 {
00134 return _what.c_str() ;
00135 }
00136
00137
00138
00139
00140
00141
00142 virtual ~DSC_Exception(void) throw() {};
00143
00144 virtual const std::string & getExceptionName() const {return _exceptionName;};
00145
00146 private:
00147
00148 std::string setFileFuncName(const char * fileName, const char * funcName) {
00149 ASSERT(fileName);
00150 ASSERT(funcName);
00151 OSS oss;
00152 if ( strcmp(fileName,"") )
00153 oss << fileName << "##" << funcName;
00154
00155 return oss;
00156 };
00157
00158
00159 protected:
00160 std::string _dscText;
00161 std::string _filefuncName;
00162 std::string _exceptionName;
00163 int _lineNumber;
00164 std::string _what;
00165 };
00166
00167 #define DSC_EXCEPTION(Derived) struct Derived : public DSC_Exception { \
00168 Derived ( const std::string & text, const char *fileName="", const unsigned int lineNumber=0, const char *funcName="" \
00169 ) : DSC_Exception(text,fileName,lineNumber,funcName) { \
00170 _exceptionName = #Derived; \
00171 } \
00172 virtual ~Derived(void) throw();\
00173 };\
00174
00175
00176
00177
00178 #define DSC_EXCEPTION_CXX(NameSpace,Derived) NameSpace::Derived::~Derived(void) throw() {};
00179
00180 #endif