use the string_map typedef in config.cpp and gui/ files...

...instead of repeating the std::map<....> type name all the time
This commit is contained in:
Tomasz Śniatowski 2008-12-01 20:48:14 +01:00
parent d1236cc6c6
commit b147c67934
13 changed files with 30 additions and 47 deletions

View File

@ -357,7 +357,7 @@ const config* config::find_child(const std::string& key,
void config::clear()
{
for(std::map<std::string,std::vector<config*> >::iterator i = children.begin(); i != children.end(); ++i) {
for(child_map::iterator i = children.begin(); i != children.end(); ++i) {
std::vector<config*>& v = i->second;
for(std::vector<config*>::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<std::string, unsigned> visitations;
boost::unordered_map<std::string, unsigned> visitations;
// Merge attributes first
string_map::const_iterator attrib_it, attrib_end = c.values.end();

View File

@ -48,7 +48,7 @@ void tlanguage_selection::pre_show(CVideo& /*video*/, twindow& window)
const std::vector<language_def>& languages = get_languages();
const language_def& current_language = get_language();
foreach(const language_def& lang, languages) {
std::map<std::string, t_string> item;
string_map item;
item.insert(std::make_pair("label", lang.language));
item.insert(std::make_pair("tooltip", lang.language));

View File

@ -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<std::string, std::map<std::string, t_string> > data;
std::map<std::string, t_string> item;
std::map<std::string, string_map> data;
string_map item;
item["label"] = server.name;
data.insert(std::make_pair("name", item));

View File

@ -72,7 +72,7 @@ void tmp_create_game::pre_show(CVideo& /*video*/, twindow& window)
list->set_callback_value_change(dialog_callback<tmp_create_game, &tmp_create_game::update_map>);
// Load option (might turn it into a button later).
std::map<std::string, t_string> 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<std::string, t_string> item;
string_map item;
item.insert(std::make_pair("label", (*map)["name"]));
item.insert(std::make_pair("tooltip", (*map)["name"]));
list->add_row(item);

View File

@ -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<std::string, t_string>::const_iterator itor = data.find("label");
string_map::const_iterator itor = data.find("label");
if(itor != data.end()) {
set_label(itor->second);
}

View File

@ -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 ***** ***** ***** *****/

View File

@ -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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> > data;
std::map<std::string, string_map> data;
data.insert(std::make_pair("", item));
add_row(data);
}
void tlistbox::add_row(const std::map<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data)
void tlistbox::add_row(const std::map<std::string /* widget id */, string_map>& data)
{
assert(list_builder_);
@ -107,12 +104,11 @@ void tlistbox::add_row(const std::map<std::string /* widget id */, std::map<
set_scrollbar_button_status();
}
void tlistbox::add_rows(const std::vector< std::map<std::string, t_string> >& data)
void tlistbox::add_rows(const std::vector<string_map>& data)
{
// foreach(const std::map<std::string, t_string>& cell, data) {
// doesn't compile it sees 3 paramters instead of 2 so use a typedef.
typedef std::map<std::string, t_string> 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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data) :
const std::map<std::string /* widget id */, string_map>& data):
grid_(dynamic_cast<tgrid*>(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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data)
const std::map<std::string /* widget id */, string_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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >
::const_iterator itor = data.find(btn->id());
std::map<std::string, string_map>::const_iterator itor = data.find(btn->id());
if(itor == data.end()) {
itor = data.find("");

View File

@ -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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data);
void add_row(const std::map<std::string /* widget id */, string_map>& data);
/**
* Adds multiple rows to the grid.
@ -91,8 +89,7 @@ public:
* it calls add_row(std::map<std::string,
* t_string>&).
*/
void add_rows(const std::vector<std::map<
std::string /* member id */, t_string /* member value */> >& data);
void add_rows(const std::vector<string_map>& data);
unsigned get_item_count() const { return rows_.size(); }
@ -282,8 +279,7 @@ private:
public:
trow(const tbuilder_grid& list_builder_,
const std::map<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data);
const std::map<std::string /* widget id */, string_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<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data);
const std::map<std::string /* widget id */, string_map>& data);
/**
* Selects all widgets in the grid.

View File

@ -21,12 +21,12 @@
namespace gui2 {
void ttoggle_button::set_members(const std::map<std::string, t_string>& data)
void ttoggle_button::set_members(const string_map& data)
{
// Inherit
tcontrol::set_members(data);
std::map<std::string, t_string>::const_iterator itor = data.find("icon");
string_map::const_iterator itor = data.find("icon");
if(itor != data.end()) {
set_icon_name(itor->second);
}

View File

@ -58,7 +58,7 @@ public:
* Sets the additional member
* * icon_name_ icon
*/
void set_members(const std::map<std::string, t_string>& data);
void set_members(const string_map& data);
/** Inherited from tcontrol. */
void set_active(const bool active);

View File

@ -19,11 +19,10 @@
namespace gui2 {
void ttoggle_panel::set_child_members(const std::map<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data)
void ttoggle_panel::set_child_members(const std::map<std::string /* widget id */, string_map>& data)
{
// typedef boost problem work around.
typedef std::pair<std::string, std::map<std::string, t_string> > hack ;
typedef std::pair<std::string, string_map> hack ;
foreach(const hack& item, data) {
tcontrol* control = dynamic_cast<tcontrol*>(find_widget(item.first, false));
if(control) {

View File

@ -46,8 +46,7 @@ public:
*
* @param data Map with the key value pairs to set the members.
*/
void set_child_members(const std::map<std::string /* widget id */, std::map<
std::string /* member id */, t_string /* member value */> >& data);
void set_child_members(const std::map<std::string /* widget id */, string_map>& data);
/***** ***** ***** ***** Inherited ***** ***** ***** *****/

View File

@ -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<std::map<std::string /*key*/, t_string/*value*/> >list_data;
std::vector<string_map>list_data;
const bool assume_fixed_row_size;
};