diff --git a/source/code/CppSdlException.cpp b/source/code/CppSdlException.cpp deleted file mode 100644 index a33a892..0000000 --- a/source/code/CppSdlException.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2013 Poul Sander - -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, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#include "CppSdlException.hpp" - -namespace CppSdl -{ - -CppSdlException::CppSdlException(Subsystem subsystem,long errorNumber, std::string msg) -{ - _errorNumber = errorNumber; - _message = msg; - _subsystem = subsystem; -} - -CppSdlException::CppSdlException(const CppSdlException& orig) -{ -} - -CppSdlException::~CppSdlException() throw() -{ -} - -const char* CppSdlException::what() const throw() -{ - return _message.c_str(); -} - -long CppSdlException::GetErrorNumber() -{ - return _errorNumber; -} - -Subsystem CppSdlException::GetSubSystem() -{ - return _subsystem; -} - -} diff --git a/source/code/CppSdlException.hpp b/source/code/CppSdlException.hpp deleted file mode 100644 index 4782f39..0000000 --- a/source/code/CppSdlException.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* -=========================================================================== -blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2013 Poul Sander - -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, see http://www.gnu.org/licenses/ - -Source information and contacts persons can be found at -http://blockattack.sf.net -=========================================================================== -*/ - -#ifndef _CPPSDLEXCEPTION_HPP -#define _CPPSDLEXCEPTION_HPP - -#include - -#define CPPSDL_ERROR_DATA 1 -#define CPPSDL_ERROR_INVALID 2 -#define CPPSDL_ERROR_MISSINGFILE 3 -#define CPPSDL_ERROR_NULLPOINTER 4 - -enum Subsystem {OTHER,IMAGE,TILE,SPRITE,LAYER,SCREEN }; - - -namespace CppSdl -{ -class CppSdlException : std::exception -{ -public: - //CppSdlException(); - /** - * Constructor for making a fully CppSdl compliant expection - * @param subsystem Can be: OTHER,IMAGE,TILE,SPRITE,LAYER,SCREEN - * @param errorNumber 1=Data error, 2=Invalid, 3=Missingfile, 4=null pointer - * @param msg Human readable error message. - */ - CppSdlException(Subsystem subsystem, long errorNumber, std::string msg); - CppSdlException(const CppSdlException& orig); - virtual ~CppSdlException() throw(); - virtual const char* what() const throw(); - long GetErrorNumber(); - Subsystem GetSubSystem(); -private: - std::string _message; - long _errorNumber; - Subsystem _subsystem; -}; - - -} -#endif /* _CPPSDLEXCEPTION_HPP */ - diff --git a/source/code/CppSdlImageHolder.cpp b/source/code/CppSdlImageHolder.cpp index f4b6353..be8fde0 100644 --- a/source/code/CppSdlImageHolder.cpp +++ b/source/code/CppSdlImageHolder.cpp @@ -23,6 +23,7 @@ http://blockattack.sf.net #include "CppSdlImageHolder.hpp" #include "SDL_image.h" +#include namespace CppSdl { @@ -38,8 +39,7 @@ CppSdlImageHolder::CppSdlImageHolder(std::string filename) if(!data) { //Here we should throw an exception - CppSdlException e(IMAGE,CPPSDL_ERROR_MISSINGFILE,"Could not read file \""+filename+"\""); - throw e; + throw std::runtime_error(std::string("Could not read file \""+filename+"\"")); } SDL_GetClipRect(data,&area); OptimizeForBlit(); @@ -51,15 +51,13 @@ CppSdlImageHolder::CppSdlImageHolder(char* rawdata, int datasize) //The above might fail and return null. if (!rw) { - CppSdlException e(IMAGE,CPPSDL_ERROR_NULLPOINTER, "Could not read raw data"); - throw e; + throw std::runtime_error(std::string("Could not read raw data")); } data = IMG_Load_RW(rw,true); //the second argument tells the function to free RWops if (!data) { - CppSdlException e(IMAGE,CPPSDL_ERROR_DATA,"Could not convert raw data to image"); - throw e; + throw std::runtime_error("Could not convert raw data to image"); } SDL_GetClipRect(data,&area); @@ -115,8 +113,9 @@ void CppSdlImageHolder::OptimizeForBlit(bool allowAlpha) void CppSdlImageHolder::Initialized() { - if(data == NULL) - throw(CppSdlException(IMAGE,CPPSDL_ERROR_NULLPOINTER,"ImageHolder used uninitialized!")); + if(data == NULL) { + throw std::runtime_error("ImageHolder used uninitialized!"); + } } bool CppSdlImageHolder::IsNull() diff --git a/source/code/CppSdlImageHolder.hpp b/source/code/CppSdlImageHolder.hpp index b46f102..d6c5384 100644 --- a/source/code/CppSdlImageHolder.hpp +++ b/source/code/CppSdlImageHolder.hpp @@ -26,7 +26,6 @@ http://blockattack.sf.net #include "SDL.h" #include -#include "CppSdlException.hpp" namespace CppSdl { diff --git a/source/code/Makefile b/source/code/Makefile index 442249c..14917aa 100644 --- a/source/code/Makefile +++ b/source/code/Makefile @@ -43,7 +43,7 @@ endif BASE_LIBS += -lphysfs -OFILES=main.o highscore.o ReadKeyboard.o joypad.o listFiles.o common.o stats.o CppSdlException.o CppSdlImageHolder.o Libs/NFont.o MenuSystem.o menudef.o puzzlehandler.o +OFILES=main.o highscore.o ReadKeyboard.o joypad.o listFiles.o common.o stats.o CppSdlImageHolder.o Libs/NFont.o MenuSystem.o menudef.o puzzlehandler.o ifeq ($(CROSS),i686-pc-mingw32-) OFILES += winicon.res diff --git a/source/code/MenuSystem.cpp b/source/code/MenuSystem.cpp index 8992df4..74fb373 100644 --- a/source/code/MenuSystem.cpp +++ b/source/code/MenuSystem.cpp @@ -34,6 +34,8 @@ extern int verboseLevel; int mousex; int mousey; +using namespace std; + /*Draws a image from on a given Surface. Takes source image, destination surface and coordinates*/ inline void DrawIMG(SDL_Surface *img, SDL_Surface *target, int x, int y) { @@ -83,7 +85,7 @@ Button::Button(const Button& b) popOnRun = false; } -void Button::setLabel(string text) +void Button::setLabel(const string& text) { label = text; } @@ -212,7 +214,7 @@ Menu::Menu(SDL_Surface **screen,bool submenu) exit.setLabel( _("Exit") ); } -Menu::Menu(SDL_Surface** screen, string title, bool submenu) +Menu::Menu(SDL_Surface** screen, const string& title, bool submenu) { this->screen = *screen; buttons = vector(0); diff --git a/source/code/MenuSystem.h b/source/code/MenuSystem.h index 3857f29..67ba7a6 100644 --- a/source/code/MenuSystem.h +++ b/source/code/MenuSystem.h @@ -32,8 +32,6 @@ http://blockattack.sf.net #include "CppSdlImageHolder.hpp" #include -using namespace std; - //The ButtonGfx object hold common media for all buttons, so we can reskin them by only changeing one pointer class ButtonGfx { @@ -57,7 +55,7 @@ class Button { private: //The label. This is written on the button - string label; + std::string label; //Pointer to a callback function. void (*action)(Button *b); @@ -79,7 +77,7 @@ public: //Set the text to write on the button - void setLabel(string text); + void setLabel(const std::string& text); //Set the action to run void setAction(void (*action2run)(Button*)); @@ -99,13 +97,13 @@ public: class Menu { private: - vector buttons; //Vector holder the buttons + std::vector buttons; //Vector holder the buttons Button exit; //The exit button is special since it does not have a callback function bool isSubmenu; //True if the menu is a submenu int marked; //The index of the marked button (for keyboard up/down) bool running; //The menu is running. The menu will terminate then this is false SDL_Surface *screen; //Pointer to the screen to draw to - string title; + std::string title; // SDL_Surface *background; //Pointer to the background image void drawSelf(); //Private function to draw the screen @@ -116,7 +114,7 @@ public: //SubMenu is true by default Menu(SDL_Surface **screen,bool isSubmenu); Menu(SDL_Surface **screen); - Menu(SDL_Surface **screen, string title, bool isSubmenu); + Menu(SDL_Surface **screen, const std::string& title, bool isSubmenu); //Add a button to the menu void addButton(Button *b); @@ -128,13 +126,13 @@ public: class FileMenu { private: - string pm_path; - string pm_fileending; + std::string pm_path; + std::string pm_fileending; bool pm_hidden_files; public: - FileMenu(string path,string fileending,bool hidden_files = false); + FileMenu(const std::string& path, const std::string& fileending, bool hidden_files = false); - string getFile(SDL_Surface **screen); + std::string getFile(SDL_Surface **screen); }; #endif /* _MENUSYSTEM_H */ diff --git a/source/code/SConscript b/source/code/SConscript index 9b185fe..a81c4b6 100644 --- a/source/code/SConscript +++ b/source/code/SConscript @@ -15,8 +15,7 @@ common.cpp MenuSystem.cpp menudef.cpp puzzlehandler.cpp -CppSdlImageHolder.cpp -CppSdlException.cpp""") +CppSdlImageHolder.cpp""") # Modify Build Environment # env.ParseConfig('sdl-config --cflags --libs')