aboutsummaryrefslogtreecommitdiff
path: root/src/nodemetadata.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/nodemetadata.cpp')
-rw-r--r--src/nodemetadata.cpp50
1 files changed, 30 insertions, 20 deletions
diff --git a/src/nodemetadata.cpp b/src/nodemetadata.cpp
index 1e40a1630..d4da7a5ed 100644
--- a/src/nodemetadata.cpp
+++ b/src/nodemetadata.cpp
@@ -45,10 +45,11 @@ void NodeMetadata::serialize(std::ostream &os) const
{
int num_vars = m_stringvars.size();
writeU32(os, num_vars);
- for(std::map<std::string, std::string>::const_iterator
- i = m_stringvars.begin(); i != m_stringvars.end(); i++){
- os<<serializeString(i->first);
- os<<serializeLongString(i->second);
+ for (StringMap::const_iterator
+ it = m_stringvars.begin();
+ it != m_stringvars.end(); ++it) {
+ os << serializeString(it->first);
+ os << serializeLongString(it->second);
}
m_inventory->serialize(os);
@@ -157,10 +158,21 @@ NodeMetadataList::~NodeMetadataList()
clear();
}
-NodeMetadata* NodeMetadataList::get(v3s16 p)
+std::vector<v3s16> NodeMetadataList::getAllKeys()
{
- std::map<v3s16, NodeMetadata*>::const_iterator n = m_data.find(p);
- if(n == m_data.end())
+ std::vector<v3s16> keys;
+
+ std::map<v3s16, NodeMetadata *>::const_iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it)
+ keys.push_back(it->first);
+
+ return keys;
+}
+
+NodeMetadata *NodeMetadataList::get(v3s16 p)
+{
+ std::map<v3s16, NodeMetadata *>::const_iterator n = m_data.find(p);
+ if (n == m_data.end())
return NULL;
return n->second;
}
@@ -168,8 +180,7 @@ NodeMetadata* NodeMetadataList::get(v3s16 p)
void NodeMetadataList::remove(v3s16 p)
{
NodeMetadata *olddata = get(p);
- if(olddata)
- {
+ if (olddata) {
delete olddata;
m_data.erase(p);
}
@@ -183,22 +194,20 @@ void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
void NodeMetadataList::clear()
{
- for(std::map<v3s16, NodeMetadata*>::iterator
- i = m_data.begin();
- i != m_data.end(); i++)
- {
- delete i->second;
+ std::map<v3s16, NodeMetadata*>::iterator it;
+ for (it = m_data.begin(); it != m_data.end(); ++it) {
+ delete it->second;
}
m_data.clear();
}
-std::string NodeMetadata::getString(const std::string &name, unsigned short recursion) const
+std::string NodeMetadata::getString(const std::string &name,
+ unsigned short recursion) const
{
- std::map<std::string, std::string>::const_iterator it;
- it = m_stringvars.find(name);
- if (it == m_stringvars.end()) {
+ StringMap::const_iterator it = m_stringvars.find(name);
+ if (it == m_stringvars.end())
return "";
- }
+
return resolveString(it->second, recursion);
}
@@ -211,7 +220,8 @@ void NodeMetadata::setString(const std::string &name, const std::string &var)
}
}
-std::string NodeMetadata::resolveString(const std::string &str, unsigned short recursion) const
+std::string NodeMetadata::resolveString(const std::string &str,
+ unsigned short recursion) const
{
if (recursion > 1) {
return str;