diff --git a/source/code/CppSdlException.cpp b/source/code/CppSdlException.cpp index c7bb2c0..a33a892 100644 --- a/source/code/CppSdlException.cpp +++ b/source/code/CppSdlException.cpp @@ -1,9 +1,25 @@ /* - * File: CppSdlException.cpp - * Author: poul - * - * Created on 7. november 2010, 13:19 - */ +=========================================================================== +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" diff --git a/source/code/CppSdlException.hpp b/source/code/CppSdlException.hpp index ebf35e2..4782f39 100644 --- a/source/code/CppSdlException.hpp +++ b/source/code/CppSdlException.hpp @@ -1,7 +1,7 @@ /* =========================================================================== blockattack - Block Attack - Rise of the Blocks -Copyright (C) 2005-2012 Poul Sander +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 diff --git a/source/code/CppSdlImageHolder.cpp b/source/code/CppSdlImageHolder.cpp index 1b93032..6375248 100644 --- a/source/code/CppSdlImageHolder.cpp +++ b/source/code/CppSdlImageHolder.cpp @@ -1,9 +1,25 @@ /* - * File: CppSdlImageHolder.cpp - * Author: poul - * - * Created on 29. september 2010, 19:46 - */ +=========================================================================== +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 "CppSdlImageHolder.hpp" #include "SDL_image.h" diff --git a/source/code/common.cc b/source/code/common.cc index 7b4f5fe..eb88fda 100644 --- a/source/code/common.cc +++ b/source/code/common.cc @@ -48,7 +48,7 @@ string double2str(double num) * if the string is not a double then 0.0 is returned instead of throing an error * in that way this function will always return a useable value. */ -double str2double(string str2parse) +double str2double(const string &str2parse) { try { @@ -58,7 +58,7 @@ double str2double(string str2parse) converter >> val; return val; } - catch(ios_base::failure f) + catch(ios_base::failure &f) { return 0.0; } @@ -69,7 +69,7 @@ double str2double(string str2parse) * if the string is not an int then 0 is returned instead of throing an error * in that way this function will always return a useable value. */ -int str2int(string str2parse) +int str2int(const string &str2parse) { try { @@ -79,7 +79,7 @@ int str2int(string str2parse) converter >> val; return val; } - catch(ios_base::failure f) + catch(ios_base::failure &f) { return 0; } @@ -143,7 +143,7 @@ commonTime TimeHandler::ms2ct(unsigned int milliseconds) return ct; } -commonTime TimeHandler::getTime(string name) +commonTime TimeHandler::getTime(const string &name) { commonTime ct; ct.days = Config::getInstance()->getInt(name+"Days"); @@ -157,7 +157,7 @@ commonTime TimeHandler::getTime(string name) * Returns the total runtime with toAdd added but without writing it to config file. * Used for stats */ -commonTime TimeHandler::peekTime(string name, commonTime toAdd) +commonTime TimeHandler::peekTime(const string &name, const commonTime &toAdd) { commonTime ct = getTime(name); @@ -181,7 +181,7 @@ commonTime TimeHandler::peekTime(string name, commonTime toAdd) * Same as peekTotalTime but writes the time to the config file. * Should only be called only once! when the program shuts down */ -commonTime TimeHandler::addTime(string name, commonTime toAdd) +commonTime TimeHandler::addTime(const string &name, const commonTime &toAdd) { commonTime ct = peekTime(name,toAdd); @@ -255,13 +255,13 @@ void Config::save() outFile.close(); } -bool Config::exists(string varName) const +bool Config::exists(const string &varName) const { //Using that find returns an iterator to the end of the map if not found return configMap.find(varName) != configMap.end(); } -void Config::setDefault(string varName,string content) +void Config::setDefault(const string &varName,const string &content) { if(exists(varName)) return; //Already exists do not change @@ -278,22 +278,22 @@ long Config::isShuttingDown() const return shuttingDown; } -void Config::setString(string varName, string content) +void Config::setString(const string &varName, const string &content) { configMap[varName] = content; } -void Config::setInt(string varName, int content) +void Config::setInt(const string &varName, int content) { configMap[varName] = itoa(content); } -void Config::setValue(string varName,double content) +void Config::setValue(const string &varName,double content) { configMap[varName] = double2str(content); } -string Config::getString(string varName) +string Config::getString(const string &varName) { if(exists(varName)) { @@ -303,7 +303,7 @@ string Config::getString(string varName) return ""; } -int Config::getInt(string varName) +int Config::getInt(const string &varName) { if(exists(varName)) { @@ -313,7 +313,7 @@ int Config::getInt(string varName) return 0; } -double Config::getValue(string varName) +double Config::getValue(const string &varName) { if(exists(varName)) { diff --git a/source/code/common.h b/source/code/common.h index c1bf53b..eb3a2dc 100644 --- a/source/code/common.h +++ b/source/code/common.h @@ -72,7 +72,7 @@ string getPathToSaveFiles() __attribute__((pure)); * if the string is not an int then 0 is returned instead of throing an error * in that way this function will always return a useable value. */ -int str2int(string str2parse) __attribute__((const)); +int str2int(const string &str2parse) __attribute__((const)); string double2str(double num) __attribute__((const)); @@ -81,7 +81,7 @@ string double2str(double num) __attribute__((const)); * if the string is not a double then 0.0 is returned instead of throing an error * in that way this function will always return a useable value. */ -double str2double(string str2parse) __attribute__((const)); +double str2double(const string &str2parse) __attribute__((const)); #ifdef WIN32 string getMyDocumentsPath(); @@ -92,11 +92,11 @@ class TimeHandler public: static commonTime ms2ct(unsigned int milliseconds); - static commonTime getTime(string name); + static commonTime getTime(const string &name); - static commonTime peekTime(string name, commonTime toAdd); + static commonTime peekTime(const string &name, const commonTime &toAdd); - static commonTime addTime(string name, commonTime toAdd); + static commonTime addTime(const string &name, const commonTime &toAdd); }; #define MAX_VAR_LENGTH 1024 @@ -140,36 +140,36 @@ public: *Looks in the config file and returns the string that matches the key "varName" *Returns an empty string if varName does not exist. */ - string getString(string varName); + string getString(const string &varName); /*getInt(varName) *Looks in the config file and returns the int that matches the key "varName" *Returns "0" if varName does not exist or cannot be parsed. */ - int getInt(string varName); + int getInt(const string &varName); /*getValue(varName) *Looks in the config file and returns the double that matches the key "varName" *Returns "0.0" if varName does not exist or cannot be parsed. */ - double getValue(string varName); + double getValue(const string &varName); /*setString(varName,content) *Sets the config variable with key "varName" to the value of "content" */ - void setString(string varName,string content); + void setString(const string &varName,const string &content); /*setInt(varName,content) *Sets the config variable with key "varName" to the value of "content" */ - void setInt(string varName,int content); + void setInt(const string &varName,int content); /** * Sets a config variable to a given (double) value * @param varName Name of the variable to set * @param content Value to give the variable */ - void setValue(string varName,double content); + void setValue(const string &varName,double content); /** * returns true if the key varName exists. This is used the first time 1.4.0 @@ -178,7 +178,7 @@ public: * @param varName Name of the variable * @return true if the varaible exists */ - bool exists(string varName) const; + bool exists(const string &varName) const; /*setDefault(varName,value) *if the variable "varName" does not exist it will be created with value "value" @@ -190,7 +190,7 @@ public: * @param varName Name of the variable * @param content The default value */ - void setDefault(string varName, string content); + void setDefault(const string &varName, const string &content); /** * Should be set if the user has requested the program to shutdown. diff --git a/source/code/listFiles.cpp b/source/code/listFiles.cpp index 0471103..1f3f83a 100644 --- a/source/code/listFiles.cpp +++ b/source/code/listFiles.cpp @@ -38,14 +38,14 @@ ListFiles::~ListFiles() }*/ -void ListFiles::setDirectory(string directory) +void ListFiles::setDirectory(const string &directory) { for (int i=0; i #include diff --git a/source/code/replay.cpp b/source/code/replay.cpp index 4b64870..c7e3d8a 100644 --- a/source/code/replay.cpp +++ b/source/code/replay.cpp @@ -50,7 +50,7 @@ Replay::Replay(const Replay& r) -bool Replay::saveReplay(string filename) +bool Replay::saveReplay(const string &filename) { //Saving as fileversion 4 if(verboseLevel) @@ -74,7 +74,7 @@ bool Replay::saveReplay(string filename) } } -bool Replay::saveReplay(string filename,Replay p2) +bool Replay::saveReplay(const string &filename,const Replay &p2) { //Saving as fileversion 4 if(verboseLevel) @@ -104,7 +104,7 @@ bool Replay::saveReplay(string filename,Replay p2) } } -bool Replay::loadReplay(string filename) +bool Replay::loadReplay(const string &filename) { isLoaded = true; actions.clear(); @@ -157,7 +157,7 @@ bool Replay::loadReplay(string filename) return true; } -bool Replay::loadReplay2(string filename) +bool Replay::loadReplay2(const string &filename) { isLoaded = true; bool player2started = false; //set to true once the player two part is reached @@ -213,7 +213,7 @@ bool Replay::loadReplay2(string filename) return true; } -void Replay::setName(string name) +void Replay::setName(const string &name) { this->name = name; } @@ -228,7 +228,7 @@ vector Replay::getActions() const return actions; } -void Replay::addAction(int tick, int action, string param) +void Replay::addAction(int tick, int action, const string ¶m) { #if DEBUG cout << tick << " " << action << " " << param << endl; diff --git a/source/code/replay.h b/source/code/replay.h index 1ef1549..2ec7b5f 100644 --- a/source/code/replay.h +++ b/source/code/replay.h @@ -63,14 +63,14 @@ public: Replay(const Replay& r); //Copy constructor //New replay type 2.0.0+: - void addAction(int tick, int action, string param); + void addAction(int tick, int action,const string ¶m); //Ok, I'll ignore this for some time, and just save to file, if however, we ever use a dynamic saving structure, we are fucked - bool saveReplay(string); //Saves a replay - bool saveReplay(string,Replay p2); //saves a replay, plus another replay given as a parameter - bool loadReplay(string); //laods a replay - bool loadReplay2(string); - void setName(string name); + bool saveReplay(const string &filename); //Saves a replay + bool saveReplay(const string &filename, const Replay &p2); //saves a replay, plus another replay given as a parameter + bool loadReplay(const string &filename); //laods a replay + bool loadReplay2(const string &filename); + void setName(const string &name); string getName() const; vector getActions() const; //loads the second part of the replay file, if it exists, returns false otherwise }; diff --git a/source/code/stats.cc b/source/code/stats.cc index 3306daa..b2782a1 100644 --- a/source/code/stats.cc +++ b/source/code/stats.cc @@ -77,7 +77,7 @@ void Stats::save() } } -unsigned int Stats::getNumberOf(string statName) +unsigned int Stats::getNumberOf(const string &statName) { if(exists(statName)) { @@ -87,7 +87,7 @@ unsigned int Stats::getNumberOf(string statName) return 0; } -void Stats::addOne(string statName) +void Stats::addOne(const string &statName) { map::iterator iter = statMap.find(statName); if(iter == statMap.end()) @@ -100,7 +100,7 @@ void Stats::addOne(string statName) } } -bool Stats::exists(string statName) +bool Stats::exists(const string &statName) { //Using that 'find' returns an iterator to the end of the map if not found return statMap.find(statName) != statMap.end(); diff --git a/source/code/stats.h b/source/code/stats.h index 8c6bb44..57b1f84 100644 --- a/source/code/stats.h +++ b/source/code/stats.h @@ -58,11 +58,11 @@ public: void save(); - unsigned int getNumberOf(string statName); + unsigned int getNumberOf(const string &statName); - void addOne(string statName); + void addOne(const string &statName); - bool exists(string statName); + bool exists(const string &statName); };