From 9f72c5331a9cf477edeb8cc0e05103ace007dbc8 Mon Sep 17 00:00:00 2001 From: Patrick Parker Date: Sun, 3 Feb 2008 21:36:06 +0000 Subject: [PATCH] now allow configs to be streamed directly to an ostream remove an iterator redefinition remove a pointless debug calculation that was not being output anywhere --- src/actions.cpp | 2 +- src/config.cpp | 14 +++++++++----- src/config.hpp | 3 ++- src/game_events.cpp | 2 +- src/gamestatus.cpp | 2 +- src/multiplayer_ui.cpp | 2 +- src/network.cpp | 4 ++-- src/playcampaign.cpp | 1 - src/replay.cpp | 2 +- src/server/game.cpp | 6 +++--- src/server/server.cpp | 2 +- src/tests/test_network_worker.cpp | 2 +- src/unit_display.cpp | 5 +++-- 13 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 3c045b51e05..41fda12b0fa 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -202,7 +202,7 @@ std::string recruit_unit(const gamemap& map, const int side, unit_map& units, config cfg_unit1; new_unit.write(cfg_unit1); - DBG_NG << cfg_unit1.debug(); + DBG_NG << cfg_unit1; if (!game_config::ignore_replay_errors) { throw replay::error("OOS while recruiting."); } diff --git a/src/config.cpp b/src/config.cpp index 2ee9cb44e18..6e1cd802a0d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -688,22 +688,26 @@ void config::reset_translation() const std::string config::debug() const { std::ostringstream outstream; + outstream << *this; + return outstream.str(); +} + +std::ostream& operator << (std::ostream& outstream, const config& cfg) { static int i = 0; i++; - for(string_map::const_iterator val = values.begin(); val != values.end(); ++val) { + for(string_map::const_iterator val = cfg.values.begin(); val != cfg.values.end(); ++val) { for (int j = 0; j < i; j++){ outstream << char(9); } outstream << val->first << " = " << val->second << "\n"; } - - for(all_children_iterator list = ordered_begin(); list != ordered_end(); ++list) { + for(config::all_children_iterator list = cfg.ordered_begin(); list != cfg.ordered_end(); ++list) { { for (int j = 0; j < i-1; j++){ outstream << char(9); } } outstream << "[" << *(*list).first << "]\n"; - outstream << (*list).second->debug(); + outstream << (*list).second; { for (int j = 0; j < i-1; j++){ outstream << char(9); } } outstream << "[/" << *(*list).first << "]\n"; } i--; - return outstream.str(); + return outstream; } std::string config::hash() const diff --git a/src/config.hpp b/src/config.hpp index 2a229568e25..91e0ff84796 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -20,9 +20,9 @@ #include "global.hpp" -#include #include #include +#include #include #include #include "tstring.hpp" @@ -179,5 +179,6 @@ private: bool operator==(const config& a, const config& b); bool operator!=(const config& a, const config& b); +std::ostream& operator << (std::ostream& os, const config& cfg); #endif diff --git a/src/game_events.cpp b/src/game_events.cpp index 2bf80b280b1..a7f46b50159 100644 --- a/src/game_events.cpp +++ b/src/game_events.cpp @@ -2514,7 +2514,7 @@ static void commit_wmi_commands() { mref->command.add_child("allow_undo"); } LOG_NG << "setting command for " << mref->name << "\n"; - LOG_NG << wcc.second->debug(); + LOG_NG << *wcc.second; delete wcc.second; wmi_command_changes.pop_back(); } diff --git a/src/gamestatus.cpp b/src/gamestatus.cpp index 19b81ff5f7c..76a3759c19e 100644 --- a/src/gamestatus.cpp +++ b/src/gamestatus.cpp @@ -1237,7 +1237,7 @@ game_state::~game_state() { void game_state::set_variables(const config& vars) { if(!variables.empty()) { WRN_NG << "clobbering the game_state variables\n"; - WRN_NG << variables.debug(); + WRN_NG << variables; } variables = vars; } diff --git a/src/multiplayer_ui.cpp b/src/multiplayer_ui.cpp index 76546640719..8830c9d1dd0 100644 --- a/src/multiplayer_ui.cpp +++ b/src/multiplayer_ui.cpp @@ -155,7 +155,7 @@ void level_to_gamestate(config& level, game_state& state, bool saved_game) LOG_NG << "No variables were found for the game_state." << std::endl; } else { LOG_NG << "Variables found and loaded into game_state:" << std::endl; - LOG_NG << state.get_variables().debug(); + LOG_NG << state.get_variables(); } } diff --git a/src/network.cpp b/src/network.cpp index 211bc676052..75c333da0e6 100644 --- a/src/network.cpp +++ b/src/network.cpp @@ -687,7 +687,7 @@ connection receive_data(config& cfg, connection connection_num) } } if(!cfg.empty()) { - DBG_NW << "RECEIVED from: " << result << ": " << cfg.debug(); + DBG_NW << "RECEIVED from: " << result << ": " << cfg; } assert(result != 0); @@ -738,7 +738,7 @@ void send_data(const config& cfg, connection connection_num, const bool gzipped) return; } - LOG_NW << "SENDING to: " << connection_num << ": " << cfg.debug(); + LOG_NW << "SENDING to: " << connection_num << ": " << cfg; network_worker_pool::queue_data(info->second.sock, cfg, gzipped); } diff --git a/src/playcampaign.cpp b/src/playcampaign.cpp index 0c741198a84..e52024763af 100644 --- a/src/playcampaign.cpp +++ b/src/playcampaign.cpp @@ -511,7 +511,6 @@ LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_ // Sends scenario data config cfg; cfg.add_child("store_next_scenario", *scenario); - (*scenario).debug(); // Adds player information, and other state // information, to the configuration object diff --git a/src/replay.cpp b/src/replay.cpp index f5be35da8ee..3d8120ed8bd 100644 --- a/src/replay.cpp +++ b/src/replay.cpp @@ -746,7 +746,7 @@ bool do_replay_handle(game_display& disp, const gamemap& map, const game_data& g bool fix_shroud = false; if (cfg) { - DBG_REPLAY << "Replay data:\n" << cfg->debug() << "\n"; + DBG_REPLAY << "Replay data:\n" << *cfg << "\n"; } else { diff --git a/src/server/game.cpp b/src/server/game.cpp index 3022c2a57ad..b97d8d7cb92 100644 --- a/src/server/game.cpp +++ b/src/server/game.cpp @@ -234,7 +234,7 @@ void game::update_side_data() { const config::child_itors level_sides = level_.child_range("side"); /* for (config::child_iterator side = level_sides.first; side != level_sides.second; ++side) - DBG_GAME << (*side)->debug();*/ + DBG_GAME << (**side);*/ // For each user: // * Find the username. // * Find the side this username corresponds to. @@ -756,7 +756,7 @@ void game::filter_commands(const network::connection member, config& cfg) { const config& server_msg = construct_server_message(msg.str()); send_data(server_msg); record_data(server_msg); - DBG_GAME << (*i)->debug(); + DBG_GAME << (**i); marked.push_back(index - marked.size()); } ++index; @@ -768,7 +768,7 @@ void game::filter_commands(const network::connection member, config& cfg) { } bool game::process_commands(const config& cfg) { - //DBG_GAME << "processing commands: '" << cfg.debug() << "'\n"; + //DBG_GAME << "processing commands: '" << cfg << "'\n"; bool res = false; const config::child_list& cmd = cfg.get_children("command"); for(config::child_list::const_iterator i = cmd.begin(); i != cmd.end(); ++i) { diff --git a/src/server/server.cpp b/src/server/server.cpp index 8c3e9e0b7f9..3ee4332a3f5 100644 --- a/src/server/server.cpp +++ b/src/server/server.cpp @@ -1244,7 +1244,7 @@ void server::process_data_game(const network::connection sock, const config& dat // FIXME: Relaying arbitrary data that possibly didn't get handled at all // seems like a bad idea. DBG_SERVER << "Relaying data RECEIVED from: " << sock - << " to all other players: " << data.debug(); + << " to all other players: " << data; g->send_data(data, sock); if (g->started()) { g->record_data(data); diff --git a/src/tests/test_network_worker.cpp b/src/tests/test_network_worker.cpp index 9c9ee69cd7e..a0e6585b767 100644 --- a/src/tests/test_network_worker.cpp +++ b/src/tests/test_network_worker.cpp @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE( test_send_client ) BOOST_CHECK_MESSAGE( receive_from == server_client1, "Received data is not from test client 1" ); - BOOST_CHECK_MESSAGE(cfg_send == received, "send is not same as received\n" << cfg_send.debug() << "\n" << received.debug() ); + BOOST_CHECK_MESSAGE(cfg_send == received, "send is not same as received\n" << cfg_send << "\n" << received.debug() ); } diff --git a/src/unit_display.cpp b/src/unit_display.cpp index 857b3734bc0..7c0777820fe 100644 --- a/src/unit_display.cpp +++ b/src/unit_display.cpp @@ -86,11 +86,12 @@ static void move_unit_between(const gamemap::location& a, const gamemap::locatio animator.wait_until(target_time); gamemap::location arr[6]; get_adjacent_tiles(a, arr); - for (unsigned int i = 0; i < 6; i++) { + unsigned int i; + for (i = 0; i < 6; i++) { disp->invalidate(arr[i]); } get_adjacent_tiles(b, arr); - for (unsigned int i = 0; i < 6; i++) { + for (i = 0; i < 6; i++) { disp->invalidate(arr[i]); } }