Commit 8a46bc90 authored by louiz’'s avatar louiz’

Use std::bind and std::function everywhere.

fixes #2257
parent 3cc10ec9
......@@ -19,9 +19,9 @@
#include <iostream>
#include <string>
#include <boost/algorithm/string/trim_all.hpp>
#include <boost/function.hpp>
#include <functional>
typedef boost::function<void()> t_config_changed_callback;
typedef std::function<void()> t_config_changed_callback;
class Config
{
......
......@@ -12,7 +12,7 @@
# define __ACTION_HPP__
#include <vector>
#include <boost/function.hpp>
#include <functional>
#include <game/event.hpp>
......@@ -29,7 +29,7 @@ namespace actions
};
}
typedef boost::function< void(ActionEvent*) > t_action_callback;
typedef std::function< void(ActionEvent*) > t_action_callback;
class Action
{
......
......@@ -8,7 +8,7 @@
*/
#include <deque>
#include <boost/function.hpp>
#include <functional>
#ifndef __TURN_HANDLER_HPP__
# define __TURN_HANDLER_HPP__
......@@ -17,7 +17,7 @@
#include <game/action.hpp>
#include <game/replay.hpp>
typedef boost::function< void(unsigned long) > t_next_turn_callback;
typedef std::function< void(unsigned long) > t_next_turn_callback;
/**
* The number of ticks contained in a turn
......
#ifndef __ACTION_PANEL_BUTTON_HPP__
# define __ACTION_PANEL_BUTTON_HPP__
#include <boost/function.hpp>
#include <functional>
#include <SFML/Graphics.hpp>
#include <gui/cursor.hpp>
......@@ -10,7 +10,7 @@
* (which should be ignored in some cases, for example if we target an
* entity) and a type_id.
*/
typedef boost::function<bool(const unsigned int, const unsigned int, const std::size_t)> t_left_click_callback;
typedef std::function<bool(const unsigned int, const unsigned int, const std::size_t)> t_left_click_callback;
/**
* A function that should be called when drawing the cursor. For example if
......@@ -19,7 +19,7 @@ typedef boost::function<bool(const unsigned int, const unsigned int, const std::
* may draw a building (with transparency or whatever) indicating the
* position where the building would go if the user actually clicked.
*/
typedef boost::function<cursor::type (const unsigned int, const unsigned int, const std::size_t)> t_draw_cursor_action;
typedef std::function<cursor::type (const unsigned int, const unsigned int, const std::size_t)> t_draw_cursor_action;
/**
* a structure containing various elements to pass to the left click callback (for example if this is cast_spell, the structure contains the type_id of the spell).
......@@ -41,7 +41,7 @@ struct t_left_click
std::size_t id;
};
typedef boost::function<void(const t_left_click)> t_action_panel_button_callback;
typedef std::function<void(const t_left_click)> t_action_panel_button_callback;
class ActionPanelButton
{
......
#include <boost/bind.hpp>
#include <functional>
#include <gui/hud/action_panel_table.hpp>
#include <gui/cursor.hpp>
#include <assert.h>
ActionPanelTable::ActionPanelTable():
current_page(0)
{
......
#include <boost/bind.hpp>
#include <functional>
#include <gui/hud/hud.hpp>
#include <world/entity.hpp>
......@@ -12,7 +11,7 @@ Hud::Hud(GraphMap* map, ClientWorld* world, sf::RenderWindow* win, Camera* camer
{
// Install a callback on the selection that will reset the action_panel
// whenever the selection is modified.
world->add_selection_change_callback(boost::bind(&ActionPanel::reset_all_tables, &this->action_panel));
world->add_selection_change_callback(std::bind(&ActionPanel::reset_all_tables, &this->action_panel));
this->hud_texture.loadFromFile("./data/images/hud.png");
this->hud_sprite.setTexture(this->hud_texture);
this->hud_sprite.setPosition(0, win->getSize().y - HUD_HEIGHT);
......
......@@ -19,8 +19,8 @@ void NetworkToUi::on_login_form_validated(const std::string& login,
const short& port)
{
this->client.connect(host, port,
boost::bind(&NetworkToUi::on_connection_success, this, login, password),
boost::bind(&NetworkToUi::on_connection_failed, this, host, port));
std::bind(&NetworkToUi::on_connection_success, this, login, password),
std::bind(&NetworkToUi::on_connection_failed, this, host, port));
}
void NetworkToUi::on_connection_failed(const std::string& host, const short& port)
......@@ -45,7 +45,7 @@ void NetworkToUi::authenticate(const std::string& login, const std::string& pass
std::string body = login + '*' + password;
log_error(body);
command->set_body(body.data(), body.size());
this->client.request_answer(command, boost::bind(&Ui::on_authenticate, this->ui, _1));
this->client.request_answer(command, std::bind(&Ui::on_authenticate, this->ui, std::placeholders::_1));
}
void NetworkToUi::request_file(const std::string& filename)
......
......@@ -3,7 +3,7 @@
#include <logging/logging.hpp>
#include <config/config.hpp>
#include <SFML/System.hpp>
#include <boost/bind.hpp>
#include <functional>
#include <sha.h>
#include <base64.h>
#include <translation/translation.hpp>
......@@ -19,7 +19,7 @@ void Login::connect()
std::string login = this->entry_login->GetText().toAnsiString();
std::string password = this->entry_pass->GetText().toAnsiString();
std::string digest;
CryptoPP::SHA256 hash;
CryptoPP::SHA256 hash;
if (this->entry_login->GetText() != "" && password != "")
{
......@@ -37,7 +37,7 @@ void Login::hide()
{
this->window_menu->Show(false);
this->window_login->Show(false);
this->remember_login->Show(false);
this->remember_login->Show(false);
}
void Login::show()
......@@ -204,7 +204,7 @@ void Login::handle_keys_connect()
{
this->ui->set_event_handled(false);
this->connect();
}
}
else if (this->ui->get_key() == sf::Keyboard::Tab && this->ui->get_event_handled() == true)
{
this->ui->set_event_handled(false);
......@@ -218,4 +218,4 @@ void Login::on_authenticate_success()
{
Config::set("login", this->entry_login->GetText().toAnsiString(), true);
}
}
\ No newline at end of file
}
......@@ -18,27 +18,27 @@ int main()
map->load_from_file("test4.tmx");
ClientMod mod("monsters.yaml");
ClientWorld* world = new ClientWorld(map, mod);
world->set_next_turn_callback(boost::bind(&ClientWorld::on_next_turn, world, _1));
world->set_next_turn_callback(std::bind(&ClientWorld::on_next_turn, world, std::placeholders::_1));
c->install_callback("NEW_OCCUPANT",
boost::bind(&ClientWorld::new_occupant_callback, world, _1));
std::bind(&ClientWorld::new_occupant_callback, world, std::placeholders::_1));
c->install_callback("OCCUPANT_LEFT",
boost::bind(&ClientWorld::occupant_left_callback, world, _1));
std::bind(&ClientWorld::occupant_left_callback, world, std::placeholders::_1));
c->install_callback("NEW_UNIT",
boost::bind(&ClientWorld::new_unit_callback, world, _1));
std::bind(&ClientWorld::new_unit_callback, world, std::placeholders::_1));
c->install_callback("START",
boost::bind(&ClientWorld::handle_start_command, world, _1));
std::bind(&ClientWorld::handle_start_command, world, std::placeholders::_1));
c->install_callback("OK",
boost::bind(&ClientWorld::ok_callback, world, _1));
std::bind(&ClientWorld::ok_callback, world, std::placeholders::_1));
c->install_callback("T",
boost::bind(&ClientWorld::turn_callback, world, _1));
std::bind(&ClientWorld::turn_callback, world, std::placeholders::_1));
c->install_callback("PATH",
boost::bind(&ClientWorld::path_callback, world, _1));
std::bind(&ClientWorld::path_callback, world, std::placeholders::_1));
c->install_callback("BUILD",
boost::bind(&ClientWorld::build_callback, world, _1));
std::bind(&ClientWorld::build_callback, world, std::placeholders::_1));
c->install_callback("SPAWN",
boost::bind(&ClientWorld::spawn_callback, world, _1));
std::bind(&ClientWorld::spawn_callback, world, std::placeholders::_1));
// c->connect("88.190.23.192", 7879);
c->connect("127.0.0.1", 7879);
......
#include <boost/bind.hpp>
#include <functional>
#include <logging/logging.hpp>
#include <gui/screen/screen.hpp>
#include <mod/client_mod.hpp>
......@@ -84,10 +83,10 @@ void ClientMod::fill_default_unit_actions(Screen* screen, ActionPanelTable* tabl
t_left_click left_click = null_left;
// Move button
left_click.callback = boost::bind(&ClientWorld::action_move, screen->get_world(), _1, _2, _3);
left_click.cursor_callback = boost::bind(&Screen::draw_move_cursor, screen, _1, _2, _3);
left_click.callback = std::bind(&ClientWorld::action_move, screen->get_world(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
left_click.cursor_callback = std::bind(&Screen::draw_move_cursor, screen, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
page->add_button(new ActionPanelButton("move.png",
boost::bind(&Screen::set_left_click_callback, screen, _1), 0, left_click), 0);
std::bind(&Screen::set_left_click_callback, screen, std::placeholders::_1), 0, left_click), 0);
// Empty buttons, yet
page->add_button(new ActionPanelButton("stop.png",
......@@ -117,21 +116,21 @@ void ClientMod::add_action_to_table(ActionPanelTable* table, const ModActionInfo
this->add_empty_pages(table, infos.value + 1); // To be able to switch to the page.
// Indicate what page we switch to when clicking the button.
left_click.id = infos.value;
button = new ActionPanelButton(infos.image_filename, boost::bind(&ActionPanelTable::action_change_current_page, table, _1), infos.position, left_click);
button = new ActionPanelButton(infos.image_filename, std::bind(&ActionPanelTable::action_change_current_page, table, std::placeholders::_1), infos.position, left_click);
}
else if (infos.type == "build")
{
left_click.id = infos.value;
left_click.callback = boost::bind(&ClientWorld::action_build, screen->get_world(), _1, _2, _3);
left_click.cursor_callback = boost::bind(&Screen::draw_build_cursor, screen, _1, _2, _3);
button = new ActionPanelButton(infos.image_filename, boost::bind(&Screen::set_left_click_callback, screen, _1), infos.position, left_click);
left_click.callback = std::bind(&ClientWorld::action_build, screen->get_world(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
left_click.cursor_callback = std::bind(&Screen::draw_build_cursor, screen, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
button = new ActionPanelButton(infos.image_filename, std::bind(&Screen::set_left_click_callback, screen, std::placeholders::_1), infos.position, left_click);
}
else if (infos.type == "spawn")
{
left_click.id = infos.value;
left_click.callback = 0;
left_click.cursor_callback = 0;
button = new ActionPanelButton(infos.image_filename, boost::bind(&ClientWorld::action_spawn, screen->get_world(), _1), infos.position, left_click);
button = new ActionPanelButton(infos.image_filename, std::bind(&ClientWorld::action_spawn, screen->get_world(), std::placeholders::_1), infos.position, left_click);
}
else
{
......
......@@ -12,7 +12,7 @@ Client::~Client()
void Client::install_callbacks()
{
this->install_callback("TRANSFER", boost::bind(&Client::transfer_init_callback, this, _1));
this->install_callback("TRANSFER", std::bind(&Client::transfer_init_callback, this, std::placeholders::_1));
}
void Client::transfer_init_callback(Command* received_command)
......
......@@ -27,8 +27,7 @@
#include <cstring>
#include <fstream>
#include <sstream>
#include <boost/function.hpp>
#include <functional>
#ifndef __COMMAND_HPP__
# define __COMMAND_HPP__
......@@ -70,7 +69,7 @@ public:
/**
* If not 0, will be called from the send_handler.
*/
boost::function< void(void) > callback;
std::function< void(void) > callback;
private:
Command& operator=(const Command&);
......
......@@ -106,10 +106,10 @@ void CommandHandler::read_handler(const boost::system::error_code& error, const
boost::asio::async_read(*this->socket,
this->data,
boost::asio::transfer_at_least(length_to_read),
boost::bind(&CommandHandler::binary_read_handler, this,
boost::asio::placeholders::error,
command,
size, callback));
std::bind(&CommandHandler::binary_read_handler, this,
std::placeholders::_1,
command,
size, callback));
}
void CommandHandler::binary_read_handler(const boost::system::error_code& error,
......@@ -140,9 +140,9 @@ void CommandHandler::install_read_handler(void)
boost::asio::async_read_until(*this->socket,
this->data,
':',
boost::bind(&CommandHandler::read_handler, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred));
std::bind(&CommandHandler::read_handler, this,
std::placeholders::_1,
std::placeholders::_2));
}
void CommandHandler::request_answer(Command* command, t_read_callback on_answer, std::string name)
......@@ -153,7 +153,7 @@ void CommandHandler::request_answer(Command* command, t_read_callback on_answer,
this->send(command);
}
void CommandHandler::send(Command* command, boost::function< void(void) > on_sent)
void CommandHandler::send(Command* command, std::function< void(void) > on_sent)
{
if (on_sent)
command->callback = on_sent;
......@@ -181,10 +181,10 @@ void CommandHandler::actually_send(Command* command)
buffs.push_back(boost::asio::buffer(command->body, command->body_size));
async_write(*this->socket,
buffs,
boost::bind(&CommandHandler::send_handler, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred,
command));
std::bind(&CommandHandler::send_handler, this,
std::placeholders::_1,
std::placeholders::_2,
command));
}
void CommandHandler::send_handler(const boost::system::error_code& error,
......
......@@ -11,9 +11,8 @@
#include <deque>
#include <map>
#include <boost/function.hpp>
#include <functional>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#ifndef __COMMAND_HANDLER_HPP__
# define __COMMAND_HANDLER_HPP__
......@@ -23,7 +22,7 @@
using boost::asio::ip::tcp;
typedef boost::function<void(Command*)> t_read_callback;
typedef std::function<void(Command*)> t_read_callback;
typedef std::deque<Command*> command_queue;
class CommandHandler
......@@ -72,7 +71,7 @@ public:
* command, if there's no async_write() call already running.
* It does not necessarily actually send the command on the socket.
*/
void send(Command* command, boost::function< void(void) > on_sent = 0);
void send(Command* command, std::function< void(void) > on_sent = 0);
protected:
/**
......
......@@ -29,8 +29,8 @@ public:
void new_client_callback(Command*);
private:
void connect_handler(boost::function< void(void) >,
boost::function< void(void) >,
void connect_handler(std::function< void(void) >,
std::function< void(void) >,
const boost::system::error_code&);
boost::asio::io_service io_service;
};
......
......@@ -31,21 +31,21 @@ InterfaceClient::~InterfaceClient()
// Connect, asyncly, and call one of the given callbacks
void InterfaceClient::connect(const std::string& host,
const short& port,
boost::function< void(void) > on_success,
boost::function< void(void) > on_failure)
const short& port,
std::function< void(void) > on_success,
std::function< void(void) > on_failure)
{
// TODO use resolve and DNS
tcp::endpoint endpoint(boost::asio::ip::address::from_string(host), port);
this->socket->async_connect(endpoint,
boost::bind(&InterfaceClient::connect_handler, this,
on_success, on_failure,
boost::asio::placeholders::error));
std::bind(&InterfaceClient::connect_handler, this,
on_success, on_failure,
std::placeholders::_1));
log_info("Connecting to " << host << ":" << port);
}
void InterfaceClient::connect_handler(boost::function< void(void) > on_success,
boost::function< void(void) > on_failure,
void InterfaceClient::connect_handler(std::function< void(void) > on_success,
std::function< void(void) > on_failure,
const boost::system::error_code& error)
{
if (error)
......@@ -57,7 +57,7 @@ void InterfaceClient::connect_handler(boost::function< void(void) > on_success,
else
{
log_info("Connected.");
this->install_callback("PING", boost::bind(&InterfaceClient::ping_callback, this, _1));
this->install_callback("PING", std::bind(&InterfaceClient::ping_callback, this, std::placeholders::_1));
this->install_callbacks();
this->install_read_handler();
if (on_success)
......
......@@ -11,8 +11,7 @@
*/
#include <boost/asio.hpp>
#include <boost/function.hpp>
#include <boost/bind.hpp>
#include <functional>
#include <string>
#include <cstdlib>
......@@ -39,8 +38,8 @@ public:
*/
void connect(const std::string&,
const short&,
boost::function< void(void) > on_success = 0,
boost::function< void(void) > on_failure = 0);
std::function< void(void) > on_success = 0,
std::function< void(void) > on_failure = 0);
/**
* Install all the default callbacks.
*/
......@@ -56,8 +55,8 @@ public:
virtual boost::asio::io_service& get_io_service();
private:
void connect_handler(boost::function< void(void) >,
boost::function< void(void) >,
void connect_handler(std::function< void(void) >,
std::function< void(void) >,
const boost::system::error_code&);
/**
* Called when the server sends us a PING request. Sends a PONG back.
......
......@@ -26,7 +26,7 @@ void InterfaceRemoteClient::start()
{
log_debug("Starting InterfaceRemoteClient " << this->number);
this->install_callbacks();
this->install_timed_event(boost::bind(&InterfaceRemoteClient::send_ping, this), 2);
this->install_timed_event(std::bind(&InterfaceRemoteClient::send_ping, this), 2);
CommandHandler::install_read_handler();
}
......@@ -34,7 +34,7 @@ void InterfaceRemoteClient::send_ping()
{
Command* command = new Command;
command->set_name("PING");
this->request_answer(command, boost::bind(&InterfaceRemoteClient::on_pong, this, _1), "PONG");
this->request_answer(command, std::bind(&InterfaceRemoteClient::on_pong, this, std::placeholders::_1), "PONG");
this->ping_sent();
}
......@@ -42,5 +42,5 @@ void InterfaceRemoteClient::on_pong(Command*)
{
this->pong_received();
log_debug("Current ping: " << this->get_latency() << "micro seconds.");
this->install_timed_event(boost::bind(&InterfaceRemoteClient::send_ping, this), 2);
this->install_timed_event(std::bind(&InterfaceRemoteClient::send_ping, this), 2);
}
......@@ -13,7 +13,7 @@
*/
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <functional>
#ifndef __INTERFACE_REMOTE_CLIENT_HPP__
# define __INTERFACE_REMOTE_CLIENT_HPP__
......
......@@ -24,8 +24,8 @@ User* RemoteClient::get_user()
void RemoteClient::install_callbacks()
{
this->install_callback("AUTH", boost::bind(&RemoteClient::auth_callback, this, _1));
this->install_callback("TRANSFER", boost::bind(&RemoteClient::transfer_callback, this, _1));
this->install_callback("AUTH", std::bind(&RemoteClient::auth_callback, this, std::placeholders::_1));
this->install_callback("TRANSFER", std::bind(&RemoteClient::transfer_callback, this, std::placeholders::_1));
}
void RemoteClient::auth_callback(Command* received_command)
......
......@@ -8,12 +8,12 @@
* @class RemoteClient
*/
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#ifndef __REMOTE_CLIENT_HPP__
# define __REMOTE_CLIENT_HPP__
#include <boost/asio.hpp>
#include <functional>
#include <network/interface_remote_client.hpp>
#include <network/transfer_sender.hpp>
#include <network/server.hpp>
......
......@@ -25,11 +25,11 @@ void RemoteGameClient::install_callbacks()
assert(game_server);
ServerWorld* world = game_server->get_world();
this->install_callback("OK", boost::bind(&RemoteGameClient::ok_callback, this, _1));
this->install_callback("T", boost::bind(&RemoteGameClient::turn_callback, this, _1));
this->install_callback("MOVE", boost::bind(&ServerWorld::move_callback, world, _1));
this->install_callback("BUILD", boost::bind(&ServerWorld::build_callback, world, _1));
this->install_callback("SPAWN", boost::bind(&ServerWorld::spawn_callback, world, _1));
this->install_callback("OK", std::bind(&RemoteGameClient::ok_callback, this, std::placeholders::_1));
this->install_callback("T", std::bind(&RemoteGameClient::turn_callback, this, std::placeholders::_1));
this->install_callback("MOVE", std::bind(&ServerWorld::move_callback, world, std::placeholders::_1));
this->install_callback("BUILD", std::bind(&ServerWorld::build_callback, world, std::placeholders::_1));
this->install_callback("SPAWN", std::bind(&ServerWorld::spawn_callback, world, std::placeholders::_1));
}
boost::asio::io_service& RemoteGameClient::get_io_service()
......
......@@ -6,12 +6,14 @@
* @class RemoteGameClient
*/
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#ifndef __REMOTE_GAME_CLIENT_HPP__
# define __REMOTE_GAME_CLIENT_HPP__
#include <functional>
#include <boost/asio.hpp>
#include <network/interface_remote_client.hpp>
#include <network/server.hpp>
#include <database/user.hpp>
......
......@@ -13,13 +13,15 @@
* @class Server
*/
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#ifndef __SERVER_HPP__
# define __SERVER_HPP__
#include <istream>
#include <vector>
#include <functional>
#ifndef __SERVER_HPP__
# define __SERVER_HPP__
#include <boost/asio.hpp>
#include <logging/logging.hpp>
#include <network/command.hpp>
......@@ -193,9 +195,9 @@ private:
T* new_client = new T(this->io_service, this);
this->acceptor->async_accept(new_client->get_socket(),
boost::bind(&Server<T>::handle_accept,
this, new_client,
boost::asio::placeholders::error));
std::bind(&Server<T>::handle_accept,
this, new_client,
std::placeholders::_1));
}
void handle_accept(T* client, const boost::system::error_code& error)
......
......@@ -9,7 +9,7 @@ TimedEvent::TimedEvent(TimedEventHandler* handler,
timer(timer),
callback(callback)
{
this->timer->async_wait(boost::bind(&TimedEvent::on_expires, this, _1));
this->timer->async_wait(std::bind(&TimedEvent::on_expires, this, std::placeholders::_1));
}
void TimedEvent::on_expires(const boost::system::error_code& error)
......
......@@ -8,17 +8,17 @@
* @class TimedEvent
*/