Remove the use of lambdas in buildingplan.

develop
Alexander Gavrilov 2013-10-02 19:55:48 +04:00
parent 33469f5bb2
commit f3be0ee187
1 changed files with 22 additions and 18 deletions

@ -92,6 +92,8 @@ static void debug(const string &msg)
* Material Choice Screen * Material Choice Screen
*/ */
static string material_to_string_fn(MaterialInfo m) { return m.toString(); }
struct ItemFilter struct ItemFilter
{ {
df::dfhack_material_category mat_mask; df::dfhack_material_category mat_mask;
@ -114,8 +116,10 @@ struct ItemFilter
bool matches(MaterialInfo &material) const bool matches(MaterialInfo &material) const
{ {
return any_of(materials.begin(), materials.end(), for (auto it = materials.begin(); it != materials.end(); ++it)
[&] (const MaterialInfo &m) { return material.matches(m); }); if (material.matches(*it))
return true;
return false;
} }
bool matches(df::item *item) bool matches(df::item *item)
@ -137,8 +141,7 @@ struct ItemFilter
{ {
vector<string> descriptions; vector<string> descriptions;
transform_(materials, descriptions, transform_(materials, descriptions, material_to_string_fn);
[] (MaterialInfo m) { return m.toString(); });
if (descriptions.size() == 0) if (descriptions.size() == 0)
bitfield_to_string(&descriptions, mat_mask); bitfield_to_string(&descriptions, mat_mask);
@ -157,8 +160,8 @@ struct ItemFilter
str.append("/"); str.append("/");
if (materials.size() > 0) if (materials.size() > 0)
{ {
for_each_(materials, for (size_t i = 0; i < materials.size(); i++)
[&] (MaterialInfo &m) { str.append(m.getToken() + ","); }); str.append(materials[i].getToken() + ",");
if (str[str.size()-1] == ',') if (str[str.size()-1] == ',')
str.resize(str.size () - 1); str.resize(str.size () - 1);
@ -217,6 +220,7 @@ private:
bool valid; bool valid;
}; };
static MaterialInfo &material_info_identity_fn(MaterialInfo &m) { return m; }
class ViewscreenChooseMaterial : public dfhack_viewscreen class ViewscreenChooseMaterial : public dfhack_viewscreen
{ {
@ -284,13 +288,12 @@ public:
// Category masks // Category masks
auto masks = masks_column.getSelectedElems(); auto masks = masks_column.getSelectedElems();
for_each_(masks, for (auto it = masks.begin(); it != masks.end(); ++it)
[&] (df::dfhack_material_category &m) { filter->mat_mask.whole |= m.whole; }); filter->mat_mask.whole |= it->whole;
// Specific materials // Specific materials
auto materials = materials_column.getSelectedElems(); auto materials = materials_column.getSelectedElems();
transform_(materials, filter->materials, transform_(materials, filter->materials, material_info_identity_fn);
[] (MaterialInfo &m) { return m; });
Screen::dismiss(this); Screen::dismiss(this);
} }
@ -465,6 +468,7 @@ private:
} }
}; };
static void delete_item_fn(df::job_item *x) { delete x; }
// START Planning // START Planning
class PlannedBuilding class PlannedBuilding
@ -555,7 +559,7 @@ public:
auto job = building->jobs[0]; auto job = building->jobs[0];
for_each_(job->job_items, [] (df::job_item *x) { delete x; }); for_each_(job->job_items, delete_item_fn);
job->job_items.clear(); job->job_items.clear();
job->flags.bits.suspend = false; job->flags.bits.suspend = false;
@ -613,9 +617,10 @@ private:
ItemFilter filter; ItemFilter filter;
}; };
static map<df::building_type, bool> planmode_enabled, saved_planmodes; static map<df::building_type, bool> planmode_enabled, saved_planmodes;
static void enable_quickfort_fn(pair<const df::building_type, bool>& pair) { pair.second = true; }
class Planner class Planner
{ {
public: public:
@ -804,8 +809,7 @@ public:
void enableQuickfortMode() void enableQuickfortMode()
{ {
saved_planmodes = planmode_enabled; saved_planmodes = planmode_enabled;
for_each_(planmode_enabled, for_each_(planmode_enabled, enable_quickfort_fn);
[] (pair<const df::building_type, bool>& pair) { pair.second = true; } );
quickfort_mode = true; quickfort_mode = true;
} }
@ -1093,8 +1097,8 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
OutputHotkeyString(x, y, "Material Filter:", "m", true, left_margin); OutputHotkeyString(x, y, "Material Filter:", "m", true, left_margin);
auto filter_descriptions = filter->getMaterialFilterAsVector(); auto filter_descriptions = filter->getMaterialFilterAsVector();
for_each_(filter_descriptions, for (auto it = filter_descriptions.begin(); it != filter_descriptions.end(); ++it)
[&](string d) { OutputString(COLOR_BROWN, x, y, " *" + d, true, left_margin); }); OutputString(COLOR_BROWN, x, y, " *" + *it, true, left_margin);
} }
else else
{ {
@ -1121,8 +1125,8 @@ struct buildingplan_hook : public df::viewscreen_dwarfmodest
OutputString(COLOR_BROWN, x, y, "Materials:", true, left_margin); OutputString(COLOR_BROWN, x, y, "Materials:", true, left_margin);
auto filters = filter->getMaterialFilterAsVector(); auto filters = filter->getMaterialFilterAsVector();
for_each_(filters, for (auto it = filters.begin(); it != filters.end(); ++it)
[&](string d) { OutputString(COLOR_BLUE, x, y, "*" + d, true, left_margin); }); OutputString(COLOR_BLUE, x, y, "*" + *it, true, left_margin);
} }
else else
{ {