const std::vector<std::string> &itemstrings, IGameDef *gamedef)
{
std::vector<std::string> result;
- for (std::vector<std::string>::const_iterator
- it = itemstrings.begin();
- it != itemstrings.end(); it++) {
- result.push_back(craftGetItemName(*it, gamedef));
+ for (std::vector<std::string>::size_type i = 0;
+ i < itemstrings.size(); i++) {
+ result.push_back(craftGetItemName(itemstrings[i], gamedef));
}
return result;
}
const std::vector<ItemStack> &items, IGameDef *gamedef)
{
std::vector<std::string> result;
- for (std::vector<ItemStack>::const_iterator
- it = items.begin();
- it != items.end(); it++) {
- result.push_back(it->name);
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < items.size(); i++) {
+ result.push_back(items[i].name);
}
return result;
}
const std::vector<std::string> &items, IGameDef *gamedef)
{
std::vector<ItemStack> result;
- for (std::vector<std::string>::const_iterator
- it = items.begin();
- it != items.end(); it++) {
- result.push_back(ItemStack(std::string(*it), (u16)1,
+ for (std::vector<std::string>::size_type i = 0;
+ i < items.size(); i++) {
+ result.push_back(ItemStack(std::string(items[i]), (u16)1,
(u16)0, "", gamedef->getItemDefManager()));
}
return result;
bool success = false;
unsigned int x = 0;
unsigned int y = 0;
- for (std::vector<std::string>::const_iterator
- it = items.begin();
- it != items.end(); it++) {
+ for (std::vector<std::string>::size_type i = 0;
+ i < items.size(); i++) {
// Is this an actual item?
- if (*it != "") {
+ if (items[i] != "") {
if (!success) {
// This is the first nonempty item
min_x = max_x = x;
// Removes 1 from each item stack
static void craftDecrementInput(CraftInput &input, IGameDef *gamedef)
{
- for (std::vector<ItemStack>::iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (it->count != 0)
- it->remove(1);
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ if (input.items[i].count != 0)
+ input.items[i].remove(1);
}
}
// Make a copy of the replacements pair list
std::vector<std::pair<std::string, std::string> > pairs = replacements.pairs;
- for (std::vector<ItemStack>::iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ ItemStack &item = input.items[i];
// Find an appropriate replacement
bool found_replacement = false;
for (std::vector<std::pair<std::string, std::string> >::iterator
j = pairs.begin();
- j != pairs.end(); j++) {
- if (it->name == craftGetItemName(j->first, gamedef)) {
- if (it->count == 1) {
- it->deSerialize(j->second, gamedef->idef());
+ j != pairs.end(); ++j) {
+ if (item.name == craftGetItemName(j->first, gamedef)) {
+ if (item.count == 1) {
+ item.deSerialize(j->second, gamedef->idef());
found_replacement = true;
pairs.erase(j);
break;
} else {
ItemStack rep;
rep.deSerialize(j->second, gamedef->idef());
- it->remove(1);
+ item.remove(1);
found_replacement = true;
output_replacements.push_back(rep);
break;
}
}
// No replacement was found, simply decrement count by one
- if (!found_replacement && it->count > 0)
- it->remove(1);
+ if (!found_replacement && item.count > 0)
+ item.remove(1);
}
}
unsigned int width)
{
std::ostringstream os(std::ios::binary);
- os<<"{ ";
- unsigned int x = 0;
- for(std::vector<std::string>::const_iterator
- it = items.begin();
- it != items.end(); it++, x++) {
- if (x == width) {
- os<<"; ";
- x = 0;
- } else if (x != 0) {
- os<<",";
+ os << "{ ";
+ for(std::vector<std::string>::size_type i = 0;
+ i < items.size(); i++) {
+ if (i == width) {
+ os << "; ";
+ i = 0;
+ } else if (i != 0) {
+ os << ",";
}
- os << '"' << (*it) << '"';
+ os << '"' << items[i] << '"';
}
os << " }";
return os.str();
{
std::ostringstream os(std::ios::binary);
os << "{ ";
- unsigned int x = 0;
- for (std::vector<ItemStack>::const_iterator
- it = items.begin();
- it != items.end(); it++, x++) {
- if (x == width) {
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < items.size(); i++) {
+ if (i == width) {
os << "; ";
- x = 0;
- } else if (x != 0) {
- os<<",";
+ i = 0;
+ } else if (i != 0) {
+ os << ",";
}
- os << '"' << (it->getItemString()) << '"';
+ os << '"' << (items[i].getItemString()) << '"';
}
os << " }";
return os.str();
std::ostringstream os(std::ios::binary);
os<<"{";
const char *sep = "";
- for (std::vector<std::pair<std::string, std::string> >::const_iterator
- it = pairs.begin();
- it != pairs.end(); it++) {
- os << sep << '"' << (it->first) << "\"=>\"" << (it->second) << '"';
+ for (std::vector<std::pair<std::string, std::string> >::size_type i = 0;
+ i < pairs.size(); i++) {
+ const std::pair<std::string, std::string> &repl_p = pairs[i];
+ os << sep
+ << '"' << (repl_p.first)
+ << "\"=>\"" << (repl_p.second) << '"';
sep = ",";
}
os << "}";
// Filter empty items out of input
std::vector<std::string> input_filtered;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (it->name != "")
- input_filtered.push_back(it->name);
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ const ItemStack &item = input.items[i];
+ if (item.name != "")
+ input_filtered.push_back(item.name);
}
// If there is a wrong number of items in input, no match
ItemStack item1;
ItemStack item2;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (!it->empty()) {
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ const ItemStack &item = input.items[i];
+ if (!item.empty()) {
if (item1.empty())
- item1 = *it;
+ item1 = item;
else if (item2.empty())
- item2 = *it;
+ item2 = item;
else
return false;
}
{
ItemStack item1;
ItemStack item2;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (!it->empty()) {
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ const ItemStack &item = input.items[i];
+ if (!item.empty()) {
if (item1.empty())
- item1 = *it;
+ item1 = item;
else if (item2.empty())
- item2 = *it;
+ item2 = item;
}
}
ItemStack repaired = craftToolRepair(item1, item2, additional_wear, gamedef);
// Filter empty items out of input
std::vector<std::string> input_filtered;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (it->name != "")
- input_filtered.push_back(it->name);
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ const std::string &name = input.items[i].name;
+ if (name != "")
+ input_filtered.push_back(name);
}
// If there is a wrong number of items in input, no match
// Filter empty items out of input
std::vector<std::string> input_filtered;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (it->name != "")
- input_filtered.push_back(it->name);
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ const std::string &name = input.items[i].name;
+ if (name != "")
+ input_filtered.push_back(name);
}
// If there is a wrong number of items in input, no match
// If all input items are empty, abort.
bool all_empty = true;
- for (std::vector<ItemStack>::const_iterator
- it = input.items.begin();
- it != input.items.end(); it++) {
- if (!it->empty()) {
+ for (std::vector<ItemStack>::size_type i = 0;
+ i < input.items.size(); i++) {
+ if (!input.items[i].empty()) {
all_empty = false;
break;
}
const std::vector<CraftDefinition*> &hash_collisions = col_iter->second;
// Walk crafting definitions from back to front, so that later
// definitions can override earlier ones.
- for (std::vector<CraftDefinition*>::const_reverse_iterator
- it = hash_collisions.rbegin();
- it != hash_collisions.rend(); it++) {
- CraftDefinition *def = *it;
+ for (std::vector<CraftDefinition*>::size_type
+ i = hash_collisions.size(); i > 0; i--) {
+ CraftDefinition *def = hash_collisions[i - 1];
/*errorstream << "Checking " << input.dump() << std::endl
<< " against " << def->dump() << std::endl;*/
recipes.reserve(limit ? MYMIN(limit, vec.size()) : vec.size());
- for (std::vector<CraftDefinition*>::const_reverse_iterator
- it = vec.rbegin(); it != vec.rend(); ++it) {
+ for (std::vector<CraftDefinition*>::size_type i = vec.size();
+ i > 0; i--) {
+ CraftDefinition *def = vec[i - 1];
if (limit && recipes.size() >= limit)
break;
- recipes.push_back(*it);
+ recipes.push_back(def);
}
return recipes;
for (std::map<u64, std::vector<CraftDefinition*> >::const_iterator
it = (m_craft_defs[type]).begin();
it != (m_craft_defs[type]).end(); it++) {
- for (std::vector<CraftDefinition*>::const_iterator
- iit = it->second.begin(); iit != it->second.end(); iit++) {
- os << "type " << type << " hash " << it->first << (*iit)->dump() << "\n";
+ for (std::vector<CraftDefinition*>::size_type i = 0;
+ i < it->second.size(); i++) {
+ os << "type " << type
+ << " hash " << it->first
+ << " def " << it->second[i]->dump()
+ << "\n";
}
}
}
it = m_craft_defs[type].begin();
it != m_craft_defs[type].end(); it++) {
for (std::vector<CraftDefinition*>::iterator
- iit = it->second.begin(); iit != it->second.end(); iit++) {
+ iit = it->second.begin();
+ iit != it->second.end(); ++iit) {
delete *iit;
}
it->second.clear();
virtual void initHashes(IGameDef *gamedef)
{
// Move the CraftDefs from the unhashed layer into layers higher up.
- for (std::vector<CraftDefinition*>::iterator
- it = (m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0]).begin();
- it != (m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0]).end(); it++) {
- CraftDefinition *def = *it;
+ std::vector<CraftDefinition *> &unhashed =
+ m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0];
+ for (std::vector<CraftDefinition*>::size_type i = 0;
+ i < unhashed.size(); i++) {
+ CraftDefinition *def = unhashed[i];
// Initialize and get the definition's hash
def->initHash(gamedef);
// Enter the definition
m_craft_defs[type][hash].push_back(def);
}
- m_craft_defs[(int) CRAFT_HASH_TYPE_UNHASHED][0].clear();
+ unhashed.clear();
}
private:
//TODO: change both maps to unordered_map when c++11 can be used