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

  SLC 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.

  SLC 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 SLC; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  US
*/

Seblu's avatar
Seblu committed
#include "error.hh"

Seblu's avatar
Seblu committed
/*!
** Constructor
**
** @param i error code
** @param s error message
*/
Seblu's avatar
Seblu committed
Error::Error(int i, const string s)
{
  val_ = i;
  msg_ << s;
}

Seblu's avatar
Seblu committed
/*!
** Constructor by copy
**
** @param e
*/
Seblu's avatar
Seblu committed
Error::Error(const Error &e)
{
  val_ = e.val_;
  msg_ << e.msg_.str();
}

Seblu's avatar
Seblu committed
/*!
** Print and error msg on std err
**
*/
Seblu's avatar
Seblu committed
void Error::print() const
{
  if (msg_.str() != "")
    std::cerr << msg_.str() << "." << std::endl;
}

Seblu's avatar
Seblu committed
/*!
** @return a copy of message description
*/
Seblu's avatar
Seblu committed
string Error::message() const
{
  return msg_.str();
}

Seblu's avatar
Seblu committed
/*!
** @return the error code
*/
Seblu's avatar
Seblu committed
int Error::code() const
{
  return val_;
}

Seblu's avatar
Seblu committed
/*!
** Set error code to @param v
*/
Seblu's avatar
Seblu committed
void Error::code(int v)
{
  val_ = v;
}

Seblu's avatar
Seblu committed
/*!
** Copy operator
*/
Seblu's avatar
Seblu committed
Error &Error::operator=(const Error &rhs)
{
  val_ = rhs.val_;
  msg_.str("");
  msg_ << rhs.msg_.str();
  return *this;
}

Seblu's avatar
Seblu committed
/*!
** Print error message to @param o stream
*/
Seblu's avatar
Seblu committed
ostream &operator<<(ostream &o, const Error &e)
{
  o << e.msg_.str();
  return o;
}

Seblu's avatar
Seblu committed
/*!
** Concatenate @param val to errror message
*/
Seblu's avatar
Seblu committed
Error &operator<<(Error &e, int val)
{
  e.msg_ << val;
  return e;
}

Seblu's avatar
Seblu committed
/*!
** Concatenate @param s to errror message
*/
Seblu's avatar
Seblu committed
Error &operator<<(Error &e, const string &s)
{
  e.msg_ << s;
  return e;
}

Seblu's avatar
Seblu committed
/*!
** Concatenate @param s before error message
*/
Seblu's avatar
Seblu committed
Error &operator>>(Error &e, const string &s)
{
  string buf = s + e.msg_.str();

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