Skip to content

Commit

Permalink
Backport: Use BOOST_FOREACH directly instead of #define foreach BOOST…
Browse files Browse the repository at this point in the history
…_FOREACH

2012-07-07T00:49:45Z!loonycyborg@gmail.com from trunk.

The define is extremely unreliable, will break compile with boost >=
1.50 and upstream can't fix issues with it, see

https://svn.boost.org/trac/boost/ticket/6131
  • Loading branch information
loonycyborg committed Jul 8, 2012
1 parent 8d2892c commit c7b7cdd
Show file tree
Hide file tree
Showing 195 changed files with 1,280 additions and 1,199 deletions.
21 changes: 11 additions & 10 deletions src/about.cpp
Expand Up @@ -22,10 +22,11 @@

#include "construct_dialog.hpp"
#include "display.hpp"
#include "foreach.hpp"
#include "gettext.hpp"
#include "marked-up_text.hpp"

#include <boost/foreach.hpp>

/**
* @namespace about
* Display credits %about all contributors.
Expand All @@ -52,7 +53,7 @@ static void add_lines(std::vector<std::string> &res, config const &c) {
}

std::vector<std::string> lines = utils::split(c["text"], '\n');
foreach (std::string &line, lines)
BOOST_FOREACH(std::string &line, lines)
{
if (line.size() > 1 && line[0] == '+')
line = "+ " + line.substr(1);
Expand All @@ -67,7 +68,7 @@ static void add_lines(std::vector<std::string> &res, config const &c) {
}
}

foreach (const config &entry, c.child_range("entry")) {
BOOST_FOREACH(const config &entry, c.child_range("entry")) {
res.push_back("- "+ entry["name"].str());
}
}
Expand All @@ -80,15 +81,15 @@ std::vector<std::string> get_text(const std::string &campaign)
config::child_itors about_entries = about_list.child_range("about");

if (!campaign.empty()) {
foreach (const config &about, about_entries) {
BOOST_FOREACH(const config &about, about_entries) {
// just finished a particular campaign
if (campaign == about["id"]) {
add_lines(res, about);
}
}
}

foreach (const config &about, about_entries) {
BOOST_FOREACH(const config &about, about_entries) {
add_lines(res, about);
}

Expand All @@ -101,7 +102,7 @@ void set_about(const config &cfg)
images.clear();
images_default = "";

foreach (const config &about, cfg.child_range("about"))
BOOST_FOREACH(const config &about, cfg.child_range("about"))
{
about_list.add_child("about", about);
const std::string &im = about["images"];
Expand All @@ -114,7 +115,7 @@ void set_about(const config &cfg)
}
}

foreach (const config &campaign, cfg.child_range("campaign"))
BOOST_FOREACH(const config &campaign, cfg.child_range("campaign"))
{
config::const_child_itors abouts = campaign.child_range("about");
if (abouts.first == abouts.second) continue;
Expand All @@ -126,7 +127,7 @@ void set_about(const config &cfg)
temp["id"] = id;
std::string campaign_images;

foreach (const config &about, abouts)
BOOST_FOREACH(const config &about, abouts)
{
const std::string &subtitle = about["title"];
if (!subtitle.empty())
Expand All @@ -139,12 +140,12 @@ void set_about(const config &cfg)
text << '\n';
}

foreach (const std::string &line, utils::split(about["text"], '\n'))
BOOST_FOREACH(const std::string &line, utils::split(about["text"], '\n'))
{
text << " " << line << '\n';
}

foreach (const config &entry, about.child_range("entry"))
BOOST_FOREACH(const config &entry, about.child_range("entry"))
{
text << " " << entry["name"] << '\n';
}
Expand Down
24 changes: 12 additions & 12 deletions src/actions.cpp
Expand Up @@ -21,7 +21,6 @@
#include "actions.hpp"

#include "attack_prediction.hpp"
#include "foreach.hpp"
#include "game_display.hpp"
#include "game_events.hpp"
#include "game_preferences.hpp"
Expand All @@ -40,6 +39,7 @@
#include "whiteboard/manager.hpp"

#include <boost/bind.hpp>
#include <boost/foreach.hpp>

static lg::log_domain log_engine("engine");
#define DBG_NG LOG_STREAM(debug, log_engine)
Expand Down Expand Up @@ -206,7 +206,7 @@ map_location unit_creator::find_location(const config &cfg, const unit* pass_che
placements.push_back("map");
placements.push_back("recall");

foreach(std::string place, placements) {
BOOST_FOREACH(std::string place, placements) {
map_location loc;
bool pass((place == "leader_passable") || (place == "map_passable"));

Expand Down Expand Up @@ -417,7 +417,7 @@ const std::vector<const unit*> get_recalls_for_location(int side, const map_loca
leader_in_place= true;
else continue;

foreach (const unit& recall_unit, recall_list)
BOOST_FOREACH(const unit& recall_unit, recall_list)
{
//Only units which match the leaders recall filter are valid.
scoped_recall_unit this_unit("this_unit", t.save_id(), &recall_unit - &recall_list[0]);
Expand All @@ -435,7 +435,7 @@ const std::vector<const unit*> get_recalls_for_location(int side, const map_loca
}

if (!(recall_loc_is_castle && leader_in_place)) {
foreach (const unit &recall, recall_list)
BOOST_FOREACH(const unit &recall, recall_list)
{
result.push_back(&recall);
}
Expand Down Expand Up @@ -546,7 +546,7 @@ std::string find_recruit_location(const int side, map_location& recruit_location

bool can_recruit_unit = is_on_team_list;
if (!can_recruit_unit) {
foreach (const std::string &recruitable, leader->recruits()) {
BOOST_FOREACH(const std::string &recruitable, leader->recruits()) {
if (recruitable == unit_type) {
can_recruit_unit = true;
break;
Expand Down Expand Up @@ -1925,7 +1925,7 @@ bool get_village(const map_location& loc, int side, int *action_timebonus)
// Simple algorithm: no maximum number of patients per healer.
void reset_resting(unit_map& units, int side)
{
foreach (unit &u, units) {
BOOST_FOREACH(unit &u, units) {
if (u.side() == side)
u.set_resting(true);
}
Expand All @@ -1946,7 +1946,7 @@ void calculate_healing(int side, bool update_display)
std::list<unit_healing_struct> l;

// We look for all allied units, then we see if our healer is near them.
foreach (unit &u, units) {
BOOST_FOREACH(unit &u, units) {

if (u.get_state("unhealable") || u.incapacitated())
continue;
Expand Down Expand Up @@ -2307,7 +2307,7 @@ namespace {
}

pathfind::paths p(*resources::game_map, *resources::units, loc, *resources::teams, true, false, tm, 0, false, true);
foreach (const pathfind::paths::step &dest, p.destinations) {
BOOST_FOREACH(const pathfind::paths::step &dest, p.destinations) {
clear_shroud_loc(tm, dest.curr, &cleared_locations);
}

Expand Down Expand Up @@ -2350,7 +2350,7 @@ void recalculate_fog(int side)

tm.refog();

foreach (unit &u, *resources::units)
BOOST_FOREACH(unit &u, *resources::units)
{
if (u.side() == side) {
const unit_movement_resetter move_resetter(u);
Expand All @@ -2372,7 +2372,7 @@ bool clear_shroud(int side)

bool result = false;

foreach (unit &u, *resources::units)
BOOST_FOREACH(unit &u, *resources::units)
{
if (u.side() == side) {
const unit_movement_resetter move_resetter(u);
Expand Down Expand Up @@ -2435,7 +2435,7 @@ size_t move_unit(move_unit_spectator *move_spectator,

std::set<map_location> known_units;
if(check_shroud) {
foreach (const unit &u, units) {
BOOST_FOREACH(const unit &u, units) {
if (!tm->fogged(u.get_location())) {
known_units.insert(u.get_location());
tm->see(u.side() - 1);
Expand Down Expand Up @@ -2860,7 +2860,7 @@ void apply_shroud_changes(undo_list &undos, int side)
*/

