Add the SDL exception class.

This commit is contained in:
Mark de Wever 2014-03-23 13:09:08 +01:00
parent e96bd0f1e1
commit f6b52f338c
4 changed files with 83 additions and 0 deletions

View File

@ -358,6 +358,7 @@ endif()
set(wesnoth-sdl_SRC
sdl/alpha.cpp
sdl/exception.cpp
sdl/texture.cpp
sdl/window.cpp
)

View File

@ -150,6 +150,7 @@ libcampaignd = env.Library("campaignd", libcampaignd_sources, OBJPREFIX = "campa
libwesnoth_sdl_sources = Split("""
sdl_utils.cpp
sdl/alpha.cpp
sdl/exception.cpp
sdl/texture.cpp
sdl/window.cpp
tracer.cpp

37
src/sdl/exception.cpp Normal file
View File

@ -0,0 +1,37 @@
/*
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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.
See the COPYING file for more details.
*/
#include "sdl/exception.hpp"
#include <SDL_error.h>
namespace sdl
{
static std::string create_error(const std::string& operation,
const bool use_sdl_error)
{
if(use_sdl_error) {
return operation + " Error »" + SDL_GetError() + "«.\n";
} else {
return operation;
}
}
texception::texception(const std::string& operation, const bool use_sdl_error)
: game::error(create_error(operation, use_sdl_error))
{
}
} // namespace sdl

44
src/sdl/exception.hpp Normal file
View File

@ -0,0 +1,44 @@
/*
Copyright (C) 2014 by Mark de Wever <koraq@xs4all.nl>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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.
See the COPYING file for more details.
*/
#ifndef SDL_EXCEPTION_HPP_INCLUDED
#define SDL_EXCEPTION_HPP_INCLUDED
/**
* @file
* Contains a basic exception class for SDL operations.
*/
#include "exceptions.hpp"
namespace sdl
{
struct texception : public game::error
{
/**
* Constructor.
*
* @param operation The operation that has failed.
* @param use_sdl_error If set to @c true the @p operation is
* appended with the SDL error message. Else the
* @p operation is the error message for the
* exception.
*/
texception(const std::string& operation, const bool use_sdl_error);
};
} // namespace sdl
#endif