/*******************************************************************************
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
Licensed under a BSD-style license.
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
*******************************************************************************/
/**
\file ZE_ZError.cpp
\brief Source file for ZError.
Implementation of ZError, the ZEngine internal error information storage class.
$Id: ZE_ZError.cpp,v 1.12 2003/08/31 18:34:38 cozman Exp $
\author James Turk
**/
#include "ZE_ZError.h"
namespace ZE
{
std::string ZError::sErrorDesc[ZERR_LAST];
void ZError::CreateStringTable()
{
//create error strings
sErrorDesc[ZERR_NONE] = "No Error. [%s]";
sErrorDesc[ZERR_SDL_INTERNAL] = "SDL Error. [%s]";
sErrorDesc[ZERR_SDL_INIT] = "Error Initializing SDL: %s";
sErrorDesc[ZERR_MIX_INIT] = "Error Initializing SDL_mixer: %s";
sErrorDesc[ZERR_TTF_INIT] = "Error Initializing SDL_ttf: %s";
sErrorDesc[ZERR_VIDMODE] = "Error Creating Display: %s";
sErrorDesc[ZERR_LOAD_IMAGE] = "Failed to load Image: %s";
sErrorDesc[ZERR_LOAD_SOUND] = "Failed to load Sound: %s";
sErrorDesc[ZERR_LOAD_MUSIC] = "Failed to load Music: %s";
sErrorDesc[ZERR_LOAD_FONT] = "Failed to load Font: %s";
sErrorDesc[ZERR_NOIMAGE] = "Called ZImage::%s with no Image loaded.";
sErrorDesc[ZERR_NOSOUND] = "Called ZSound::%s with no Sound loaded.";
sErrorDesc[ZERR_NOMUSIC] = "Called ZMusic::%s with no Music loaded.";
sErrorDesc[ZERR_NOFONT] = "Called ZFont::%s with no Font loaded.";
}
ZError::ZError(ZErrorCode code, std::string desc, std::string file, int line) :
rCode(code), rDescription(desc), rFilename(file), rLine(line)
{
}
void ZError::Create(ZErrorCode code, std::string desc, std::string file, int line)
{
rCode = code;
rDescription = desc;
rFilename = file;
rLine = line;
}
ZErrorCode ZError::Code() const
{
return rCode;
}
std::string ZError::LogString() const
{
std::string msg;
//if there is a description be sure to integrate it
msg = rDescription.length() ? FormatStr(sErrorDesc[rCode].c_str(),rDescription.c_str()) : sErrorDesc[rCode];
if(rLine != 0) //if there is a line (there is also a filename)
return FormatStr(" -%s(%d): %s\n",rFilename.c_str(),rLine,msg.c_str());
else if(rFilename.length()) //no line, just filename
return FormatStr(" -%s: %s\n",rFilename.c_str(),msg.c_str());
else //just the message
return FormatStr(" -%s\n",msg.c_str());
}
}