Skip to content

Commit

Permalink
FIXED deprecation warnings by replacing __gnu_cxx::hash_map/set with …
Browse files Browse the repository at this point in the history
…tr1::unordered_map/set when compiling with gcc 4.4 and newer.
  • Loading branch information
Kai Sterker committed Oct 2, 2010
1 parent 3ebec1d commit 2bcdae9
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 41 deletions.
15 changes: 14 additions & 1 deletion src/base/hash_map.h
Expand Up @@ -26,7 +26,19 @@

#ifndef BASE_HASHMAP_H
#define BASE_HASHMAP_H


// gcc >= 4.4
#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 4
#include <tr1/unordered_map>
#include <tr1/unordered_set>

#define hash_map unordered_map
#define hash_set unordered_set

namespace std { using namespace tr1; }

#else
// gcc < 4.4
#if __GNUG__ > 2
#include <ext/hash_map>
#include <ext/hash_set>
Expand Down Expand Up @@ -57,5 +69,6 @@ namespace std
#if __GNUG__ > 2
namespace std { using namespace __gnu_cxx; }
#endif
#endif

#endif // BASE_HASHMAP_H
2 changes: 2 additions & 0 deletions src/event/types.h
Expand Up @@ -30,6 +30,8 @@
#ifndef EVENT_TYPES_H
#define EVENT_TYPES_H

#include <vector>

#include "event/event.h"
#include <base/hash_map.h>

Expand Down
4 changes: 3 additions & 1 deletion src/rpg/character.cc
Expand Up @@ -25,6 +25,8 @@
* @brief Base class for creatures, NPCs and Player characters.
*/

#include <algorithm>

#include "base/base.h"
#include "rpg/character.h"

Expand Down Expand Up @@ -129,7 +131,7 @@ bool character::remove_faction(const std::string & name)
{
faction * tmp = get_faction(name);

std::vector<faction *>::iterator i = find(Factions.begin(), Factions.end(), tmp);
std::vector<faction *>::iterator i = std::find(Factions.begin(), Factions.end(), tmp);

if (*i != NULL)
{
Expand Down
8 changes: 5 additions & 3 deletions src/rpg/dialog.cc
Expand Up @@ -26,6 +26,8 @@
* @brief Core of the dialogue system.
*/

#include <algorithm>

#include "rpg/dialog.h"
#include "base/nls.h"

Expand Down Expand Up @@ -190,7 +192,7 @@ const rpg::dialog_line *dialog::run (const s_int32 & answer)
}

// mark player text as used unless loops allowed
if (find (Loop.begin (), Loop.end (), successor) == Loop.end ())
if (std::find (Loop.begin (), Loop.end (), successor) == Loop.end ())
Used.push_back (successor);

do
Expand All @@ -210,7 +212,7 @@ const rpg::dialog_line *dialog::run (const s_int32 & answer)
s_int32 s = PyInt_AsLong (PyList_GetItem (speech, i));

// remove text that was already used and isn't allowed to loop
if (find (Used.begin (), Used.end (), s) != Used.end ())
if (std::find (Used.begin (), Used.end (), s) != Used.end ())
{
PySequence_DelItem (speakers, i);
PySequence_DelItem (speech, i--);
Expand Down Expand Up @@ -243,7 +245,7 @@ const rpg::dialog_line *dialog::run (const s_int32 & answer)
Py_XDECREF (arg);

// mark the NPC text as used unless loops allowed
if (find (Loop.begin (), Loop.end (), successor) == Loop.end ())
if (std::find (Loop.begin (), Loop.end (), successor) == Loop.end ())
Used.push_back (successor);

// remember successor to this line of text
Expand Down
7 changes: 7 additions & 0 deletions src/rpg/log_index.h
Expand Up @@ -93,6 +93,12 @@ namespace rpg
};
}

#if __GNUC_PREREQ(4,4)
namespace tr1
{

}
#else
#if __GNUG__ > 2
namespace __gnu_cxx
#else
Expand All @@ -110,6 +116,7 @@ namespace std
}
};
}
#endif

namespace rpg
{
Expand Down
18 changes: 1 addition & 17 deletions src/rpg/pathfinding_costs.h
Expand Up @@ -27,28 +27,12 @@
#ifndef PATHFINDING_COSTS_H
#define PATHFINDING_COSTS_H

#if __GNUG__ > 2
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
using namespace std;
#endif
#include "base/hash_map.h"
#include "rpg/specie.h"
#include "rpg/faction.h"

namespace rpg
{
/// Compares two string for equality
struct eqstr
{
bool operator()(std::string s1, std::string s2) const
{
return (s1 == s2);
}
};

/**
* The class with the terrain/cost hash_map.
*/
Expand Down Expand Up @@ -82,7 +66,7 @@ namespace rpg
}
}
private:
typedef hash_map<std::string, s_int16, hash<std::string>, eqstr> Terrain_Cost_Hash;
typedef std::hash_map<std::string, s_int16> Terrain_Cost_Hash;
/// The hash_map
Terrain_Cost_Hash Terrain_Cost;
};
Expand Down
4 changes: 3 additions & 1 deletion src/rpg/quest_event_manager.cc
Expand Up @@ -26,6 +26,8 @@
* @brief Handle execution of quest events class.
*/

#include <algorithm>

#include "rpg/quest_event_manager.h"
#include "rpg/quest_event.h"

Expand Down Expand Up @@ -107,7 +109,7 @@ void quest_event_manager::remove (listener *li)
std::vector<listener*>::iterator i;

// Search for the listener we want to remove
i = find ((*e).second.begin (), (*e).second.end (), li);
i = std::find ((*e).second.begin (), (*e).second.end (), li);

// found? -> get rid of it :)
if (i != (*e).second.end ())
Expand Down
18 changes: 1 addition & 17 deletions src/world/node_cache.h
Expand Up @@ -29,14 +29,6 @@

#ifndef WORLD_NODE_CACHE_H
#define WORLD_NODE_CACHE_H

#if __GNUG__ > 2
#include <ext/hash_map>
using namespace __gnu_cxx;
#else
#include <hash_map>
using namespace std;
#endif

#include "world/node.h"
#include "world/chunk_info.h"
Expand All @@ -45,14 +37,6 @@ using namespace std;

namespace world
{
struct eqstr
{
bool operator()(std::string s1, std::string s2) const
{
return (s1 == s2);
}
};

/**
* Keeps a hash map of every used node.
*/
Expand Down Expand Up @@ -107,7 +91,7 @@ namespace world
private:

/// The hash map
typedef hash_map<std::string, node *, hash<std::string>, eqstr> nodeHash;
typedef std::hash_map<std::string, node *> nodeHash;
nodeHash m_usedNodes;

};
Expand Down
2 changes: 1 addition & 1 deletion test/Makefile.am
Expand Up @@ -9,7 +9,7 @@ EXTRA_DIST = README audiotest.py dialogtest.py gfxsave.py itemtest.py \
convert_graphics.py CMakeLists.txt README.worldtest smallworld.cc

noinst_PROGRAMS = audiotest callbacktest diskiotest guitest inputtest gfxtest worldtest \
imagetest dialogtest path_test
imagetest path_test

audiotest_SOURCES = audiotest.cc
audiotest_LDADD = \
Expand Down

0 comments on commit 2bcdae9

Please sign in to comment.