Skip to content

Commit

Permalink
Remove map_utils.hpp
Browse files Browse the repository at this point in the history
Rationale:
- The at() emulation is only used in one file and will become redundant once we move to C++11 soon
- The map_get_value_default function is also only used in one file, and removing it actually makes the logic clearer
- It was moved to map/utils.hpp despite having nothing to do with game maps; removing it is slightly easier than moving it again
  • Loading branch information
CelticMinstrel committed Mar 21, 2016
1 parent d49ef6b commit 9313769
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 80 deletions.
1 change: 0 additions & 1 deletion projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -820,7 +820,6 @@
<Unit filename="../../src/map/location.hpp" />
<Unit filename="../../src/map/map.cpp" />
<Unit filename="../../src/map/map.hpp" />
<Unit filename="../../src/map/utils.hpp" />
<Unit filename="../../src/marked-up_text.cpp" />
<Unit filename="../../src/marked-up_text.hpp" />
<Unit filename="../../src/md5.cpp" />
Expand Down
4 changes: 0 additions & 4 deletions projectfiles/VC9/wesnoth.vcproj
Expand Up @@ -24339,10 +24339,6 @@
RelativePath="..\..\src\util.hpp"
>
</File>
<File
RelativePath="..\..\src\map\utils.hpp"
>
</File>
<File
RelativePath="..\..\src\variable.cpp"
>
Expand Down
2 changes: 0 additions & 2 deletions projectfiles/Xcode/Wesnoth.xcodeproj/project.pbxproj
Expand Up @@ -1684,7 +1684,6 @@
B55999F00EC62181008DD061 /* md5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = md5.cpp; path = ../src/md5.cpp; sourceTree = "<group>"; };
B55999F10EC62181008DD061 /* marked-up_text.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = "marked-up_text.hpp"; path = "../src/marked-up_text.hpp"; sourceTree = "<group>"; };
B55999F20EC62181008DD061 /* marked-up_text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = "marked-up_text.cpp"; path = "../src/marked-up_text.cpp"; sourceTree = "<group>"; };
B55999F70EC62181008DD061 /* utils.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = utils.hpp; sourceTree = "<group>"; };
B55999F80EC62181008DD061 /* location.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = location.hpp; sourceTree = "<group>"; };
B55999F90EC62181008DD061 /* location.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = location.cpp; sourceTree = "<group>"; };
B55999FA0EC62181008DD061 /* label.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = label.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3344,7 +3343,6 @@
B55999F80EC62181008DD061 /* location.hpp */,
B5599A000EC62181008DD061 /* map.cpp */,
B55999FF0EC62181008DD061 /* map.hpp */,
B55999F70EC62181008DD061 /* utils.hpp */,
);
path = map;
sourceTree = "<group>";
Expand Down
11 changes: 8 additions & 3 deletions src/formula/formula.cpp
Expand Up @@ -18,7 +18,6 @@

#include "formula/callable.hpp"
#include "formula/function.hpp"
#include "map/utils.hpp"
#include "random_new.hpp"
#include "serialization/string_utils.hpp"

Expand Down Expand Up @@ -48,8 +47,14 @@ map_formula_callable& map_formula_callable::add(const std::string& key,

variant map_formula_callable::get_value(const std::string& key) const
{
return map_get_value_default(values_, key,
fallback_ ? fallback_->query_value(key) : variant());
std::map<std::string,variant>::const_iterator it = values_.find(key);
if(it != values_.end()) {
return it->second;
} else if(fallback_) {
return fallback_->query_value(key);
} else {
return variant();
}
}

void map_formula_callable::get_inputs(std::vector<formula_input>* inputs) const
Expand Down
36 changes: 30 additions & 6 deletions src/gui/auxiliary/filter.hpp
Expand Up @@ -20,11 +20,14 @@
#ifndef GUI_AUXILIARY_FILTER_HPP_INCLUDED
#define GUI_AUXILIARY_FILTER_HPP_INCLUDED

#include "global.hpp"
#include "gui/widgets/text_box.hpp"
#include "map/utils.hpp"
#include "util.hpp"
#include "serialization/string_utils.hpp"
#include "serialization/unicode.hpp"
#ifndef HAVE_CXX11
#include <stdexcept> // needed for the at() emulation
#endif

namespace gui2
{
Expand All @@ -35,13 +38,26 @@ inline bool sort(const tpane::titem& lhs,
const std::string& tag,
const bool ascending)
{
#ifdef HAVE_CXX11
if(ascending) {
return lexical_cast<T>(lhs.tags.at(tag))
< lexical_cast<T>(rhs.tags.at(tag));
} else {
return lexical_cast<T>(lhs.tags.at(tag))
> lexical_cast<T>(rhs.tags.at(tag));
}
#else
typedef std::map<std::string,std::string>::const_iterator iterator;
iterator lhs_it = lhs.tags.find(tag), rhs_it = rhs.tags.find(tag);
if(lhs_it == lhs.tags.end() || rhs_it == rhs.tags.end()) {
throw std::out_of_range("Key »" + tag + "« doesn't exist.");
}
if(ascending) {
return lexical_cast<T>(at(lhs.tags, tag))
< lexical_cast<T>(at(rhs.tags, tag));
return lexical_cast<T>(*lhs_it) < lexical_cast<T>(*rhs_it);
} else {
return lexical_cast<T>(at(lhs.tags, tag))
> lexical_cast<T>(at(rhs.tags, tag));
return lexical_cast<T>(*lhs_it) > lexical_cast<T>(*rhs_it);
}
#endif
}

/**
Expand All @@ -67,8 +83,16 @@ inline bool contains(const tpane::titem& item,
const std::string& tag,
const ttext_box& text_box)
{
return at(item.tags, tag).find(utf8::lowercase(text_box.text()))
#ifdef HAVE_CXX11
return item.tags.at(tag).find(utf8::lowercase(text_box.text()))
!= std::string::npos;
#else
std::map<std::string,std::string>::const_iterator it = item.tags.find(tag);
if(it == item.tags.end()) {
throw std::out_of_range("Key »" + tag + "« doesn't exist.");
}
return it->second.find(utf8::lowercase(text_box.text())) != std::string::npos;
#endif
}

} // namespace gui2
Expand Down
64 changes: 0 additions & 64 deletions src/map/utils.hpp

This file was deleted.

0 comments on commit 9313769

Please sign in to comment.