std::set<map_location> known_units;
foreach (const unit &u, units) {
BOOST_FOREACH(const unit &u, units) {
if (!tm.fogged(u.get_location())) {
known_units.insert(u.get_location());
}
Expand Down
33 changes: 17 additions & 16 deletions src/addon/manager.cpp
Expand Up @@ -19,7 +19,6 @@
#include "addon/manager.hpp"
#include "dialogs.hpp"
#include "filesystem.hpp"
#include "foreach.hpp"
#include "formatter.hpp"
#include "game_display.hpp"
#include "game_preferences.hpp"
Expand All @@ -41,6 +40,8 @@
#include "wml_separators.hpp"
#include "formula_string_utils.hpp"

#include <boost/foreach.hpp>

static lg::log_domain log_config("config");
#define ERR_CFG LOG_STREAM(err , log_config)
#define LOG_CFG LOG_STREAM(info, log_config)
Expand Down Expand Up @@ -321,11 +322,11 @@ static void unarchive_dir(const std::string& path, const config& cfg)

make_directory(dir);

foreach (const config &d, cfg.child_range("dir")) {
BOOST_FOREACH(const config &d, cfg.child_range("dir")) {
unarchive_dir(dir, d);
}

foreach (const config &f, cfg.child_range("file")) {
BOOST_FOREACH(const config &f, cfg.child_range("file")) {
unarchive_file(dir, f);
}
}
Expand Down Expand Up @@ -701,7 +702,7 @@ namespace {
std::string missing = "";
size_t count_missing = 0;

foreach(const std::string& i, dependencies) {
BOOST_FOREACH(const std::string& i, dependencies) {
if (std::find(installed.begin(), installed.end(), i) == installed.end()) {
missing += "\n" + i;
++count_missing;
Expand All @@ -717,7 +718,7 @@ namespace {
std::vector< std::string > unsafe_matches;
std::ostringstream unsafe_list;
std::map<std::string, version_info> remote_version_map;
foreach (const config &remote_addon, remote_addons_list)
BOOST_FOREACH(const config &remote_addon, remote_addons_list)
{
const std::string& name = remote_addon["name"];
if (std::find(dependencies.begin(), dependencies.end(), name) != dependencies.end()) {
Expand Down Expand Up @@ -837,7 +838,7 @@ namespace {
if(!result) {
assert(failed_titles.empty() == false);
std::string failed_titles_list_fmt;
foreach(const std::string& entry, failed_titles) {
BOOST_FOREACH(const std::string& entry, failed_titles) {
failed_titles_list_fmt += '\n';
failed_titles_list_fmt += entry;
}
Expand Down Expand Up @@ -870,7 +871,7 @@ namespace {
std::vector<version_info> safe_local_versions;
std::vector<version_info> unsafe_local_versions;
std::map<std::string, version_info> remote_version_map;
foreach (const config &remote_addon, remote_addons_list)
BOOST_FOREACH(const config &remote_addon, remote_addons_list)
{
const std::string& name = remote_addon["name"];
const std::string& version = remote_addon["version"];
Expand Down Expand Up @@ -1065,7 +1066,7 @@ namespace {
if(!result) {
assert(failed_titles.empty() == false);
std::string failed_titles_list_fmt;
foreach(const std::string& entry, failed_titles) {
BOOST_FOREACH(const std::string& entry, failed_titles) {
failed_titles_list_fmt += '\n';
failed_titles_list_fmt += entry;
}
Expand All @@ -1090,7 +1091,7 @@ namespace {
const std::string& addon,
const std::vector<std::string>& own_addons)
{
foreach(const std::string& current_own_addon, own_addons) {
BOOST_FOREACH(const std::string& current_own_addon, own_addons) {
if(current_own_addon == addon) {
utils::string_map symbols;
symbols["addon"] = addon;
Expand Down Expand Up @@ -1171,7 +1172,7 @@ namespace {

std::vector< addon_info > infos;

foreach(const config &c, addon_cfgs)
BOOST_FOREACH(const config &c, addon_cfgs)
{
const std::string& name = c["name"];
const std::string& downloads = c["downloads"].str();
Expand Down Expand Up @@ -1254,13 +1255,13 @@ namespace {
infos.push_back(inf);
}

foreach(const std::string& pub, publish_options) {
BOOST_FOREACH(const std::string& pub, publish_options) {
static const std::string publish_icon = "icons/icon-addon-publish.png";
const std::string text = _("Publish add-on: ") + get_addon_name(pub);
options.push_back(IMAGE_PREFIX + publish_icon + COLUMN_SEPARATOR + font::GOOD_TEXT + text);
options_to_filter.push_back(text);
}
foreach(const std::string& del, delete_options) {
BOOST_FOREACH(const std::string& del, delete_options) {
static const std::string delete_icon = "icons/icon-addon-delete.png";
const std::string text = _("Delete add-on: ") + get_addon_name(del);
options.push_back(IMAGE_PREFIX + delete_icon + COLUMN_SEPARATOR + font::BAD_TEXT + text);
Expand Down Expand Up @@ -1408,7 +1409,7 @@ namespace {

remove_names.clear();

foreach(const std::string& id, remove_ids) {
BOOST_FOREACH(const std::string& id, remove_ids) {
remove_names.push_back(get_addon_name(id));
}

Expand All @@ -1425,7 +1426,7 @@ namespace {

std::vector<std::string> failed_names, skipped_names, succeeded_names;

foreach(const std::string& id, remove_ids) {
BOOST_FOREACH(const std::string& id, remove_ids) {
const std::string& name = get_addon_name(id);

if(have_addon_pbl_info(id) || have_addon_in_vcs_tree(id)) {
Expand Down Expand Up @@ -1531,12 +1532,12 @@ void refresh_addon_version_info_cache()
}
static const std::string parentd = get_addon_campaigns_dir();
std::vector<std::string> addon_info_files;
foreach(std::string const& dir, addons)
BOOST_FOREACH(std::string const& dir, addons)
addon_info_files.push_back(parentd+"/"+dir+"/_info.cfg");

size_t i = 0;

foreach(std::string const& info_file, addon_info_files) {
BOOST_FOREACH(std::string const& info_file, addon_info_files) {
assert(i < addons.size());

std::string const& addon = addons[i];
Expand Down
7 changes: 4 additions & 3 deletions src/addon/validation.cpp
Expand Up @@ -17,7 +17,8 @@
#include "global.hpp"
#include "addon/validation.hpp"
#include "config.hpp"
#include "foreach.hpp"

#include <boost/foreach.hpp>

#include <cstring>

Expand All @@ -44,10 +45,10 @@ bool addon_name_legal(const std::string& name)

bool check_names_legal(const config& dir)
{
foreach (const config &path, dir.child_range("file")) {
BOOST_FOREACH(const config &path, dir.child_range("file")) {
if (!addon_name_legal(path["name"])) return false;
}
foreach (const config &path, dir.child_range("dir")) {
BOOST_FOREACH(const config &path, dir.child_range("dir")) {
if (!addon_name_legal(path["name"])) return false;
if (!check_names_legal(path)) return false;
}
Expand Down

0 comments on commit c7b7cdd

Please sign in to comment.