exception.cpp
Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00034 #include "gpucalc/exception.h"
00035 
00036 #include "gpucalc/log_manager.h"
00037 #include "gpucalc/application.h"
00038 #include "gpucalc/string_util.h"
00039 
00040 namespace gpucalc
00041 {
00042 
00043 
00044  Exception::Exception(int num, const Object & object, const std::string & desc, const std::string & src):
00045    mLine(0), mObject(&object), mNumber(num), mDescription(desc), mSource(src)
00046  {
00047   
00048   
00049  }
00050 
00051 
00052  Exception::Exception(int num, const Object & object, const std::string & desc, const std::string & src, const char * typ, const char * fil, long lin):
00053   mLine(lin), mObject(&object), mNumber(num), mTypeName(typ), mDescription(desc), mSource(src), mFile(fil)
00054  {
00055   
00056   if (LogManager::getSingletonPtr())
00057   {
00058    LogManager::getSingleton().logMessage(mObject, this->getFullDescription(), LML_Critical, true);
00059   }
00060  }
00061 
00062 
00063  Exception::Exception(const Exception & rhs): std::exception(), mLine(rhs.mLine), mObject(rhs.mObject),
00064   mNumber(rhs.mNumber), mDescription(rhs.mDescription), mSource(rhs.mSource), mFile(rhs.mFile)
00065  {
00066  }
00067 
00068 
00069  void Exception::operator = (const Exception & rhs)
00070  {
00071   mDescription = rhs.mDescription;
00072   mNumber = rhs.mNumber;
00073   mSource = rhs.mSource;
00074   mFile = rhs.mFile;
00075   mLine = rhs.mLine;
00076   mObject = rhs.mObject;
00077   mTypeName = rhs.mTypeName;
00078  }
00079 
00080 
00081  const std::string & Exception::getFullDescription() const
00082  {
00083   if (mFullDesc.empty())
00084   {
00085    std::ostringstream desc;
00086    desc << "EXCEPTION(" << mNumber << ":" << mTypeName << "): "
00087     << mDescription << " in " << mSource;
00088 
00089    if (mLine > 0)
00090    {
00091     desc << " at " << mFile << " (line " << mLine << ")";
00092    }
00093    mFullDesc = desc.str();
00094   }
00095   return mFullDesc;
00096  }
00097 
00098 
00099  int Exception::getNumber() const throw()
00100  {
00101   return mNumber;
00102  }
00103 
00104 
00110  namespace _workaround
00111  {
00112   void DoWarning::doWarning(const Object * obj, const std::string & Description, const std::string & Source,
00113    const std::string & File, int Line)
00114   {
00115    if(!Application::getSingleton().supressWarnings())
00116    {
00117     LogManager::getSingleton().logMessage(obj,
00118      "!!!WARNING!!!\t" + Description + ". " + Source + " at " + File + " (line " + auxillary::StringUtil::toString(Line) + ")",
00119      gpucalc::LML_Critical);
00120    }
00121   }
00122  }
00123 }