From b147c67934582295424e1b004dc7fc799efc3988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Mon, 1 Dec 2008 20:48:14 +0100 Subject: [PATCH] use the string_map typedef in config.cpp and gui/ files... ...instead of repeating the std::map<....> type name all the time --- src/config.cpp | 4 ++-- src/gui/dialogs/language_selection.cpp | 2 +- src/gui/dialogs/mp_connect.cpp | 4 ++-- src/gui/dialogs/mp_create_game.cpp | 4 ++-- src/gui/widgets/control.cpp | 5 ++--- src/gui/widgets/control.hpp | 3 +-- src/gui/widgets/listbox.cpp | 24 ++++++++-------------- src/gui/widgets/listbox.hpp | 15 +++++--------- src/gui/widgets/toggle_button.cpp | 4 ++-- src/gui/widgets/toggle_button.hpp | 2 +- src/gui/widgets/toggle_panel.cpp | 5 ++--- src/gui/widgets/toggle_panel.hpp | 3 +-- src/gui/widgets/window_builder_private.hpp | 2 +- 13 files changed, 30 insertions(+), 47 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index fb87dfcc8f2..83eb86c4e8f 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -357,7 +357,7 @@ const config* config::find_child(const std::string& key, void config::clear() { - for(std::map >::iterator i = children.begin(); i != children.end(); ++i) { + for(child_map::iterator i = children.begin(); i != children.end(); ++i) { std::vector& v = i->second; for(std::vector::iterator j = v.begin(); j != v.end(); ++j) delete *j; @@ -603,7 +603,7 @@ void config::apply_diff(const config& diff) void config::merge_with(const config& c) { - std::map visitations; + boost::unordered_map visitations; // Merge attributes first string_map::const_iterator attrib_it, attrib_end = c.values.end(); diff --git a/src/gui/dialogs/language_selection.cpp b/src/gui/dialogs/language_selection.cpp index 21e0a1d59a4..aaf34211d63 100644 --- a/src/gui/dialogs/language_selection.cpp +++ b/src/gui/dialogs/language_selection.cpp @@ -48,7 +48,7 @@ void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window) const std::vector& languages = get_languages(); const language_def& current_language = get_language(); foreach(const language_def& lang, languages) { - std::map item; + string_map item; item.insert(std::make_pair("label", lang.language)); item.insert(std::make_pair("tooltip", lang.language)); diff --git a/src/gui/dialogs/mp_connect.cpp b/src/gui/dialogs/mp_connect.cpp index 281124e7c96..63a39dafcda 100644 --- a/src/gui/dialogs/mp_connect.cpp +++ b/src/gui/dialogs/mp_connect.cpp @@ -74,8 +74,8 @@ void tmp_server_list::pre_show(CVideo& /*video*/, twindow& window) foreach(const game_config::server_info& server, pref_servers) { - std::map > data; - std::map item; + std::map data; + string_map item; item["label"] = server.name; data.insert(std::make_pair("name", item)); diff --git a/src/gui/dialogs/mp_create_game.cpp b/src/gui/dialogs/mp_create_game.cpp index 3a1afcf0488..82e2aa4c4c1 100644 --- a/src/gui/dialogs/mp_create_game.cpp +++ b/src/gui/dialogs/mp_create_game.cpp @@ -72,7 +72,7 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window) list->set_callback_value_change(dialog_callback); // Load option (might turn it into a button later). - std::map item; + string_map item; item.insert(std::make_pair("label", _("Load Game"))); item.insert(std::make_pair("tooltip", _("Load Game..."))); list->add_row(item); @@ -94,7 +94,7 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window) foreach(const config* map, cfg_.get_children("multiplayer")) { if(utils::string_bool((*map)["allow_new_game"], true)) { - std::map item; + string_map item; item.insert(std::make_pair("label", (*map)["name"])); item.insert(std::make_pair("tooltip", (*map)["name"])); list->add_row(item); diff --git a/src/gui/widgets/control.cpp b/src/gui/widgets/control.cpp index 401a707ed93..9eee3f0a9ff 100644 --- a/src/gui/widgets/control.cpp +++ b/src/gui/widgets/control.cpp @@ -34,10 +34,9 @@ tcontrol::tcontrol(const unsigned canvas_count) { } -void tcontrol::set_members(const std::map< - std::string /* member id */, t_string /* member value */>& data) +void tcontrol::set_members(const string_map& data) { - std::map::const_iterator itor = data.find("label"); + string_map::const_iterator itor = data.find("label"); if(itor != data.end()) { set_label(itor->second); } diff --git a/src/gui/widgets/control.hpp b/src/gui/widgets/control.hpp index 39263ef40e4..6ce3b822b20 100644 --- a/src/gui/widgets/control.hpp +++ b/src/gui/widgets/control.hpp @@ -48,8 +48,7 @@ public: * * @param data Map with the key value pairs to set the members. */ - virtual void set_members(const std::map< - std::string /* member id */, t_string /* member value */>& data); + virtual void set_members(const string_map& data); /***** ***** ***** ***** State handling ***** ***** ***** *****/ diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index 8e87459b871..6e70bcdd60a 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -69,18 +69,15 @@ void tlistbox::list_item_selected(twidget* caller) assert(false); } -void tlistbox::add_row(const std::map< - std::string /* member id */, t_string /* member value */>& item) +void tlistbox::add_row(const string_map& item) { - std::map > data; + std::map data; data.insert(std::make_pair("", item)); add_row(data); } -void tlistbox::add_row(const std::map >& data) +void tlistbox::add_row(const std::map& data) { assert(list_builder_); @@ -107,12 +104,11 @@ void tlistbox::add_row(const std::map >& data) +void tlistbox::add_rows(const std::vector& data) { // foreach(const std::map& cell, data) { // doesn't compile it sees 3 paramters instead of 2 so use a typedef. - typedef std::map hack ; - foreach(const hack& cell, data) { + foreach(const string_map& cell, data) { add_row(cell); } } @@ -322,8 +318,7 @@ bool tlistbox::get_item_active(const unsigned item) const } tlistbox::trow::trow(const tbuilder_grid& list_builder_, - const std::map >& data) : + const std::map& data): grid_(dynamic_cast(list_builder_.build())), height_(0), canvas_(), @@ -342,8 +337,7 @@ void tlistbox::trow::set_selected(const bool selected) } void tlistbox::trow::init_in_grid(tgrid* grid, - const std::map >& data) + const std::map& data) { for(unsigned row = 0; row < grid->get_rows(); ++row) { for(unsigned col = 0; col < grid->get_cols(); ++col) { @@ -357,9 +351,7 @@ void tlistbox::trow::init_in_grid(tgrid* grid, if(btn) { btn->set_callback_state_change(callback_select_list_item); - std::map > - ::const_iterator itor = data.find(btn->id()); + std::map::const_iterator itor = data.find(btn->id()); if(itor == data.end()) { itor = data.find(""); diff --git a/src/gui/widgets/listbox.hpp b/src/gui/widgets/listbox.hpp index 1bc11c33809..773457d3d68 100644 --- a/src/gui/widgets/listbox.hpp +++ b/src/gui/widgets/listbox.hpp @@ -59,8 +59,7 @@ public: * @param item The data to send to set_members of the * widget or to all the widgets. */ - void add_row(const std::map< - std::string /* member id */, t_string /* member value */>& item); + void add_row(const string_map& item); /** * Adds single row to the grid. @@ -77,8 +76,7 @@ public: * Having both empty and non-empty id's gives * undefined behaviour. */ - void add_row(const std::map >& data); + void add_row(const std::map& data); /** * Adds multiple rows to the grid. @@ -91,8 +89,7 @@ public: * it calls add_row(std::map&). */ - void add_rows(const std::vector >& data); + void add_rows(const std::vector& data); unsigned get_item_count() const { return rows_.size(); } @@ -282,8 +279,7 @@ private: public: trow(const tbuilder_grid& list_builder_, - const std::map >& data); + const std::map& data); /***** ***** ***** setters / getters for members ***** ****** *****/ @@ -326,8 +322,7 @@ private: /** Initializes all widgets in the grid. */ void init_in_grid(tgrid* grid, - const std::map >& data); + const std::map& data); /** * Selects all widgets in the grid. diff --git a/src/gui/widgets/toggle_button.cpp b/src/gui/widgets/toggle_button.cpp index 5011b7a9ff4..84aeeec8e3e 100644 --- a/src/gui/widgets/toggle_button.cpp +++ b/src/gui/widgets/toggle_button.cpp @@ -21,12 +21,12 @@ namespace gui2 { -void ttoggle_button::set_members(const std::map& data) +void ttoggle_button::set_members(const string_map& data) { // Inherit tcontrol::set_members(data); - std::map::const_iterator itor = data.find("icon"); + string_map::const_iterator itor = data.find("icon"); if(itor != data.end()) { set_icon_name(itor->second); } diff --git a/src/gui/widgets/toggle_button.hpp b/src/gui/widgets/toggle_button.hpp index 8a1e3ac70f4..addec5a8ee4 100644 --- a/src/gui/widgets/toggle_button.hpp +++ b/src/gui/widgets/toggle_button.hpp @@ -58,7 +58,7 @@ public: * Sets the additional member * * icon_name_ icon */ - void set_members(const std::map& data); + void set_members(const string_map& data); /** Inherited from tcontrol. */ void set_active(const bool active); diff --git a/src/gui/widgets/toggle_panel.cpp b/src/gui/widgets/toggle_panel.cpp index c6f6688712b..a6c8253af97 100644 --- a/src/gui/widgets/toggle_panel.cpp +++ b/src/gui/widgets/toggle_panel.cpp @@ -19,11 +19,10 @@ namespace gui2 { -void ttoggle_panel::set_child_members(const std::map >& data) +void ttoggle_panel::set_child_members(const std::map& data) { // typedef boost problem work around. - typedef std::pair > hack ; + typedef std::pair hack ; foreach(const hack& item, data) { tcontrol* control = dynamic_cast(find_widget(item.first, false)); if(control) { diff --git a/src/gui/widgets/toggle_panel.hpp b/src/gui/widgets/toggle_panel.hpp index 281202c411c..321f718854d 100644 --- a/src/gui/widgets/toggle_panel.hpp +++ b/src/gui/widgets/toggle_panel.hpp @@ -46,8 +46,7 @@ public: * * @param data Map with the key value pairs to set the members. */ - void set_child_members(const std::map >& data); + void set_child_members(const std::map& data); /***** ***** ***** ***** Inherited ***** ***** ***** *****/ diff --git a/src/gui/widgets/window_builder_private.hpp b/src/gui/widgets/window_builder_private.hpp index 20aad3ba653..e29c0832e3b 100644 --- a/src/gui/widgets/window_builder_private.hpp +++ b/src/gui/widgets/window_builder_private.hpp @@ -149,7 +149,7 @@ public: * Contains a vector with the data to set in every cell, it's used to * serialize the data in the config, so the config is no longer required. */ - std::vector >list_data; + std::vectorlist_data; const bool assume_fixed_row_size; };