summaryrefslogtreecommitdiff
path: root/src/metadata.cpp
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2017-02-08 00:15:55 +0100
committerGitHub <noreply@github.com>2017-02-08 00:15:55 +0100
commitef6feca501fcf0d5a1fd2021f1d4df96a4533f65 (patch)
tree58361be1085c91222ab9c0cad507ca70a87dfe8e /src/metadata.cpp
parent0680c47d6c7d3e98e2b96b823f8cc9ca76d5e7f8 (diff)
downloadminetest-ef6feca501fcf0d5a1fd2021f1d4df96a4533f65.tar.gz
minetest-ef6feca501fcf0d5a1fd2021f1d4df96a4533f65.tar.bz2
minetest-ef6feca501fcf0d5a1fd2021f1d4df96a4533f65.zip
Add ModMetadata API (#5131)
* mod can create a ModMetadata object where store its values and retrieve it. * Modmetadata object can only be fetched at mod loading * Save when modified using same time as map interval or at server stop * add helper function to get mod storage path * ModMetadata has exactly same calls than all every other Metadata
Diffstat (limited to 'src/metadata.cpp')
-rw-r--r--src/metadata.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/metadata.cpp b/src/metadata.cpp
index 3cc45f919..2ce9af5af 100644
--- a/src/metadata.cpp
+++ b/src/metadata.cpp
@@ -76,13 +76,27 @@ const std::string &Metadata::getString(const std::string &name,
return resolveString(it->second, recursion);
}
-void Metadata::setString(const std::string &name, const std::string &var)
+/**
+ * Sets var to name key in the metadata storage
+ *
+ * @param name
+ * @param var
+ * @return true if key-value pair is created or changed
+ */
+bool Metadata::setString(const std::string &name, const std::string &var)
{
if (var.empty()) {
m_stringvars.erase(name);
- } else {
- m_stringvars[name] = var;
+ return true;
+ }
+
+ StringMap::iterator it = m_stringvars.find(name);
+ if (it != m_stringvars.end() && it->second == var) {
+ return false;
}
+
+ m_stringvars[name] = var;
+ return true;
}
const std::string &Metadata::resolveString(const std::string &str,