Skip to content
error.cc 899 B
Newer Older
Seblu's avatar
Seblu committed
#include "error.hh"
Seblu's avatar
Seblu committed
#include "log.hh"
Seblu's avatar
Seblu committed

Error::Error(int i, const string s)
{
  val_ = i;
  msg_ << s;
}

Error::Error(const Error &e)
{
  val_ = e.val_;
  msg_ << e.msg_.str();
}

void Error::print() const
{
  if (msg_.str() != "")
Seblu's avatar
Seblu committed
    logerr << msg_.str() << ".\n";
Seblu's avatar
Seblu committed
}

string Error::message() const
{
  return msg_.str();
}

int Error::code() const
{
  return val_;
}

void Error::code(int v)
{
  val_ = v;
}

Error &Error::operator=(const Error &rhs)
{
  val_ = rhs.val_;
  msg_.str("");
  msg_ << rhs.msg_.str();
  return *this;
}

ostream &operator<<(ostream &o, const Error &e)
{
  o << e.msg_.str();
  return o;
}

Error &operator<<(Error &e, int val)
{
  e.msg_ << val;
  return e;
}

Error &operator<<(Error &e, const string &s)
{
  e.msg_ << s;
  return e;
}

Error &operator>>(Error &e, const string &s)
{
  string buf = s + e.msg_.str();

  e.msg_.str("");
  e.msg_ << buf;
  return e;
}