Skip to content
error.cc 1.63 KiB
Newer Older
Seblu's avatar
Seblu committed
/*
  This file is part of SLD.
  Copyright (C) 2008 Sebastien LUTTRINGER <contact@seblu.net>

  SLD is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  SLD is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with SLD; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

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;
}