mail[Wesnoth-commits] r33872 - in /trunk/src: gamestatus.cpp gamestatus.hpp multiplayer_ui.cpp playcampaign.cpp replay.cpp replay.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by guillaume . melquiond on March 20, 2009 - 08:06:
Author: silene
Date: Fri Mar 20 08:06:40 2009
New Revision: 33872

URL: http://svn.gna.org/viewcvs/wesnoth?rev=33872&view=rev
Log:
Removed config::child_list from gamestatus.cpp.

Modified:
    trunk/src/gamestatus.cpp
    trunk/src/gamestatus.hpp
    trunk/src/multiplayer_ui.cpp
    trunk/src/playcampaign.cpp
    trunk/src/replay.cpp
    trunk/src/replay.hpp

Modified: trunk/src/gamestatus.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.cpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/gamestatus.cpp (original)
+++ trunk/src/gamestatus.cpp Fri Mar 20 08:06:40 2009
@@ -19,6 +19,7 @@
 
 #include "global.hpp"
 
+#include "foreach.hpp"
 #include "gettext.hpp"
 #include "log.hpp"
 #include "game_preferences.hpp"
@@ -203,9 +204,9 @@
 
        set_start_ToD(const_cast<config&>(time_cfg),s_o_g);
 
-       const config::child_list& times_range = 
time_cfg.get_children("time_area");
-       for(config::child_list::const_iterator t = times_range.begin(); t != 
times_range.end(); ++t)
-               this->add_time_area(**t);
+       foreach (const config &t, time_cfg.child_range("time_area")) {
+               this->add_time_area(t);
+       }
 }
 
 void gamestatus::write(config& cfg) const
@@ -401,24 +402,23 @@
        return numTurns_ == -1 || turn_ <= size_t(numTurns_);
 }
 
