00001
00022 #include "config.h"
00023 #include "libnebular-plugin.hpp"
00024
00025 #ifndef LIBNEBULAR_PLUGIN_TEMPLATES_HPP_
00026 #define LIBNEBULAR_PLUGIN_TEMPLATES_HPP_
00027
00028 namespace libnebular{
00029 template <typename T> const String Log::getWrongValueMsg(
00030 const String &key,
00031 const T &value,
00032 const String &shouldBe,
00033 const String &where,
00034 const String &wrongnessType
00035 ){
00036 std::ostringstream tmpOut;
00037 tmpOut << wrongnessType << " value";
00038 if(where != ""){
00039 tmpOut << " in " << where;
00040 }
00041 tmpOut << ": " <<
00042 key << " = \"" << value << "\"";
00043 if(shouldBe != ""){
00044 tmpOut << "; should be " << shouldBe << "";
00045 }
00046 return tmpOut.str();
00047 }
00048
00049 template <typename CurrException> void RawCExceptionLongJmp::exactThrow(boost::shared_ptr<const std::exception> x){
00050 throw *static_cast<const CurrException*>(x.get());
00051 }
00052
00053 template <typename CurrException> void RawCExceptionLongJmp::doThrow(const CurrException &newException){
00054 anException = boost::make_shared<CurrException>(newException);
00055 currExactThrow = &exactThrow<CurrException>;
00056 if(!isEnabled){
00057
00058 throw std::logic_error("(FATAL) \"RawCExceptionLongJmp::doThrow\" is called from outside of code enclosed by \"RawCExceptionLongJmp::run\"");
00059 }
00060 longjmp(aJmpBuf, 1);
00061 }
00062
00063 #if HAVE_LOKI_FUNCTOR_H
00064 #if HAVE_CSETJMP
00065
00066 template <typename Return> Return RawCExceptionLongJmp::run(
00067 Loki::Functor<Return> code
00068 ){
00069 isEnabled = true;
00070
00071 if(setjmp(aJmpBuf) == 0){
00072
00073 return code();
00074 }else{
00075
00076 if(!cleanupCode.empty()){
00077 cleanupCode();
00078 }
00079 if(std::string(anException->what()) != ""){
00080
00081 currExactThrow(anException);
00082 }else{
00083 Log::warning("Programmer logic error: No exception definition have been provided. Do you really control \"longjmp\"-s in your code?");
00084 currExactThrow(anException);
00085 }
00086 throw std::logic_error("Assumption failure");
00087 }
00088
00089 isEnabled = false;
00090 }
00091
00092
00093 #endif // HAVE_CSETJMP
00094 #endif // HAVE_LOKI_FUNCTOR_H
00095 }
00096
00097
00098 #endif // LIBNEBULAR_PLUGIN_TEMPLATES_HPP_