*/
void NodeMetadataList::serialize(std::ostream &os, u8 blockver, bool disk,
- bool absolute_pos) const
+ bool absolute_pos, bool include_empty) const
{
/*
Version 0 is a placeholder for "nothing to see here; go away."
*/
- u16 count = countNonEmpty();
+ u16 count = include_empty ? m_data.size() : countNonEmpty();
if (count == 0) {
writeU8(os, 0); // version
return;
i != m_data.end(); ++i) {
v3s16 p = i->first;
NodeMetadata *data = i->second;
- if (data->empty())
+ if (!include_empty && data->empty())
continue;
if (absolute_pos) {
std::vector<v3s16> NodeMetadataList::getAllKeys()
{
std::vector<v3s16> keys;
-
- NodeMetadataMap::const_iterator it;
- for (it = m_data.begin(); it != m_data.end(); ++it)
- keys.push_back(it->first);
+ keys.reserve(m_data.size());
+ for (const auto &it : m_data)
+ keys.push_back(it.first);
return keys;
}
{
NodeMetadataMap::const_iterator n = m_data.find(p);
if (n == m_data.end())
- return NULL;
+ return nullptr;
return n->second;
}
void NodeMetadataList::set(v3s16 p, NodeMetadata *d)
{
remove(p);
- m_data.insert(std::make_pair(p, d));
+ m_data.emplace(p, d);
}
void NodeMetadataList::clear()
int NodeMetadataList::countNonEmpty() const
{
int n = 0;
- NodeMetadataMap::const_iterator it;
- for (it = m_data.begin(); it != m_data.end(); ++it) {
- if (!it->second->empty())
+ for (const auto &it : m_data) {
+ if (!it.second->empty())
n++;
}
return n;