-static player_info read_player(const config* cfg)
+static player_info read_player(const config &cfg)
 {
        player_info res;
 
-       res.name = (*cfg)["name"];
-
-       res.gold = atoi((*cfg)["gold"].c_str());
-       res.gold_add = utils::string_bool((*cfg)["gold_add"]);
-
-       const config::child_list& units = cfg->get_children("unit");
-       for(config::child_list::const_iterator i = units.begin(); i != 
units.end(); ++i) {
-               res.available_units.push_back(unit(**i,false));
+       res.name = cfg["name"];
+
+       res.gold = atoi(cfg["gold"].c_str());
+       res.gold_add = utils::string_bool(cfg["gold_add"]);
+
+       foreach (const config &u, cfg.child_range("unit")) {
+               res.available_units.push_back(unit(u, false));
        }
 
        res.can_recruit.clear();
 
-       const std::string& can_recruit_str = (*cfg)["can_recruit"];
-       if(can_recruit_str != "") {
+       const std::string &can_recruit_str = cfg["can_recruit"];
+       if (!can_recruit_str.empty()) {
                const std::vector<std::string> can_recruit = 
utils::split(can_recruit_str);
                
std::copy(can_recruit.begin(),can_recruit.end(),std::inserter(res.can_recruit,res.can_recruit.end()));
        }
@@ -498,7 +498,7 @@
                
rng_.seed_random(lexical_cast_default<unsigned>((*snapshot)["random_calls"]));
 
                // Midgame saves have the recall list stored in the snapshot.
-               load_recall_list(snapshot->get_children("player"));
+               load_recall_list(snapshot->child_range("player"));
 
        } else {
                // Start of scenario save, replays and MP campaign network 
next scenario
@@ -510,14 +510,14 @@
                // it will be preferred.
                if (replay_start != NULL){
                        // Check if we find some player information in the 
starting position
-                       const config::child_list& cfg_players = 
(*replay_start).get_children("player");
-                       if (!cfg_players.empty())
+                       config::const_child_itors cfg_players = 
replay_start->child_range("player");
+                       if (cfg_players.first != cfg_players.second)
                                load_recall_list(cfg_players);
                        else
-                               load_recall_list(cfg.get_children("player"));
+                               load_recall_list(cfg.child_range("player"));
                }
                else{
-                       load_recall_list(cfg.get_children("player"));
+                       load_recall_list(cfg.child_range("player"));
                }
        }
 
@@ -536,7 +536,7 @@
        if(vars != NULL) {
                set_variables(*vars);
        }
-       set_menu_items(cfg.get_children("menu_item"));
+       set_menu_items(cfg.child_range("menu_item"));
 
        const config* const replay = cfg.child("replay");
        if(replay != NULL) {
@@ -552,10 +552,9 @@
                //See also playcampaign::play_game, where after finishing the 
scenario the replay
                //will be saved.
                if(!starting_pos.empty()) {
-                       config::child_list player_list = 
cfg.get_children("player");
-                       for (config::child_list::const_iterator p = 
player_list.begin(); p != player_list.end(); p++){
+                       foreach (const config &p, cfg.child_range("player")) {
                                config& cfg_player = 
starting_pos.add_child("player");
-                               cfg_player.merge_with(**p);
+                               cfg_player.merge_with(p);
                        }
                }
        }
@@ -1051,21 +1050,20 @@
 
        if(leader == "") {
                const config& snapshot = has_snapshot ? gamestate.snapshot : 
gamestate.starting_pos;
-               const config::child_list& sides = 
snapshot.get_children("side");
-               for(config::child_list::const_iterator s = sides.begin(); s 
!= sides.end() && leader.empty(); ++s) {
-
-                       if((**s)["controller"] != "human") {
+               foreach (const config &side, snapshot.child_range("side"))
+               {
+                       if (side["controller"] != "human") {
                                continue;
                        }
 
-                       if(utils::string_bool((**s)["shroud"])) {
+                       if (utils::string_bool(side["shroud"])) {
                                shrouded = true;
                        }
 
-                       const config::child_list& units = 
(**s).get_children("unit");
-                       for(config::child_list::const_iterator u = 
units.begin(); u != units.end(); ++u) {
-                               if(utils::string_bool( (**u)["canrecruit"], 
false) == true) {
-                                       leader = (**u)["id"];
+                       foreach (const config &u, side.child_range("unit"))
+                       {
+                               if (utils::string_bool(u["canrecruit"], 
false)) {
+                                       leader = u["id"];
                                        break;
                                }
                        }
@@ -1119,11 +1117,10 @@
        /** @todo Ideally we should grab all leaders if there's more than 1 
human player? */
        std::string leader;
 
-       const config::child_list& players = cfg_save.get_children("player");
-
-       for(config::child_list::const_iterator i = players.begin(); i != 
players.end(); ++i) {
-               if (utils::string_bool( (**i)["canrecruit"], false) == true){
-                       leader = (**i)["save_id"];
+       foreach (const config &p, cfg_save.child_range("player"))
+       {
+               if (utils::string_bool(p["canrecruit"], false)) {
+                       leader = p["save_id"];
                }
        }
 
@@ -1132,21 +1129,20 @@
        if(leader == "") {
                const config* snapshot = has_snapshot ? cfg_snapshot : 
cfg_replay_start;
                if (snapshot != NULL){
-                       const config::child_list& sides = 
snapshot->get_children("side");
-                       for(config::child_list::const_iterator s = 
sides.begin(); s != sides.end() && leader.empty(); ++s) {
-
-                               if((**s)["controller"] != "human") {
+                       foreach (const config &side, 
snapshot->child_range("side"))
+                       {
+                               if (side["controller"] != "human") {
                                        continue;
                                }
 
-                               if(utils::string_bool((**s)["shroud"])) {
+                               if (utils::string_bool(side["shroud"])) {
                                        shrouded = true;
                                }
 
-                               const config::child_list& units = 
(**s).get_children("unit");
-                               for(config::child_list::const_iterator u = 
units.begin(); u != units.end(); ++u) {
-                                       if(utils::string_bool( 
(**u)["canrecruit"], false) == true) {
-                                               leader = (**u)["id"];
+                               foreach (const config &u, 
side.child_range("unit"))
+                               {
+                                       if 
(utils::string_bool(u["canrecruit"], false)) {
+                                               leader = u["id"];
                                                break;
                                        }
                                }
@@ -1226,18 +1222,19 @@
        }
 }
 
-void game_state::load_recall_list(const config::child_list& players)
-{
-       if(!players.empty()) {
-               for(config::child_list::const_iterator i = players.begin(); i 
!= players.end(); ++i) {
-                       std::string save_id = (**i)["save_id"];
-
-                       if(save_id.empty()) {
-                               ERR_NG << "Corrupted player entry: NULL 
save_id" << std::endl;
-                       } else {
-                               player_info player = read_player(*i);
-                               this->players.insert(std::pair<std::string, 
player_info>(save_id,player));
-                       }
+void game_state::load_recall_list(const config::const_child_itors &players)
+{
+       if (players.first == players.second) return;
+
+       foreach (const config &p, players)
+       {
+               const std::string &save_id = p["save_id"];
+
+               if (save_id.empty()) {
+                       ERR_NG << "Corrupted player entry: NULL save_id" << 
std::endl;
+               } else {
+                       player_info player = read_player(p);
+                       this->players.insert(std::make_pair(save_id, player));
                }
        }
 }
@@ -1333,15 +1330,15 @@
        variables = vars;
 }
 
-void game_state::set_menu_items(const config::child_list& menu_items) {
+void game_state::set_menu_items(const config::const_child_itors &menu_items)
+{
        clear_wmi(wml_menu_items);
-       for (config::child_list::const_iterator i = menu_items.begin(),
-            i_end = menu_items.end(); i != i_end; ++i)
+       foreach (const config &item, menu_items)
        {
-               const std::string& id = (**i)["id"].base_str();
+               const std::string &id = item["id"].base_str();
                wml_menu_item*& mref = wml_menu_items[id];
                if(mref == NULL) {
-                       mref = new wml_menu_item(id, *i);
+                       mref = new wml_menu_item(id, &item);
                } else {
                        WRN_NG << "duplicate menu item (" << id << ") while 
loading gamestate\n";
                }

Modified: trunk/src/gamestatus.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/gamestatus.hpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/gamestatus.hpp (original)
+++ trunk/src/gamestatus.hpp Fri Mar 20 08:06:40 2009
@@ -108,7 +108,7 @@
         *
         * @param players      Reference to the players section to load.
         */
-       void load_recall_list(const config::child_list& players);
+       void load_recall_list(const config::const_child_itors &players);
 
        std::vector<scoped_wml_variable*> scoped_variables;
        std::map<std::string, wml_menu_item*> wml_menu_items;
@@ -116,7 +116,7 @@
        const config& get_variables() const { return variables; }
        void set_variables(const config& vars);
 
-       void set_menu_items(const config::child_list& menu_items);
+       void set_menu_items(const config::const_child_itors &menu_items);
 
        // Variable access
 

Modified: trunk/src/multiplayer_ui.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/multiplayer_ui.cpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/multiplayer_ui.cpp (original)
+++ trunk/src/multiplayer_ui.cpp Fri Mar 20 08:06:40 2009
@@ -119,7 +119,7 @@
        if(vars != NULL) {
                state.set_variables(*vars);
        }
-       state.set_menu_items(level.get_children("menu_item"));
+       state.set_menu_items(level.child_range("menu_item"));
 
        //Check whether it is a save-game by looking for snapshot data
        const bool saved_game = (level.child("snapshot") && 
level.child("snapshot")->child("side"));
@@ -136,13 +136,13 @@
                if (state.snapshot.child("variables") != NULL){
                        
state.set_variables(*state.snapshot.child("variables"));
                }
-               
state.set_menu_items(state.snapshot.get_children("menu_item"));
+               state.set_menu_items(state.snapshot.child_range("menu_item"));
        }
 
        //If it is a start-of-scenario save, we need to load the player 
information from
        //the [player] tags
        if(start_of_scenario){
-               
state.load_recall_list(state.starting_pos.get_children("player"));
+               
state.load_recall_list(state.starting_pos.child_range("player"));
        }
 
        //In any type of reload(normal save or start-of-scenario) the players 
could have

Modified: trunk/src/playcampaign.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/playcampaign.cpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/playcampaign.cpp (original)
+++ trunk/src/playcampaign.cpp Fri Mar 20 08:06:40 2009
@@ -240,7 +240,7 @@
                if(gamestate.snapshot.child("variables") != NULL) {
                        
gamestate.set_variables(*gamestate.snapshot.child("variables"));
                }
-               
gamestate.set_menu_items(gamestate.snapshot.get_children("menu_item"));
+               
gamestate.set_menu_items(gamestate.snapshot.child_range("menu_item"));
                // Replace game label with that from snapshot
                if (!gamestate.snapshot["label"].empty()){
                        gamestate.label = gamestate.snapshot["label"];
@@ -417,13 +417,14 @@
                                std::string label = gamestate.label + _(" 
replay");
                                if (dialogs::get_save_name(disp, "", _("Name: 
"), &label,
                                        gui::OK_CANCEL, _("Save Replay"), 
false, false) == 0) {
-                               try {
+                                       try {
                                                config snapshot;
                                                //If the starting position 
contains player information, use this for
                                                //the replay savegame (this 
originally comes from the gamestate constructor,
                                                //where the player stuff is 
added to the starting position to be used here.
-                                               config::child_list 
player_list = gamestate.starting_pos.get_children("player");
-                                               if (player_list.size() > 0) {
+                                               config::child_itors 
player_list =
+                                                       
gamestate.starting_pos.child_range("player");
+                                               if (player_list.first != 
player_list.second) {
                                                        
recorder.set_save_info(gamestate, player_list);
                                                }
                                                recorder.save_game(label, 
snapshot, gamestate.starting_pos);

Modified: trunk/src/replay.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.cpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/replay.cpp (original)
+++ trunk/src/replay.cpp Fri Mar 20 08:06:40 2009
@@ -169,7 +169,7 @@
        saveInfo_ = save;
 }
 
-void replay::set_save_info(const game_state& save, const config::child_list& 
players)
+void replay::set_save_info(const game_state &save, const 
config::const_child_itors &players)
 {
        saveInfo_ = save;
        saveInfo_.players.clear();

Modified: trunk/src/replay.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/replay.hpp?rev=33872&r1=33871&r2=33872&view=diff
==============================================================================
--- trunk/src/replay.hpp (original)
+++ trunk/src/replay.hpp Fri Mar 20 08:06:40 2009
@@ -43,7 +43,7 @@
        explicit replay(const config& cfg);
 
        void set_save_info(const game_state& save);
-       void set_save_info(const game_state& save, const config::child_list& 
players);
+       void set_save_info(const game_state &save, const 
config::const_child_itors &players);
        void set_save_info_completion(const std::string &st);
 
        void set_skip(bool skip);




Related Messages


Powered by MHonArc, Updated Fri Mar 20 08:20:31 2009