This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the DIE macro by better code
git-svn-id: svn://solarus-engine.org/solarus/trunk@1438 08e91b48-8f19-0410-8fc9-9db6b7bce602
- Loading branch information
1 parent
41d591a
commit 97e22be
Showing
71 changed files
with
505 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright (C) 2009 Christopho, Solarus - http://www.solarus-engine.org | ||
* | ||
* Solarus 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Solarus 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/>. | ||
*/ | ||
#ifndef SOLARUS_DEBUG_H | ||
#define SOLARUS_DEBUG_H | ||
|
||
#include "Common.h" | ||
#include <stdexcept> | ||
#include <iostream> | ||
|
||
/** | ||
* @brief Provides functionalities for printing debug messages | ||
* or making runtime verifications, especially when the code is compiled in debugging mode. | ||
*/ | ||
class Debug { | ||
|
||
private: | ||
|
||
Debug(); // don't instanciate this class | ||
|
||
public: | ||
|
||
static void print(const std::string &message, std::ostream &os = std::cout); | ||
static void assert(bool assertion, const std::string &error_message = ""); | ||
static void die(const std::string &error_message = ""); | ||
}; | ||
|
||
|
||
/** | ||
* @brief Prints a message if the program is in debug mode. | ||
* | ||
* This function does nothing if SOLARUS_DEBUG_LEVEL is 0. | ||
* | ||
* @param message the message to print. | ||
* @param the output stream to write (default is std::cout) | ||
*/ | ||
inline void Debug::print(const std::string &message, std::ostream &os) { | ||
|
||
#if SOLARUS_DEBUG_LEVEL > 0 | ||
os << message << std::endl; | ||
#endif | ||
} | ||
|
||
/** | ||
* @brief Throws an exception if the specified assertion fails. | ||
* | ||
* If the assertion fails, an std::logic_error with the specified error message is thrown. | ||
* If SOLARUS_DEBUG_LEVEL is greater than 0, the error message is | ||
* printed on stderr first. | ||
* This function should be used to detect fatal errors only, that is, | ||
* errors in your code or in the quest (the data files) that require to stop the program. | ||
* | ||
* @param assertion the boolean condition to check | ||
* @param error_message the error message to attach to the exception when the assertion fails | ||
*/ | ||
inline void Debug::assert(bool assertion, const std::string &error_message) { | ||
|
||
if (!assertion) { | ||
print(error_message, std::cerr); | ||
throw std::logic_error(error_message); | ||
} | ||
} | ||
|
||
/** | ||
* @brief Throws an exception to stop the program. | ||
* | ||
* This function is equivalent to assert(false, error_message). | ||
* | ||
* @param error_message the error message to attach to the exception | ||
*/ | ||
inline void Debug::die(const std::string &error_message) { | ||
|
||
assert(false, error_message); | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2009 Christopho, Solarus - http://www.solarus-engine.org | ||
* | ||
* Solarus 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 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Solarus 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/>. | ||
*/ | ||
#ifndef SOLARUS_STRING_CONCAT_H | ||
#define SOLARUS_STRING_CONCAT_H | ||
|
||
#include <sstream> | ||
|
||
/** | ||
* @brief A subclass of std::string that add operators | ||
* to directly concatenate elements. | ||
*/ | ||
class StringConcat: public std::string { | ||
|
||
private: | ||
|
||
std::ostringstream oss; /**< used to concatenate non string objects to this string */ | ||
|
||
public: | ||
|
||
StringConcat& operator<<(const std::string& element); | ||
template <typename T> StringConcat& operator<<(const T &element); | ||
|
||
}; | ||
|
||
/** | ||
* @brief Appends a string to this string. | ||
* @param element the string to append | ||
*/ | ||
inline StringConcat& StringConcat::operator<<(const std::string& element) { | ||
|
||
append(element); | ||
return *this; | ||
} | ||
|
||
/** | ||
* @brief Appends an object to this string. | ||
* @param element the object to append | ||
*/ | ||
template <typename T> | ||
inline StringConcat& StringConcat::operator<<(const T &element) { | ||
|
||
oss.str(""); | ||
oss << element; | ||
append(oss.str()); | ||
return *this; | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.