Skip to content
This repository has been archived by the owner on Jun 7, 2018. It is now read-only.

Commit

Permalink
Rename Debug::assert() to Debug::check_assertion() to avoid conflicts
Browse files Browse the repository at this point in the history
with the assert() macro
  • Loading branch information
christopho authored and Christophe THIÉRY committed Feb 10, 2012
1 parent df6066c commit e68f89b
Show file tree
Hide file tree
Showing 52 changed files with 147 additions and 147 deletions.
4 changes: 2 additions & 2 deletions include/lowlevel/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Debug {
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 check_assertion(bool assertion, const std::string &error_message = "");
static void die(const std::string &error_message = "");
};

Expand Down Expand Up @@ -66,7 +66,7 @@ inline void Debug::print(const std::string &message, std::ostream &os) {
* @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) {
inline void Debug::check_assertion(bool assertion, const std::string &error_message) {

if (!assertion) {
print(error_message, std::cerr);
Expand Down
6 changes: 3 additions & 3 deletions src/DialogBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ const std::string& DialogBox::get_variable() {

const std::string &value = variables[first_message_id];

Debug::assert(value.size() > 0, StringConcat() << "Missing variable in message '" << current_message_id << "'");
Debug::check_assertion(value.size() > 0, StringConcat() << "Missing variable in message '" << current_message_id << "'");

return value;
}
Expand All @@ -244,7 +244,7 @@ int DialogBox::get_last_answer() {
*/
void DialogBox::set_last_answer(int answer) {

Debug::assert(answer >= -1 && answer <= 1, StringConcat() << "Invalid value of answer: " << answer);
Debug::check_assertion(answer >= -1 && answer <= 1, StringConcat() << "Invalid value of answer: " << answer);
this->last_answer = answer;
}

Expand All @@ -259,7 +259,7 @@ void DialogBox::set_last_answer(int answer) {
void DialogBox::start_dialog(const MessageId &first_message_id, Script *issuer_script,
VerticalPosition vertical_position) {

Debug::assert(!is_enabled(), StringConcat() << "Cannot start message sequence '" << first_message_id << ": the dialog box is already enabled");
Debug::check_assertion(!is_enabled(), StringConcat() << "Cannot start message sequence '" << first_message_id << ": the dialog box is already enabled");

// save the action and sword keys
KeysEffect &keys_effect = game.get_keys_effect();
Expand Down
44 changes: 22 additions & 22 deletions src/Equipment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Equipment::~Equipment() {
*/
ItemScript& Equipment::get_item_script(const std::string &item_name) {

Debug::assert(item_scripts.count(item_name) != 0,
Debug::check_assertion(item_scripts.count(item_name) != 0,
StringConcat() << "Cannot find item script '" << item_name << "'");

return *item_scripts[item_name];
Expand All @@ -84,7 +84,7 @@ ItemScript& Equipment::get_item_script(const std::string &item_name) {
*/
void Equipment::set_game(Game &game) {

Debug::assert(this->game == NULL, "The game is already set");
Debug::check_assertion(this->game == NULL, "The game is already set");

this->game = &game;

Expand Down Expand Up @@ -191,7 +191,7 @@ int Equipment::get_max_money() {
*/
void Equipment::set_max_money(int max_money) {

Debug::assert(max_money > 0, StringConcat() << "Illegal maximum amount of money: " << max_money);
Debug::check_assertion(max_money > 0, StringConcat() << "Illegal maximum amount of money: " << max_money);

savegame.set_integer(Savegame::MAX_MONEY, max_money);
}
Expand All @@ -214,7 +214,7 @@ int Equipment::get_money() {
*/
void Equipment::set_money(int money) {

Debug::assert(money >= 0 && money <= get_max_money(), StringConcat() << "Illegal amount of money: " << money);
Debug::check_assertion(money >= 0 && money <= get_max_money(), StringConcat() << "Illegal amount of money: " << money);

savegame.set_integer(Savegame::CURRENT_MONEY, money);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ int Equipment::get_max_life() {
*/
void Equipment::set_max_life(int max_life) {

Debug::assert(max_life > 0, StringConcat() << "Illegal maximum life: " << max_life);
Debug::check_assertion(max_life > 0, StringConcat() << "Illegal maximum life: " << max_life);

savegame.set_integer(Savegame::MAX_LIFE, max_life);
}
Expand All @@ -290,7 +290,7 @@ int Equipment::get_life() {
*/
void Equipment::set_life(int life) {

Debug::assert(life >= 0 && life <= get_max_life(), StringConcat() << "Illegal level of life: " << life);
Debug::check_assertion(life >= 0 && life <= get_max_life(), StringConcat() << "Illegal level of life: " << life);

savegame.set_integer(Savegame::CURRENT_LIFE, life);
}
Expand Down Expand Up @@ -347,7 +347,7 @@ int Equipment::get_max_magic() {
*/
void Equipment::set_max_magic(int max_magic) {

Debug::assert(max_magic >= 0, StringConcat() << "Illegal maximum number of magic points: " << max_magic);
Debug::check_assertion(max_magic >= 0, StringConcat() << "Illegal maximum number of magic points: " << max_magic);

savegame.set_integer(Savegame::MAX_MAGIC, max_magic);

Expand All @@ -372,7 +372,7 @@ int Equipment::get_magic() {
*/
void Equipment::set_magic(int magic) {

Debug::assert(magic >= 0 && magic <= get_max_magic(), StringConcat() << "Illegal number of magic points: " << magic);
Debug::check_assertion(magic >= 0 && magic <= get_max_magic(), StringConcat() << "Illegal number of magic points: " << magic);

savegame.set_integer(Savegame::CURRENT_MAGIC, magic);
}
Expand Down Expand Up @@ -427,7 +427,7 @@ bool Equipment::is_magic_decreasing() {
*/
void Equipment::start_removing_magic(uint32_t delay) {

Debug::assert(delay > 0, StringConcat() << "Illegal magic bar decrease delay: " << delay);
Debug::check_assertion(delay > 0, StringConcat() << "Illegal magic bar decrease delay: " << delay);

if (get_magic() > 0) {
this->magic_decrease_delay = delay;
Expand All @@ -453,7 +453,7 @@ void Equipment::stop_removing_magic() {
ItemProperties& Equipment::get_item_properties(const std::string &item_name) {

ItemProperties *properties = item_properties[item_name];
Debug::assert(properties != NULL, StringConcat() << "Cannot find item with name '" << item_name << "'");
Debug::check_assertion(properties != NULL, StringConcat() << "Cannot find item with name '" << item_name << "'");
return *properties;
}

Expand Down Expand Up @@ -499,8 +499,8 @@ void Equipment::set_item_variant(const std::string &item_name, int variant) {

ItemProperties &properties = get_item_properties(item_name);
int index = properties.get_savegame_variable();
Debug::assert(index != -1, StringConcat() << "The item '" << item_name << "' is not saved");
Debug::assert(variant >= 0 && variant <= properties.get_nb_variants(),
Debug::check_assertion(index != -1, StringConcat() << "The item '" << item_name << "' is not saved");
Debug::check_assertion(variant >= 0 && variant <= properties.get_nb_variants(),
StringConcat() << "Invalid variant '" << variant << "' for item '" << item_name);

// set the possession state in the savegame
Expand Down Expand Up @@ -539,7 +539,7 @@ void Equipment::remove_item(const std::string &item_name) {
int Equipment::get_item_amount(const std::string &item_name) {

int counter_index = get_item_properties(item_name).get_counter_savegame_variable();
Debug::assert(counter_index != -1, StringConcat() << "No amount for item '" << item_name << "'");
Debug::check_assertion(counter_index != -1, StringConcat() << "No amount for item '" << item_name << "'");

return savegame.get_integer(counter_index);
}
Expand All @@ -558,8 +558,8 @@ void Equipment::set_item_amount(const std::string &item_name, int amount) {
int counter_index = get_item_properties(item_name).get_counter_savegame_variable();
int max = get_item_maximum(item_name);

Debug::assert(counter_index != -1, StringConcat() << "No amount for item '" << item_name << "'");
Debug::assert(amount >= 0 && amount <= max, StringConcat() << "Illegal amount for item '" << item_name << "': " << amount);
Debug::check_assertion(counter_index != -1, StringConcat() << "No amount for item '" << item_name << "'");
Debug::check_assertion(amount >= 0 && amount <= max, StringConcat() << "Illegal amount for item '" << item_name << "': " << amount);

savegame.set_integer(counter_index, amount);

Expand Down Expand Up @@ -608,11 +608,11 @@ int Equipment::get_item_maximum(const std::string &item_name) {
int fixed_limit = properties.get_fixed_limit();
if (fixed_limit != 0) {
maximum = fixed_limit;
Debug::assert(maximum > 0, StringConcat() << "No maximum amount for item '" << item_name << "'");
Debug::check_assertion(maximum > 0, StringConcat() << "No maximum amount for item '" << item_name << "'");
}
else {
const std::string &item_limiting = properties.get_item_limiting();
Debug::assert(item_limiting.size() != 0,
Debug::check_assertion(item_limiting.size() != 0,
StringConcat() << "No maximum amount for item '" << item_name << "'");
int item_limiting_variant = get_item_variant(item_limiting);
maximum = get_item_properties(item_limiting).get_amount(item_limiting_variant);
Expand Down Expand Up @@ -718,8 +718,8 @@ const std::string Equipment::get_item_assigned(int slot) {
void Equipment::set_item_assigned(int slot, const std::string &item_name) {

if (item_name.size() != 0) {
Debug::assert(has_item(item_name), StringConcat() << "Cannot assign item '" << item_name << "' because the player does not have it");
Debug::assert(get_item_properties(item_name).can_be_assigned(), StringConcat() << "The item '" << item_name << "' cannot be assigned");
Debug::check_assertion(has_item(item_name), StringConcat() << "Cannot assign item '" << item_name << "' because the player does not have it");
Debug::check_assertion(get_item_properties(item_name).can_be_assigned(), StringConcat() << "The item '" << item_name << "' cannot be assigned");
}

int index = Savegame::ITEM_SLOT_0 + slot;
Expand Down Expand Up @@ -762,7 +762,7 @@ bool Equipment::are_small_keys_enabled() {
*/
int Equipment::get_small_keys_variable() {

Debug::assert(are_small_keys_enabled(), "The small keys are not enabled on this map");
Debug::check_assertion(are_small_keys_enabled(), "The small keys are not enabled on this map");

return game->get_current_map().get_small_keys_variable();
}
Expand Down Expand Up @@ -807,7 +807,7 @@ void Equipment::add_small_keys(int amount_to_add) {
*/
void Equipment::remove_small_key() {

Debug::assert(has_small_key(), "The player has no small keys");
Debug::check_assertion(has_small_key(), "The player has no small keys");

int index = get_small_keys_variable();
savegame.set_integer(index, get_small_keys() - 1);
Expand Down Expand Up @@ -864,7 +864,7 @@ int Equipment::get_ability_savegame_variable(const std::string &ability_name) {
index = Savegame::DUNGEON_1_ABILITY_OPEN_BOSS_LOCK + 10 * (get_current_dungeon() - 1);
}

Debug::assert(index != -1, StringConcat() << "Unknown ability '" << ability_name << "'");
Debug::check_assertion(index != -1, StringConcat() << "Unknown ability '" << ability_name << "'");

return index;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ const Rectangle& Game::get_outside_world_size() {
ini.set_group("info");
int width = ini.get_integer_value("outside_world_width", 0);
int height = ini.get_integer_value("outside_world_height", 0);
Debug::assert(width > 0 && height > 0, "Missing outside world size in file quest.dat");
Debug::check_assertion(width > 0 && height > 0, "Missing outside world size in file quest.dat");
outside_world_size.set_size(width, height);
}
return outside_world_size;
Expand Down
2 changes: 1 addition & 1 deletion src/GameControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ bool GameControls::is_customizing() {
*/
GameControls::GameKey GameControls::get_key_to_customize() {

Debug::assert(is_customizing(), "The player is not customizing a key");
Debug::check_assertion(is_customizing(), "The player is not customizing a key");
return key_to_customize;
}

Expand Down
2 changes: 1 addition & 1 deletion src/InventoryItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ int InventoryItem::get_variant() {
*/
void InventoryItem::start() {

Debug::assert(variant > 0, StringConcat() << "Trying to use inventory item '" << item_name << "' without having it");
Debug::check_assertion(variant > 0, StringConcat() << "Trying to use inventory item '" << item_name << "' without having it");

this->finished = false;
game.get_equipment().get_item_script(item_name).event_use(*this);
Expand Down
2 changes: 1 addition & 1 deletion src/Message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void Message::parse(MessageId message_id) {
// parse the message
IniFile ini_file(file_name, IniFile::READ_LANGUAGE);

Debug::assert(ini_file.has_group(message_id), StringConcat() << "The message '" << message_id << "' does not exist");
Debug::check_assertion(ini_file.has_group(message_id), StringConcat() << "The message '" << message_id << "' does not exist");
ini_file.set_group(message_id);

// text
Expand Down
6 changes: 3 additions & 3 deletions src/Savegame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Savegame::Savegame(const std::string &file_name):
char *buffer;

FileTools::data_file_open_buffer(file_name, &buffer, &size);
Debug::assert(size == sizeof(SavedData), StringConcat() << "Cannot read savegame file '" << file_name << "': invalid file size");
Debug::check_assertion(size == sizeof(SavedData), StringConcat() << "Cannot read savegame file '" << file_name << "': invalid file size");
memcpy(&saved_data, buffer, sizeof(SavedData));
FileTools::data_file_close_buffer(buffer);

Expand Down Expand Up @@ -110,9 +110,9 @@ void Savegame::set_initial_values() {
const std::string &starting_destination_point_name = ini.get_string_value("starting_point", "");
int max_life = ini.get_integer_value("max_life", 1);

Debug::assert(starting_map_id != -1,
Debug::check_assertion(starting_map_id != -1,
"No starting map defined in quest.dat. Please set the value starting_map to the id of the initial map of your quest.");
Debug::assert(starting_destination_point_name.size() != 0,
Debug::check_assertion(starting_destination_point_name.size() != 0,
"No starting point defined in quest.dat. Please set the value starting_point to the name of the "
"destination point where the hero should be placed on the initial map.");

Expand Down
4 changes: 2 additions & 2 deletions src/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void Sprite::set_current_animation(const std::string &animation_name) {

SpriteAnimation *animation = animation_set.get_animation(animation_name);

Debug::assert(animation != NULL, StringConcat() << "Unknown animation '" << animation_name << "' for animation set '" << animation_set_id << "'");
Debug::check_assertion(animation != NULL, StringConcat() << "Unknown animation '" << animation_name << "' for animation set '" << animation_set_id << "'");

this->current_animation_name = animation_name;
this->current_animation = animation;
Expand Down Expand Up @@ -265,7 +265,7 @@ void Sprite::set_current_direction(int current_direction) {

if (current_direction != this->current_direction) {

Debug::assert(current_direction >= 0, StringConcat() << "Invalid sprite direction: " << current_direction);
Debug::check_assertion(current_direction >= 0, StringConcat() << "Invalid sprite direction: " << current_direction);

this->current_direction = current_direction;
set_current_frame(0);
Expand Down
2 changes: 1 addition & 1 deletion src/SpriteAnimation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool SpriteAnimation::is_looping() const {
*/
int SpriteAnimation::get_next_frame(int current_direction, int current_frame) const {

Debug::assert(current_direction >= 0 && current_direction < nb_directions,
Debug::check_assertion(current_direction >= 0 && current_direction < nb_directions,
StringConcat() << "Invalid sprite direction '" << current_direction
<< "': this sprite animation has only " << nb_directions << " direction(s)");

Expand Down
2 changes: 1 addition & 1 deletion src/SpriteAnimationDirection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ bool SpriteAnimationDirection::are_pixel_collisions_enabled() const {
*/
PixelBits * SpriteAnimationDirection::get_pixel_bits(int frame) const {

Debug::assert(pixel_bits != NULL, ("The pixel collisions are not enabled for this sprite"));
Debug::check_assertion(pixel_bits != NULL, ("The pixel collisions are not enabled for this sprite"));

return pixel_bits[frame];
}
Expand Down
6 changes: 3 additions & 3 deletions src/SpriteAnimationSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ SpriteAnimationSet::SpriteAnimationSet(const SpriteAnimationSetId &id) {
directions[i] = new SpriteAnimationDirection(nb_frames, positions_in_src, x_origin, y_origin);
}

Debug::assert(animations.count(name) == 0, StringConcat() << "Animation '" << name << "' is defined twice in sprite '" << id << "'");
Debug::check_assertion(animations.count(name) == 0, StringConcat() << "Animation '" << name << "' is defined twice in sprite '" << id << "'");
animations[name] = new SpriteAnimation(image_file_name, nb_directions, directions,
frame_delay, loop_on_frame);

Expand Down Expand Up @@ -157,7 +157,7 @@ void SpriteAnimationSet::set_map(Map &map) {
*/
const SpriteAnimation * SpriteAnimationSet::get_animation(const std::string &animation_name) const {

Debug::assert(animations.count(animation_name) > 0,
Debug::check_assertion(animations.count(animation_name) > 0,
StringConcat() << "No animation '" << animation_name << "' in this animation set");

return animations.find(animation_name)->second; // the [] operator is not const in std::map
Expand All @@ -170,7 +170,7 @@ const SpriteAnimation * SpriteAnimationSet::get_animation(const std::string &ani
*/
SpriteAnimation * SpriteAnimationSet::get_animation(const std::string &animation_name) {

Debug::assert(animations.count(animation_name) > 0,
Debug::check_assertion(animations.count(animation_name) > 0,
StringConcat() << "No animation '" << animation_name << "' in this animation set");

return animations[animation_name];
Expand Down
4 changes: 2 additions & 2 deletions src/StringResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void StringResource::initialize() {

// get the value
size_t index = line.find_last_of("\t");
Debug::assert(index != std::string::npos && index + 1 < line.size(),
Debug::check_assertion(index != std::string::npos && index + 1 < line.size(),
StringConcat() << "strings.dat, line " << i << ": cannot read string value for key '" << key << "'");
strings[key] = line.substr(index + 1);
}
Expand All @@ -84,7 +84,7 @@ void StringResource::quit() {
*/
const std::string& StringResource::get_string(const std::string& key) {

Debug::assert(strings.count(key) > 0, StringConcat() << "Cannot find string with key '" << key << "'");
Debug::check_assertion(strings.count(key) > 0, StringConcat() << "Cannot find string with key '" << key << "'");
return strings[key];
}

2 changes: 1 addition & 1 deletion src/Transition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Transition::Direction Transition::get_direction() {
*/
void Transition::set_previous_surface(Surface *previous_surface) {

Debug::assert(get_direction() != OUT, "Cannot show a previous surface with an OUT transition effect");
Debug::check_assertion(get_direction() != OUT, "Cannot show a previous surface with an OUT transition effect");

this->previous_surface = previous_surface;
}
Expand Down
2 changes: 1 addition & 1 deletion src/TransitionScrolling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ void TransitionScrolling::display(Surface *surface) {
return;
}

Debug::assert(previous_surface != NULL, "No previous surface defined for scrolling");
Debug::check_assertion(previous_surface != NULL, "No previous surface defined for scrolling");

// draw the old map
previous_surface->blit(both_maps_surface, previous_map_dst_position);
Expand Down
4 changes: 2 additions & 2 deletions src/Treasure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ ItemProperties& Treasure::get_item_properties() const {
*/
const std::string& Treasure::get_item_name() const {

Debug::assert(item_name != "_random", "This treasure has a random content and it is not decided yet");
Debug::assert(item_name == "_none" || game.get_equipment().can_receive_item(item_name, variant),
Debug::check_assertion(item_name != "_random", "This treasure has a random content and it is not decided yet");
Debug::check_assertion(item_name == "_none" || game.get_equipment().can_receive_item(item_name, variant),
"This treasure is not authorized by the equipment, did you call decide_content()?");

return item_name;
Expand Down
2 changes: 1 addition & 1 deletion src/enemies/Bubble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void Bubble::restart() {
*/
void Bubble::go(int movement_direction8) {

Debug::assert(movement_direction8 == 1
Debug::check_assertion(movement_direction8 == 1
|| movement_direction8 == 3
|| movement_direction8 == 5
|| movement_direction8 == 7,
Expand Down
Loading

0 comments on commit e68f89b

Please sign in to comment.