Skip to content

Commit

Permalink
C++11 patchset 2: remove util/cpp11.h and util/cpp11_container.h (#5821)
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzhul committed Jun 4, 2017
1 parent 2362d3f commit a98baef
Show file tree
Hide file tree
Showing 59 changed files with 223 additions and 298 deletions.
11 changes: 6 additions & 5 deletions src/client.cpp
Expand Up @@ -242,7 +242,7 @@ Client::~Client()
delete m_inventory_from_server;

// Delete detached inventories
for (UNORDERED_MAP<std::string, Inventory*>::iterator
for (std::unordered_map<std::string, Inventory*>::iterator
i = m_detached_inventories.begin();
i != m_detached_inventories.end(); ++i) {
delete i->second;
Expand Down Expand Up @@ -571,7 +571,7 @@ void Client::step(float dtime)
Update positions of sounds attached to objects
*/
{
for(UNORDERED_MAP<int, u16>::iterator i = m_sounds_to_objects.begin();
for(std::unordered_map<int, u16>::iterator i = m_sounds_to_objects.begin();
i != m_sounds_to_objects.end(); ++i) {
int client_id = i->first;
u16 object_id = i->second;
Expand All @@ -591,7 +591,7 @@ void Client::step(float dtime)
m_removed_sounds_check_timer = 0;
// Find removed sounds and clear references to them
std::vector<s32> removed_server_ids;
for(UNORDERED_MAP<s32, int>::iterator i = m_sounds_server_to_client.begin();
for (std::unordered_map<s32, int>::iterator i = m_sounds_server_to_client.begin();
i != m_sounds_server_to_client.end();) {
s32 server_id = i->first;
int client_id = i->second;
Expand All @@ -614,7 +614,7 @@ void Client::step(float dtime)
if (m_mod_storage_save_timer <= 0.0f) {
verbosestream << "Saving registered mod storages." << std::endl;
m_mod_storage_save_timer = g_settings->getFloat("server_map_save_interval");
for (UNORDERED_MAP<std::string, ModMetadata *>::const_iterator
for (std::unordered_map<std::string, ModMetadata *>::const_iterator
it = m_mod_storages.begin(); it != m_mod_storages.end(); ++it) {
if (it->second->isModified()) {
it->second->save(getModStoragePath());
Expand Down Expand Up @@ -1959,7 +1959,8 @@ bool Client::registerModStorage(ModMetadata *storage)

void Client::unregisterModStorage(const std::string &name)
{
UNORDERED_MAP<std::string, ModMetadata *>::const_iterator it = m_mod_storages.find(name);
std::unordered_map<std::string, ModMetadata *>::const_iterator it =
m_mod_storages.find(name);
if (it != m_mod_storages.end()) {
// Save unconditionaly on unregistration
it->second->save(getModStoragePath());
Expand Down
13 changes: 7 additions & 6 deletions src/client.h
Expand Up @@ -28,6 +28,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>
#include <set>
#include <vector>
#include <unordered_set>
#include "clientobject.h"
#include "gamedef.h"
#include "inventorymanager.h"
Expand Down Expand Up @@ -656,18 +657,18 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
// Sounds
float m_removed_sounds_check_timer;
// Mapping from server sound ids to our sound ids
UNORDERED_MAP<s32, int> m_sounds_server_to_client;
std::unordered_map<s32, int> m_sounds_server_to_client;
// And the other way!
UNORDERED_MAP<int, s32> m_sounds_client_to_server;
std::unordered_map<int, s32> m_sounds_client_to_server;
// And relations to objects
UNORDERED_MAP<int, u16> m_sounds_to_objects;
std::unordered_map<int, u16> m_sounds_to_objects;

// Privileges
UNORDERED_SET<std::string> m_privileges;
std::unordered_set<std::string> m_privileges;

// Detached inventories
// key = name
UNORDERED_MAP<std::string, Inventory*> m_detached_inventories;
std::unordered_map<std::string, Inventory*> m_detached_inventories;

// Storage for mesh data for creating multiple instances of the same mesh
StringMap m_mesh_data;
Expand All @@ -682,7 +683,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef

ClientScripting *m_script;
bool m_modding_enabled;
UNORDERED_MAP<std::string, ModMetadata *> m_mod_storages;
std::unordered_map<std::string, ModMetadata *> m_mod_storages;
float m_mod_storage_save_timer;
GameUIFlags *m_game_ui_flags;

Expand Down
4 changes: 2 additions & 2 deletions src/client/tile.cpp
Expand Up @@ -427,7 +427,7 @@ class TextureSource : public IWritableTextureSource
std::vector<video::ITexture*> m_texture_trash;

// Maps image file names to loaded palettes.
UNORDERED_MAP<std::string, Palette> m_palettes;
std::unordered_map<std::string, Palette> m_palettes;

// Cached settings needed for making textures from meshes
bool m_setting_trilinear_filter;
Expand Down Expand Up @@ -700,7 +700,7 @@ Palette* TextureSource::getPalette(const std::string &name)
if (name == "")
return NULL;

UNORDERED_MAP<std::string, Palette>::iterator it = m_palettes.find(name);
std::unordered_map<std::string, Palette>::iterator it = m_palettes.find(name);
if (it == m_palettes.end()) {
// Create palette
video::IImage *img = generateImage(name);
Expand Down
18 changes: 9 additions & 9 deletions src/clientenvironment.cpp
Expand Up @@ -55,8 +55,8 @@ ClientEnvironment::ClientEnvironment(ClientMap *map, scene::ISceneManager *smgr,
ClientEnvironment::~ClientEnvironment()
{
// delete active objects
for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
for (ClientActiveObjectMap::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
delete i->second;
}

Expand Down Expand Up @@ -346,8 +346,8 @@ void ClientEnvironment::step(float dtime)

g_profiler->avg("CEnv: num of objects", m_active_objects.size());
bool update_lighting = m_active_object_light_update_interval.step(dtime, 0.21);
for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
for (ClientActiveObjectMap::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
ClientActiveObject* obj = i->second;
// Step object
obj->step(dtime, this);
Expand Down Expand Up @@ -406,22 +406,22 @@ GenericCAO* ClientEnvironment::getGenericCAO(u16 id)

ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
{
UNORDERED_MAP<u16, ClientActiveObject*>::iterator n = m_active_objects.find(id);
ClientActiveObjectMap::iterator n = m_active_objects.find(id);
if (n == m_active_objects.end())
return NULL;
return n->second;
}

bool isFreeClientActiveObjectId(const u16 id,
UNORDERED_MAP<u16, ClientActiveObject*> &objects)
ClientActiveObjectMap &objects)
{
if(id == 0)
return false;

return objects.find(id) == objects.end();
}

u16 getFreeClientActiveObjectId(UNORDERED_MAP<u16, ClientActiveObject*> &objects)
u16 getFreeClientActiveObjectId(ClientActiveObjectMap &objects)
{
//try to reuse id's as late as possible
static u16 last_used_id = 0;
Expand Down Expand Up @@ -583,8 +583,8 @@ void ClientEnvironment::updateLocalPlayerBreath(u16 breath)
void ClientEnvironment::getActiveObjects(v3f origin, f32 max_d,
std::vector<DistanceSortedActiveObject> &dest)
{
for (UNORDERED_MAP<u16, ClientActiveObject*>::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
for (ClientActiveObjectMap::iterator i = m_active_objects.begin();
i != m_active_objects.end(); ++i) {
ClientActiveObject* obj = i->second;

f32 d = (obj->getPosition() - origin).getLength();
Expand Down
3 changes: 2 additions & 1 deletion src/clientenvironment.h
Expand Up @@ -64,6 +64,7 @@ struct ClientEnvEvent
};
};

typedef std::unordered_map<u16, ClientActiveObject*> ClientActiveObjectMap;
class ClientEnvironment : public Environment
{
public:
Expand Down Expand Up @@ -181,7 +182,7 @@ class ClientEnvironment : public Environment
Client *m_client;
ClientScripting *m_script;
IrrlichtDevice *m_irr;
UNORDERED_MAP<u16, ClientActiveObject*> m_active_objects;
ClientActiveObjectMap m_active_objects;
std::vector<ClientSimpleObject*> m_simple_objects;
std::queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;
Expand Down
30 changes: 14 additions & 16 deletions src/clientiface.cpp
Expand Up @@ -611,7 +611,7 @@ ClientInterface::~ClientInterface()
{
MutexAutoLock clientslock(m_clients_mutex);

for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
for (RemoteClientMap::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
// Delete client
delete i->second;
Expand All @@ -624,7 +624,7 @@ std::vector<u16> ClientInterface::getClientIDs(ClientState min_state)
std::vector<u16> reply;
MutexAutoLock clientslock(m_clients_mutex);

for(UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
for (RemoteClientMap::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
if (i->second->getState() >= min_state)
reply.push_back(i->second->peer_id);
Expand Down Expand Up @@ -682,7 +682,7 @@ void ClientInterface::send(u16 peer_id, u8 channelnum,
void ClientInterface::sendToAll(NetworkPacket *pkt)
{
MutexAutoLock clientslock(m_clients_mutex);
for (UNORDERED_MAP<u16, RemoteClient*>::iterator i = m_clients.begin();
for (RemoteClientMap::iterator i = m_clients.begin();
i != m_clients.end(); ++i) {
RemoteClient *client = i->second;

Expand All @@ -697,7 +697,7 @@ void ClientInterface::sendToAll(NetworkPacket *pkt)
RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)
{
MutexAutoLock clientslock(m_clients_mutex);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
Expand All @@ -711,7 +711,7 @@ RemoteClient* ClientInterface::getClientNoEx(u16 peer_id, ClientState state_min)

RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState state_min)
{
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
Expand All @@ -726,7 +726,7 @@ RemoteClient* ClientInterface::lockedGetClientNoEx(u16 peer_id, ClientState stat
ClientState ClientInterface::getClientState(u16 peer_id)
{
MutexAutoLock clientslock(m_clients_mutex);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::const_iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
Expand All @@ -738,7 +738,7 @@ ClientState ClientInterface::getClientState(u16 peer_id)
void ClientInterface::setPlayerName(u16 peer_id,std::string name)
{
MutexAutoLock clientslock(m_clients_mutex);
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n != m_clients.end())
Expand All @@ -750,7 +750,7 @@ void ClientInterface::DeleteClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);

// Error check
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);
// The client may not exist; clients are immediately removed if their
// access is denied, and this event occurs later then.
if (n == m_clients.end())
Expand All @@ -762,10 +762,8 @@ void ClientInterface::DeleteClient(u16 peer_id)
//TODO this should be done by client destructor!!!
RemoteClient *client = n->second;
// Handle objects
for(std::set<u16>::iterator
i = client->m_known_objects.begin();
i != client->m_known_objects.end(); ++i)
{
for (std::set<u16>::iterator i = client->m_known_objects.begin();
i != client->m_known_objects.end(); ++i) {
// Get object
u16 id = *i;
ServerActiveObject* obj = m_env->getActiveObject(id);
Expand All @@ -784,7 +782,7 @@ void ClientInterface::CreateClient(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);

// Error check
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);
// The client shouldn't already exist
if (n != m_clients.end()) return;

Expand All @@ -800,7 +798,7 @@ void ClientInterface::event(u16 peer_id, ClientStateEvent event)
MutexAutoLock clientlock(m_clients_mutex);

// Error check
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);

// No client to deliver event
if (n == m_clients.end())
Expand All @@ -821,7 +819,7 @@ u16 ClientInterface::getProtocolVersion(u16 peer_id)
MutexAutoLock conlock(m_clients_mutex);

// Error check
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);

// No client to get version
if (n == m_clients.end())
Expand All @@ -835,7 +833,7 @@ void ClientInterface::setClientVersion(u16 peer_id, u8 major, u8 minor, u8 patch
MutexAutoLock conlock(m_clients_mutex);

// Error check
UNORDERED_MAP<u16, RemoteClient*>::iterator n = m_clients.find(peer_id);
RemoteClientMap::iterator n = m_clients.find(peer_id);

// No client to set versions
if (n == m_clients.end())
Expand Down
7 changes: 4 additions & 3 deletions src/clientiface.h
Expand Up @@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" // for SER_FMT_VER_INVALID
#include "threading/mutex.h"
#include "network/networkpacket.h"
#include "util/cpp11_container.h"
#include "porting.h"

#include <list>
Expand Down Expand Up @@ -435,6 +434,8 @@ class RemoteClient
const u64 m_connection_time;
};

typedef std::unordered_map<u16, RemoteClient*> RemoteClientMap;

class ClientInterface {
public:

Expand Down Expand Up @@ -499,7 +500,7 @@ class ClientInterface {
void lock() { m_clients_mutex.lock(); }
void unlock() { m_clients_mutex.unlock(); }

UNORDERED_MAP<u16, RemoteClient*>& getClientList() { return m_clients; }
RemoteClientMap& getClientList() { return m_clients; }

private:
/* update internal player list */
Expand All @@ -509,7 +510,7 @@ class ClientInterface {
con::Connection* m_con;
Mutex m_clients_mutex;
// Connected clients (behind the con mutex)
UNORDERED_MAP<u16, RemoteClient*> m_clients;
RemoteClientMap m_clients;
std::vector<std::string> m_clients_names; //for announcing masterserver

// Environment
Expand Down
2 changes: 1 addition & 1 deletion src/clientmedia.cpp
Expand Up @@ -348,7 +348,7 @@ void ClientMediaDownloader::remoteMediaReceived(

std::string name;
{
UNORDERED_MAP<unsigned long, std::string>::iterator it =
std::unordered_map<unsigned long, std::string>::iterator it =
m_remote_file_transfers.find(fetch_result.request_id);
assert(it != m_remote_file_transfers.end());
name = it->second;
Expand Down
4 changes: 2 additions & 2 deletions src/clientmedia.h
Expand Up @@ -26,7 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <map>
#include <set>
#include <vector>
#include "util/cpp11_container.h"
#include <unordered_map>

class Client;
struct HTTPFetchResult;
Expand Down Expand Up @@ -138,7 +138,7 @@ class ClientMediaDownloader
s32 m_httpfetch_active;
s32 m_httpfetch_active_limit;
s32 m_outstanding_hash_sets;
UNORDERED_MAP<unsigned long, std::string> m_remote_file_transfers;
std::unordered_map<unsigned long, std::string> m_remote_file_transfers;

// All files up to this name have either been received from a
// remote server or failed on all remote servers, so those files
Expand Down
6 changes: 3 additions & 3 deletions src/clientobject.cpp
Expand Up @@ -42,8 +42,8 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,
Client *client, ClientEnvironment *env)
{
// Find factory function
UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
if(n == m_types.end()) {
std::unordered_map<u16, Factory>::iterator n = m_types.find(type);
if (n == m_types.end()) {
// If factory is not found, just return.
warningstream << "ClientActiveObject: No factory for type="
<< (int)type << std::endl;
Expand All @@ -57,7 +57,7 @@ ClientActiveObject* ClientActiveObject::create(ActiveObjectType type,

void ClientActiveObject::registerType(u16 type, Factory f)
{
UNORDERED_MAP<u16, Factory>::iterator n = m_types.find(type);
std::unordered_map<u16, Factory>::iterator n = m_types.find(type);
if(n != m_types.end())
return;
m_types[type] = f;
Expand Down

0 comments on commit a98baef

Please sign in to comment.