Commit 3cc10ec9 authored by louiz’'s avatar louiz’

Use nullptr everywhere I can think of

fix #2233
parent 312a406c
......@@ -3,7 +3,7 @@
#define CONF_DEFAULT_PATH "./batajelo.conf"
Config* Config::instance = 0;
Config* Config::instance = nullptr;
bool Config::read_conf(const std::string& filename)
{
......@@ -49,7 +49,7 @@ bool Config::read_conf(const std::string& filename)
std::string Config::get(const std::string& option, const std::string& def)
{
if (instance == 0)
if (instance == nullptr)
{
// We can use a default path, only for testing purpose, to avoid
// the boring Config::read_conf() at the start of every test suite
......@@ -81,7 +81,7 @@ void Config::set_int(const std::string& option, const int& value, bool save)
void Config::set(const std::string& option, const std::string& value, bool save)
{
if (instance == 0)
if (instance == nullptr)
{
std::cerr << "Error: Config::read_conf() has never been called" << std::endl;
return ;
......@@ -110,7 +110,7 @@ void Config::save_to_file() const
void Config::connect(t_config_changed_callback callback)
{
if (instance == 0)
if (instance == nullptr)
{
std::cerr << "Error: Config::read_conf() has never been called" << std::endl;
return ;
......
all: database
MYSQL_FLAGS := $(shell mysql_config --libs) $(shell mysql_config --cflags)
database:
g++ db_object.cpp database.cpp -o database $(MYSQL_FLAGS) ../config/config.cpp ../logging/logging.cpp main.cpp -lboost_date_time
.PHONY: database
......@@ -2,13 +2,13 @@
#include <logging/logging.hpp>
#include <config/config.hpp>
Database* Database::instance = 0;
Database* Database::instance = nullptr;
Database::Database():
mysql(0),
mysql(NULL),
connected(false)
{
if (this->init() == 0)
if (this->init() == false)
throw "5";
}
......@@ -30,7 +30,7 @@ bool Database::init()
Database* Database::inst()
{
if (instance == 0)
if (instance == nullptr)
instance = new Database;
return instance;
}
......
......@@ -21,7 +21,7 @@ void Request::create(const DbObject* sender, const DbObject* receiver)
{
DbObject* request_pending = this->get(sender, receiver);
if (request_pending != NULL)
if (request_pending != nullptr)
{
log_error("This request is pending ! GO BAN LES FDP DE SPAMMER");
}
......@@ -41,7 +41,7 @@ void Request::deny(const DbObject* receiver, const DbObject* sender)
{
DbObject* request_pending = this->get(sender, receiver);
if (request_pending == NULL)
if (request_pending == nullptr)
{
log_warning("Friendship request not found !");
}
......
......@@ -23,7 +23,7 @@ void Replay::reset_action_iterator()
Action* Replay::get_next_action()
{
if (this->actions_iterator == this->actions.end())
return 0;
return nullptr;
Action* action = *this->actions_iterator;
++this->actions_iterator;
return action;
......
......@@ -5,7 +5,7 @@ TurnHandler::TurnHandler(Replay* replay):
current_turn(0),
turn_advancement(0),
paused(true),
next_turn_callback(0),
next_turn_callback(nullptr),
replay(replay)
{
}
......@@ -47,7 +47,7 @@ void TurnHandler::tick(bool force)
void TurnHandler::next_turn()
{
this->current_turn++;
if (this->next_turn_callback != 0)
if (this->next_turn_callback != nullptr)
this->next_turn_callback(this->current_turn);
log_debug("current turn: " << this->current_turn);
// if the deque is empty, no action has to be taken.
......@@ -59,7 +59,7 @@ void TurnHandler::next_turn()
return ;
log_warning("Turn number " << this->current_turn << ": ");
Turn* turn = &(this->turns[0]);
if (this->replay != 0)
if (this->replay != nullptr)
turn->execute(false);
else
turn->execute(true);
......@@ -120,7 +120,7 @@ bool TurnHandler::is_next_turn_validated() const
Turn* TurnHandler::get_turn(const unsigned int number)
{
if (this->turns.size() <= number - this->current_turn)
return 0;
return nullptr;
return &this->turns[number - this->current_turn];
}
......@@ -133,7 +133,7 @@ bool TurnHandler::validate_action(const unsigned int id, const unsigned long int
for (it = this->turns.begin(); it != this->turns.end(); ++it)
{
(*it).reset_action_iterator();
while ((action = (*it).get_next_action()) != 0)
while ((action = (*it).get_next_action()) != nullptr)
{
if (action->get_id() == id)
{
......@@ -157,7 +157,7 @@ void TurnHandler::completely_validate_action(const unsigned int id)
for (it = this->turns.begin(); it != this->turns.end(); ++it)
{
(*it).reset_action_iterator();
while ((action = (*it).get_next_action()) != 0)
while ((action = (*it).get_next_action()) != nullptr)
{
if (action->get_id() == id)
{
......@@ -176,7 +176,7 @@ bool TurnHandler::validate_turn(const unsigned int number,
return false;
}
Turn* turn = this->get_turn(number);
if (turn == 0)
if (turn == nullptr)
return false;
return turn->validate(by, confirmations_needed);
}
......@@ -195,7 +195,7 @@ void TurnHandler::completely_validate_turn(const unsigned int number)
{
this->insert_turn(number);
Turn* turn = this->get_turn(number);
assert(turn != 0);
assert(turn != nullptr);
return turn->validate_completely();
}
......@@ -228,7 +228,7 @@ Turn* TurnHandler::get_next_turn()
if (this->turns_iterator == this->turns.end())
{
this->reset_turns_iterator();
return 0;
return nullptr;
}
std::deque<Turn>::iterator it = this->turns_iterator;
++this->turns_iterator;
......
......@@ -7,7 +7,7 @@ GraphMap::GraphMap()
{
// A value of 0 in a cell means no tile, so the TileGraph
// with gid 0 is NULL;
this->tiles.push_back(0);
this->tiles.push_back(nullptr);
}
GraphMap::~GraphMap()
......@@ -15,7 +15,7 @@ GraphMap::~GraphMap()
std::vector<GraphTile*>::iterator it;
for (it = this->tiles.begin(); it < this->tiles.end(); ++it)
{
if ((*it) != 0)
if ((*it) != nullptr)
delete *it;
}
std::vector<sf::Texture*>::iterator itt;
......@@ -135,9 +135,9 @@ void GraphMap::draw_full_map(sf::RenderTarget& target)
uint level = 0;
this->reset_layers_iterator();
while ((layer = this->get_next_layer()) != 0)
while ((layer = this->get_next_layer()) != nullptr)
{
if (layer->cells == 0)
if (!layer->cells)
continue ;
uint yoffset = level++ * LEVEL_HEIGHT;
for (uint y = 0;
......
#include <gui/current_user.hpp>
#include <logging/logging.hpp>
CurrentUser::CurrentUser() {}
CurrentUser::CurrentUser():teams(nullptr)
{}
CurrentUser::~CurrentUser() {}
CurrentUser::~CurrentUser()
{}
const std::map<std::string, std::string>& CurrentUser::get_current_user() const
{
......
#include <logging/logging.hpp>
#include <config/config.hpp>
Logger* Logger::instance = 0;
Logger* Logger::instance = nullptr;
Logger::Logger():
log_level(atoi(Config::get("log_level", "0").data())),
......@@ -12,7 +12,7 @@ Logger::Logger():
Logger* Logger::inst()
{
if (instance == 0)
if (instance == nullptr)
{
instance = new Logger;
}
......
......@@ -4,7 +4,6 @@
#include <network/remote_game_client.hpp>
#include <network/remote_client.hpp>
#include <network/game_server.hpp>
#include <cstdlib>
int main()
{
......
#include <network/command.hpp>
#include <assert.h>
Command::Command():
body(0),
body_size(0),
callback(0)
callback(nullptr)
{
}
......
......@@ -63,7 +63,7 @@ void GameServer::send_replay(RemoteGameClient* new_client)
Action* action;
Command* command;
ActionEvent* event;
while ((action = replay->get_next_action()) != 0)
while ((action = replay->get_next_action()) != nullptr)
{
event = action->get_event();
command = new Command;
......@@ -82,10 +82,10 @@ void GameServer::send_and_adjust_future_commands(RemoteGameClient* new_client)
TurnHandler* turn_handler = this->world->get_turn_handler();
unsigned int occupants = this->world->get_number_of_occupants();
turn_handler->reset_turns_iterator();
while ((turn = turn_handler->get_next_turn()) != 0)
while ((turn = turn_handler->get_next_turn()) != nullptr)
{
turn->reset_action_iterator();
while ((action = turn->get_next_action()) != 0)
while ((action = turn->get_next_action()) != nullptr)
{
if (action->is_completely_validated() == false)
{
......@@ -109,7 +109,7 @@ void GameServer::adjust_and_revalidate_futur_commands()
unsigned long turn_id = this->world->get_turn_handler()->get_current_turn();
turn_handler->reset_turns_iterator();
while ((turn = turn_handler->get_next_turn()) != 0)
while ((turn = turn_handler->get_next_turn()) != nullptr)
{
if (turn->get_number_of_validations() == occupants)
{
......@@ -117,7 +117,7 @@ void GameServer::adjust_and_revalidate_futur_commands()
turn->validate_completely();
}
turn->reset_action_iterator();
while ((action = turn->get_next_action()) != 0)
while ((action = turn->get_next_action()) != nullptr)
{
if (action->is_completely_validated() == false)
{
......
......@@ -6,14 +6,14 @@ RemoteClient::RemoteClient(boost::asio::io_service& io_service,
Server<RemoteClient>* server):
InterfaceRemoteClient(io_service),
server(server),
user(0)
user(nullptr)
{
}
RemoteClient::~RemoteClient()
{
log_info("Deleting remote client " << this->number);
if (this->user != 0)
if (this->user)
delete this->user;
}
......@@ -44,12 +44,12 @@ void RemoteClient::auth_callback(Command* received_command)
std::string login = arg.substr(0, pos);
std::string password = arg.substr(pos+1);
log_debug(login << ":" << password);
try
try
{
DbObject* user = Database::inst()->get_object("*", "User",
std::string("`login`='" + login + "'"));
std::cout << "USER: " << user << std::endl;
if (user == 0)
if (user == nullptr)
{
log_info("Authentication: User " << login << " does not exist in database.");
body = "2";
......
#include <world/layer.hpp>
Layer::Layer():
cells(0)
cells(nullptr)
{
}
......@@ -37,7 +37,7 @@ void Layer::set_cell(const unsigned int cell, const unsigned int value)
unsigned int Layer::get_cell(const unsigned int cell) const
{
if (this->cells == 0)
if (!this->cells)
return 0;
return this->cells[cell];
}
......@@ -15,7 +15,7 @@ Map::Map():
height(0),
width_in_tiles(0),
height_in_tiles(0),
walking_map(0)
walking_map(nullptr)
{
for (int i = 0; i < LAYER_NUMBER; ++i)
this->layers.push_back(new Layer);
......
......@@ -17,7 +17,7 @@ void ServerWorld::spawn_unit(const size_t type, const int x, const int y)
new_unit->pos = Position(x, y);
DoUnitEvent* e = new DoUnitEvent(new_unit);
e->turn = 1;
Action* action = new Action(0, e, 0);
Action* action = new Action(nullptr, e, 0);
action->validate_completely();
this->replay->insert_action(action);
}
......@@ -70,8 +70,8 @@ void ServerWorld::move_callback(Command* command)
log_debug("move_callback: " << path_event->to_string());
path_event->turn = current_turn + 2;
this->generate_command("PATH", path_event->to_string());
// Action* action = new Action(boost::bind(&World::do_path, this, _1), path_event, this->occupants.size());
Action* action = new Action(0, path_event, this->occupants.size());
// Action* action = new Action(std::bind(&World::do_path, this, std::placeholders::_1), path_event, this->occupants.size());
Action* action = new Action(nullptr, path_event, this->occupants.size());
this->turn_handler->insert_action(action, path_event->turn);
}
......@@ -88,7 +88,7 @@ void ServerWorld::build_callback(Command* command)
DoBuildEvent* doevent = new DoBuildEvent(event);
doevent->turn = this->turn_handler->get_current_turn() + 2;
this->generate_command("BUILD", doevent->to_string());
Action* action = new Action(0, doevent, this->occupants.size());
Action* action = new Action(nullptr, doevent, this->occupants.size());
this->turn_handler->insert_action(action, doevent->turn);
}
......@@ -103,7 +103,7 @@ void ServerWorld::spawn_callback(Command* command)
DoSpawnEvent* doevent = new DoSpawnEvent(event);
doevent->turn = this->turn_handler->get_current_turn() + 2;
this->generate_command("SPAWN", doevent->to_string());
Action* action = new Action(0, doevent, this->occupants.size());
Action* action = new Action(nullptr, doevent, this->occupants.size());
this->turn_handler->insert_action(action, doevent->turn);
}
......
......@@ -151,13 +151,13 @@ Unit* Unit::get_unit_ahead(const Vec2& mov, World* world) const
return unit;
}
}
return 0;
return nullptr;
}
bool Unit::will_collide_if_we_move(Vec2& mov, World* world) const
{
Unit* unit = this->get_unit_ahead(mov, world);
if (unit != 0)
if (unit != nullptr)
return true;
if (this->is_wall_ahead(mov, world) == true)
return true;
......
......@@ -20,7 +20,7 @@ BuildWork::BuildWork(Unit* unit, const unsigned short id, const short x, const s
id(id),
x(x),
y(y),
building(0)
building(nullptr)
{}
SpawnWork::SpawnWork(Building* building, const unsigned short id):
......
......@@ -22,7 +22,7 @@ BOOST_AUTO_TEST_CASE(empty_user)
{
BOOST_TEST_MESSAGE("Testing 0 row result");
DbObject* user1 = Database::inst()->get_object("*", "User", "id=1");
BOOST_REQUIRE(user1 == 0);
BOOST_REQUIRE(user1 == nullptr);
delete user1;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment