From 5ad1cd32b2f630f413646131fbdfbae85b3c72f8 Mon Sep 17 00:00:00 2001 From: smatz Date: Tue, 3 Feb 2009 18:08:07 +0000 Subject: [PATCH] (svn r15324) -Codechange: unify the class used for comparing of strings for std::map --- projects/openttd_vs80.vcproj | 4 ++++ projects/openttd_vs90.vcproj | 4 ++++ source.list | 1 + src/ai/ai.hpp | 6 ++---- src/ai/ai_config.hpp | 7 ++----- src/ai/ai_scanner.hpp | 3 ++- src/ai/api/ai_controller.hpp | 6 ++---- src/blitter/factory.hpp | 8 +------- src/core/string_compare_type.hpp | 15 +++++++++++++++ src/driver.h | 8 +------- 10 files changed, 34 insertions(+), 28 deletions(-) create mode 100644 src/core/string_compare_type.hpp diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index 8306b3add5..b46f50ebc0 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -1699,6 +1699,10 @@ RelativePath=".\..\src\core\sort_func.hpp" > + + + + AIInfoList; +typedef std::map AIInfoList; void CcAI(bool success, TileIndex tile, uint32 p1, uint32 p2); diff --git a/src/ai/ai_config.hpp b/src/ai/ai_config.hpp index 39b680f1ce..ca8b05a39e 100644 --- a/src/ai/ai_config.hpp +++ b/src/ai/ai_config.hpp @@ -7,14 +7,11 @@ #include #include "ai_info.hpp" - -#ifndef AI_HPP -struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } }; -#endif /* AI_HPP */ +#include "../core/string_compare_type.hpp" class AIConfig { private: - typedef std::map SettingValueList; + typedef std::map SettingValueList; public: AIConfig() : diff --git a/src/ai/ai_scanner.hpp b/src/ai/ai_scanner.hpp index 3bfa27bfc6..9818288bbd 100644 --- a/src/ai/ai_scanner.hpp +++ b/src/ai/ai_scanner.hpp @@ -5,6 +5,7 @@ #ifndef AI_SCANNER_HPP #define AI_SCANNER_HPP +#include "../core/string_compare_type.hpp" #include class AIScanner { @@ -73,7 +74,7 @@ public: bool HasAI(const struct ContentInfo *ci, bool md5sum); #endif private: - typedef std::map AILibraryList; + typedef std::map AILibraryList; /** * Scan the AI dir for scripts. diff --git a/src/ai/api/ai_controller.hpp b/src/ai/api/ai_controller.hpp index 1f1df743ef..d4e2bd6dcb 100644 --- a/src/ai/api/ai_controller.hpp +++ b/src/ai/api/ai_controller.hpp @@ -5,10 +5,8 @@ #ifndef AI_CONTROLLER_HPP #define AI_CONTROLLER_HPP +#include "../../core/string_compare_type.hpp" #include -#ifndef AI_HPP -struct ltstr { bool operator()(const char *s1, const char *s2) const { return strcmp(s1, s2) < 0; } }; -#endif /* AI_HPP */ /** * The Controller, the class each AI should extend. It creates the AI, makes @@ -85,7 +83,7 @@ public: static void Print(bool error_msg, const char *message); private: - typedef std::map LoadedLibraryList; + typedef std::map LoadedLibraryList; uint ticks; LoadedLibraryList loaded_library; diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index 4f7a4b108e..a1ab6dc6e1 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -8,6 +8,7 @@ #include "base.hpp" #include "../debug.h" #include "../string_func.h" +#include "../core/string_compare_type.hpp" #include #if defined(WITH_COCOA) @@ -21,13 +22,6 @@ class BlitterFactoryBase { private: const char *name; - struct StringCompare { - bool operator () (const char *a, const char *b) const - { - return strcmp(a, b) < 0; - } - }; - typedef std::map Blitters; static Blitters &GetBlitters() diff --git a/src/core/string_compare_type.hpp b/src/core/string_compare_type.hpp new file mode 100644 index 0000000000..c4bb718197 --- /dev/null +++ b/src/core/string_compare_type.hpp @@ -0,0 +1,15 @@ +/* $Id$ */ + +/** @file string_compare_type.hpp Comparator class for "const char *" so it can be used as a key for std::map */ + +#ifndef STRING_COMPARE_TYPE_HPP +#define STRING_COMPARE_TYPE_HPP + +struct StringCompare { + bool operator () (const char *a, const char *b) const + { + return strcmp(a, b) < 0; + } +}; + +#endif /* STRING_COMPARE_TYPE_HPP */ diff --git a/src/driver.h b/src/driver.h index 61fede9c44..b2a359b973 100644 --- a/src/driver.h +++ b/src/driver.h @@ -6,6 +6,7 @@ #define DRIVER_H #include "core/enum_type.hpp" +#include "core/string_compare_type.hpp" #include "string_func.h" #include @@ -39,13 +40,6 @@ private: const char *name; int priority; - struct StringCompare { - bool operator () (const char *a, const char *b) const - { - return strcmp(a, b) < 0; - } - }; - typedef std::map Drivers; static Drivers &GetDrivers()