
#include "x_at_error.h"
#include "base/at_reporterr.h"

AT_Xpace_Error::AT_Xpace_Error
  (const char* module,
   uint lineNum,
   const char* what,
   const Xpace::Exception& ex) :
     AT_General_Error(module, lineNum, "Xpace", what, translateException(ex))
{
  if (!!ex)
  {
    const char* s(ex.what());
    size_t len(strlen(s) + 1);
    what_buf.resize(len);
    memcpy(&what_buf[0], s, len);
  }
}

AT_Xpace_Error* AT_Xpace_Error::clone
  ()
  const
{
  return new AT_Xpace_Error(*this);
}

void AT_Xpace_Error::report
  (Reporter &reporter)
  const
{
  reporter.report(static_cast<const AT_General_Error*>(this));
}

AT_Error* translateException
  (const Xpace::Exception& ex)
{
  return !!ex ? new AT_Xpace_Error("Xpace", 0, ex.what(), ex.why()) : 0;
}