/* This file is part of cardwords
   (c) 1999 Tobias Peters
   see file COPYING for the copyright terms.
   
   This program 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.

   This program 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 this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

// cardwords_exceptions.cc

#include "cardwords_exceptions.hh"

ostream &
operator << (ostream & o, const CardWords_Exception & x)
{
  x.print(o);
  return o;
}
CardWords_Exception::~CardWords_Exception()
{}

CardWords_XLowResources::CardWords_XLowResources (int en, const string & desc)
  : error_number(en), description(desc)
{}

CardWords_XLowResources::CardWords_XLowResources (const string & desc)
  : error_number(errno), description(desc)
{}

void
CardWords_XLowResources::print(ostream & o) const
{
  o << gettext("Low Resources: ")
    << description << ": "
    << strerror (error_number);
}


CardWords_XInternal_Error::CardWords_XInternal_Error (const string & desc)
  : error_number(errno), description(desc)
{}

void
CardWords_XInternal_Error::print (ostream & o) const
{
  o << gettext("Internal Error: ")
    << description
    << gettext(". (May not apply here: ")
    << strerror (error_number)
    << ')';
}

void CardWords_XOutOfRange::print (ostream & o) const
{
  o << gettext("Out Of Range Error: ")
    << description;
}


CardWords_XAccessingFile::CardWords_XAccessingFile (int en,
                                                    const string & desc,
                                                    const string & fn)
  : error_number (en),
    description  (desc),
    filename     (fn)
{}

CardWords_XAccessingFile::CardWords_XAccessingFile (const string & desc,
                                                    const string & fn)
  : error_number (errno),
    description  (desc),
    filename     (fn)
{}

void
CardWords_XAccessingFile::print (ostream & os) const
{
  os << gettext ("Unable to access file ") 
     << filename << ": " << description << ": "
     << strerror(error_number);
}


CardWords_XBadInput::CardWords_XBadInput (const string & desc,
                                          const string & exp)
  : description(desc), expected(exp)
{}

void CardWords_XBadInput::print (ostream &os) const
{
  os << gettext ("Bad Input Reading ") << description
     << gettext (", expected ") << expected;
}


void
CardWords_XInvalidRequest::print(ostream & o) const
{
  o << gettext ("Invalid Request: ") << description;
}
