]> git.stg.codes - stg.git/blobdiff - libs/ibpp/exception.cpp
Port to CMake, get rid of os_int.h.
[stg.git] / libs / ibpp / exception.cpp
diff --git a/libs/ibpp/exception.cpp b/libs/ibpp/exception.cpp
new file mode 100644 (file)
index 0000000..aa47e28
--- /dev/null
@@ -0,0 +1,351 @@
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     File    : $Id: exception.cpp,v 1.1 2007/05/05 17:00:42 faust Exp $\r
+//     Subject : IBPP, Initialization of the library\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     (C) Copyright 2000-2006 T.I.P. Group S.A. and the IBPP Team (www.ibpp.org)\r
+//\r
+//     The contents of this file are subject to the IBPP License (the "License");\r
+//     you may not use this file except in compliance with the License.  You may\r
+//     obtain a copy of the License at http://www.ibpp.org or in the 'license.txt'\r
+//     file which must have been distributed along with this file.\r
+//\r
+//     This software, distributed under the License, is distributed on an "AS IS"\r
+//     basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the\r
+//     License for the specific language governing rights and limitations\r
+//     under the License.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+//\r
+//     COMMENTS\r
+//     * Tabulations should be set every four characters when editing this file.\r
+//\r
+///////////////////////////////////////////////////////////////////////////////\r
+\r
+#ifdef _MSC_VER\r
+#pragma warning(disable: 4786 4996)\r
+#ifndef _DEBUG\r
+#pragma warning(disable: 4702)\r
+#endif\r
+#endif\r
+\r
+#include "_ibpp.h"\r
+\r
+#ifdef HAS_HDRSTOP\r
+#pragma hdrstop\r
+#endif\r
+\r
+#include <stdarg.h>\r
+#include <stdio.h>\r
+\r
+using namespace ibpp_internals;\r
+\r
+// None of the exception classes methods are implemented inline, because they\r
+// are all declared throw() and Borland compilers at least, but possibly some\r
+// others emit a warning like "W8026 - functions with exception specification\r
+// are not expanded inline". Nothing we have to worry about, but we don't want\r
+// people concerned by such warnings.\r
+\r
+IBPP::Exception::~Exception() throw()\r
+{\r
+}\r
+\r
+IBPP::LogicException::~LogicException() throw()\r
+{\r
+}\r
+\r
+IBPP::SQLException::~SQLException() throw()\r
+{\r
+}\r
+\r
+IBPP::WrongType::~WrongType() throw()\r
+{\r
+}\r
+\r
+//\r
+//     (((((((( ExceptionBase Implementation ))))))))\r
+//\r
+\r
+void ExceptionBase::buildErrorMessage(const char* message)\r
+{\r
+       if (! mContext.empty())\r
+               mWhat.append(_("Context: ")).append(mContext).append("\n");\r
+\r
+       if (message != 0 && *message != 0 )\r
+               mWhat.append(_("Message: ")).append(message).append("\n");\r
+       \r
+       mWhat.append("\n");\r
+}\r
+\r
+void ExceptionBase::raise(const std::string& context, const char* message, va_list argptr)\r
+{\r
+       mContext.assign(context);\r
+\r
+       if (message != 0)\r
+       {\r
+               char buffer[1024];\r
+#if defined(_MSC_VER) || defined(__DMC__)\r
+               _vsnprintf(buffer, sizeof(buffer)-1, message, argptr);\r
+#else\r
+               vsnprintf(buffer, sizeof(buffer)-1, message, argptr);\r
+#endif\r
+               buffer[sizeof(buffer)-1] = 0;\r
+       \r
+               buildErrorMessage(buffer);\r
+       }\r
+       else\r
+               buildErrorMessage(0);\r
+}\r
+\r
+ExceptionBase::ExceptionBase() throw()\r
+{\r
+}\r
+\r
+ExceptionBase::ExceptionBase(const ExceptionBase& copied) throw()\r
+{\r
+       mContext = copied.mContext;\r
+       mWhat = copied.mWhat;\r
+}\r
+\r
+ExceptionBase& ExceptionBase::operator=(const ExceptionBase& copied) throw()\r
+{\r
+       mContext = copied.mContext;\r
+       mWhat = copied.mWhat;\r
+       return *this;\r
+}\r
+\r
+ExceptionBase::ExceptionBase(const std::string& context,\r
+                                                               const char* message, ...) throw()\r
+{\r
+       va_list argptr;\r
+       va_start(argptr, message);\r
+       mWhat.assign("*** IBPP::Exception ***\n");\r
+       raise(context, message, argptr);\r
+       va_end(argptr);\r
+}\r
+\r
+ExceptionBase::~ExceptionBase() throw()\r
+{\r
+}\r
+\r
+const char* ExceptionBase::Origin() const throw()\r
+{\r
+       return mContext.c_str();\r
+}\r
+\r
+const char* ExceptionBase::ErrorMessage() const throw()\r
+{\r
+       return mWhat.c_str();\r
+}\r
+\r
+const char* ExceptionBase::what() const throw()\r
+{\r
+       return mWhat.c_str();\r
+}\r
+\r
+//     (((((((( LogicExceptionImpl Implementation ))))))))\r
+\r
+// The following constructors are small and could be inlined, but for object\r
+// code compacity of the library it is much better to have them non-inlined.\r
+// The amount of code generated by compilers for a throw is well-enough.\r
+\r
+LogicExceptionImpl::LogicExceptionImpl() throw()\r
+       : ExceptionBase()\r
+{\r
+}\r
+\r
+LogicExceptionImpl::LogicExceptionImpl(const LogicExceptionImpl& copied) throw()\r
+       : IBPP::LogicException(), ExceptionBase(copied)\r
+{\r
+}\r
+\r
+LogicExceptionImpl& LogicExceptionImpl::operator=(const LogicExceptionImpl& copied) throw()\r
+{\r
+       ExceptionBase::operator=(copied);\r
+       return *this;\r
+}\r
+\r
+LogicExceptionImpl::LogicExceptionImpl(const std::string& context,\r
+                                                                               const char* message, ...) throw()\r
+{\r
+       va_list argptr;\r
+       va_start(argptr, message);\r
+       mWhat.assign("*** IBPP::LogicException ***\n");\r
+       raise(context, message, argptr);\r
+       va_end(argptr);\r
+}\r
+\r
+LogicExceptionImpl::~LogicExceptionImpl() throw ()\r
+{\r
+}\r
+\r
+const char* LogicExceptionImpl::Origin() const throw()\r
+{\r
+       return ExceptionBase::Origin();\r
+}\r
+\r
+const char* LogicExceptionImpl::ErrorMessage() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+const char* LogicExceptionImpl::what() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+//     (((((((( SQLExceptionImpl Implementation ))))))))\r
+\r
+SQLExceptionImpl::SQLExceptionImpl() throw()\r
+       : ExceptionBase(), mSqlCode(0), mEngineCode(0)\r
+{\r
+}\r
+\r
+SQLExceptionImpl::SQLExceptionImpl(const SQLExceptionImpl& copied) throw()\r
+       : IBPP::SQLException(), ExceptionBase(copied), mSqlCode(copied.mSqlCode),\r
+               mEngineCode(copied.mEngineCode)\r
+{\r
+}\r
+\r
+SQLExceptionImpl& SQLExceptionImpl::operator=(const SQLExceptionImpl& copied) throw()\r
+{\r
+       ExceptionBase::operator=(copied);\r
+       mSqlCode = copied.mSqlCode;\r
+       mEngineCode = copied.mEngineCode;\r
+       return *this;\r
+}\r
+\r
+SQLExceptionImpl::SQLExceptionImpl(const IBS& status, const std::string& context,\r
+                                                                       const char* message, ...) throw()\r
+{\r
+       va_list argptr;\r
+       va_start(argptr, message);\r
+       mWhat.assign("*** IBPP::SQLException ***\n");\r
+       raise(context, message, argptr);\r
+       va_end(argptr);\r
+       mSqlCode = status.SqlCode();\r
+       mEngineCode = status.EngineCode();\r
+       mWhat.append(status.ErrorMessage());\r
+}\r
+\r
+SQLExceptionImpl::~SQLExceptionImpl() throw ()\r
+{\r
+}\r
+\r
+const char* SQLExceptionImpl::Origin() const throw()\r
+{\r
+       return ExceptionBase::Origin();\r
+}\r
+\r
+const char* SQLExceptionImpl::ErrorMessage() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+const char* SQLExceptionImpl::what() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+int SQLExceptionImpl::SqlCode() const throw()\r
+{\r
+       return mSqlCode;\r
+}\r
+\r
+int SQLExceptionImpl::EngineCode() const throw()\r
+{\r
+       return mEngineCode;\r
+}\r
+\r
+//     (((((((( WrongTypeImpl Implementation ))))))))\r
+\r
+// The following constructors are small and could be inlined, but for object\r
+// code compacity of the library it is much better to have them non-inlined.\r
+// The amount of code generated by compilers for a throw is well-enough.\r
+\r
+WrongTypeImpl::WrongTypeImpl() throw()\r
+       : IBPP::WrongType(), ExceptionBase()\r
+{\r
+}\r
+\r
+WrongTypeImpl::WrongTypeImpl(const WrongTypeImpl& copied) throw()\r
+       : IBPP::WrongType(), ExceptionBase(copied)\r
+{\r
+}\r
+\r
+WrongTypeImpl& WrongTypeImpl::operator=(const WrongTypeImpl& copied) throw()\r
+{\r
+       ExceptionBase::operator=(copied);\r
+       return *this;\r
+}\r
+\r
+WrongTypeImpl::WrongTypeImpl(const std::string& context, int sqlType, IITYPE varType,\r
+                               const char* message, ...) throw()\r
+{\r
+       va_list argptr;\r
+       va_start(argptr, message);\r
+       mWhat.assign("*** IBPP::WrongType ***\n");\r
+       raise(context, message, argptr);\r
+       va_end(argptr);\r
+\r
+       std::string info;\r
+       switch (sqlType & ~1)\r
+       {\r
+               case SQL_TEXT :                 info.append("CHAR"); break;\r
+               case SQL_VARYING :              info.append("VARCHAR"); break;\r
+               case SQL_SHORT :                info.append("SMALLINT"); break;\r
+               case SQL_LONG :                 info.append("INTEGER"); break;\r
+               case SQL_INT64 :                info.append("BIGINT"); break;\r
+               case SQL_FLOAT :                info.append("FLOAT"); break;\r
+               case SQL_DOUBLE :               info.append("DOUBLE"); break;\r
+               case SQL_TIMESTAMP :    info.append("TIMESTAMP"); break;\r
+               case SQL_TYPE_DATE :    info.append("DATE"); break;\r
+               case SQL_TYPE_TIME :    info.append("TIME"); break;\r
+               case SQL_BLOB :                 info.append("BLOB"); break;\r
+               case SQL_ARRAY :                info.append("ARRAY"); break;\r
+       }\r
+       info.append(" ").append(_(" and ")).append(" ");\r
+       switch (varType)\r
+       {\r
+               case ivArray :          info.append("Array"); break;\r
+               case ivBlob :           info.append("Blob"); break;\r
+               case ivDate :           info.append("Date"); break;\r
+               case ivTime :           info.append("Time"); break;\r
+               case ivTimestamp :      info.append("Timestamp"); break;\r
+               case ivString :         info.append("std::string"); break;\r
+               case ivInt16 :          info.append("int16_t"); break;\r
+               case ivInt32 :          info.append("int32_t"); break;\r
+               case ivInt64 :          info.append("int64_t"); break;\r
+               case ivFloat :          info.append("float"); break;\r
+               case ivDouble :         info.append("double"); break;\r
+               case ivBool :           info.append("bool"); break;\r
+               case ivDBKey :          info.append("DBKey"); break;\r
+               case ivByte :           info.append("int8_t"); break;\r
+       }\r
+       mWhat.append(info).append("\n");\r
+}\r
+\r
+WrongTypeImpl::~WrongTypeImpl() throw ()\r
+{\r
+}\r
+\r
+const char* WrongTypeImpl::Origin() const throw()\r
+{\r
+       return ExceptionBase::Origin();\r
+}\r
+\r
+const char* WrongTypeImpl::ErrorMessage() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+const char* WrongTypeImpl::what() const throw()\r
+{\r
+       return ExceptionBase::what();\r
+}\r
+\r
+//\r
+//     EOF\r
+//\r