mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-03 07:33:40 +00:00
Add the SDL exception class.
This commit is contained in:
parent
e96bd0f1e1
commit
f6b52f338c
@ -358,6 +358,7 @@ endif()
|
||||
|
||||
set(wesnoth-sdl_SRC
|
||||
sdl/alpha.cpp
|
||||
sdl/exception.cpp
|
||||
sdl/texture.cpp
|
||||
sdl/window.cpp
|
||||
)
|
||||
|
@ -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
37
src/sdl/exception.cpp
Normal 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
44
src/sdl/exception.hpp
Normal 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
|
Loading…
x
Reference in New Issue
Block a user