summaryrefslogtreecommitdiff
path: root/src/metadata.cpp
diff options
context:
space:
mode:
authorrubenwardy <rubenwardy@gmail.com>2017-01-31 16:43:45 +0000
committerrubenwardy <rubenwardy@gmail.com>2017-02-04 22:07:55 +0000
commitc2e7b1f57941cb34cb7e3d71dc040fad53a64e3e (patch)
treed62246a6838911aef8b71fd420e8b6c2ac455993 /src/metadata.cpp
parent13f94ecad5d4fcda08663ee91e45b4a205a1dadb (diff)
downloadminetest-c2e7b1f57941cb34cb7e3d71dc040fad53a64e3e.tar.gz
minetest-c2e7b1f57941cb34cb7e3d71dc040fad53a64e3e.tar.bz2
minetest-c2e7b1f57941cb34cb7e3d71dc040fad53a64e3e.zip
Derive NodeMetaRef from MetaDataRef
Diffstat (limited to 'src/metadata.cpp')
-rw-r--r--src/metadata.cpp48
1 files changed, 37 insertions, 11 deletions
diff --git a/src/metadata.cpp b/src/metadata.cpp
index 8e04aa2d3..96453d710 100644
--- a/src/metadata.cpp
+++ b/src/metadata.cpp
@@ -37,12 +37,39 @@ bool Metadata::empty() const
return m_stringvars.size() == 0;
}
-std::string Metadata::getString(const std::string &name,
- u16 recursion) const
+size_t Metadata::size() const
+{
+ return m_stringvars.size();
+}
+
+bool Metadata::contains(const std::string &name) const
+{
+ return m_stringvars.find(name) != m_stringvars.end();
+}
+
+bool Metadata::operator==(const Metadata &other) const
+{
+ if (size() != other.size())
+ return false;
+
+ for (StringMap::const_iterator it = m_stringvars.begin();
+ it != m_stringvars.end(); ++it) {
+ if (!other.contains(it->first) ||
+ other.getString(it->first) != it->second)
+ return false;
+ }
+
+ return true;
+}
+
+const std::string &Metadata::getString(const std::string &name,
+ u16 recursion) const
{
StringMap::const_iterator it = m_stringvars.find(name);
- if (it == m_stringvars.end())
- return "";
+ if (it == m_stringvars.end()) {
+ static const std::string empty_string = std::string("");
+ return empty_string;
+ }
return resolveString(it->second, recursion);
}
@@ -56,14 +83,13 @@ void Metadata::setString(const std::string &name, const std::string &var)
}
}
-std::string Metadata::resolveString(const std::string &str,
- u16 recursion) const
+const std::string &Metadata::resolveString(const std::string &str,
+ u16 recursion) const
{
- if (recursion > 1) {
- return str;
- }
- if (str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
+ if (recursion <= 1 &&
+ str.substr(0, 2) == "${" && str[str.length() - 1] == '}') {
return getString(str.substr(2, str.length() - 3), recursion + 1);
+ } else {
+ return str;
}
- return str;
}