Commit fb2b1e98 by Maarten L. Hekkelman

Fixed serious bug in emplace of both datablock and file.

parent 5d4534fa
...@@ -143,13 +143,6 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name) ...@@ -143,13 +143,6 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name)
if (iequals(name, i->name())) if (iequals(name, i->name()))
{ {
is_new = false; is_new = false;
if (i != begin())
{
auto n = std::next(i);
splice(begin(), *this, i, n);
}
break; break;
} }
...@@ -158,12 +151,12 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name) ...@@ -158,12 +151,12 @@ std::tuple<datablock::iterator, bool> datablock::emplace(std::string_view name)
if (is_new) if (is_new)
{ {
auto &c = emplace_back(name); i = insert(end(), {name});
c.set_validator(m_validator, *this); i->set_validator(m_validator, *this);
} }
assert(end() != begin()); assert(i != end());
return std::make_tuple(std::prev(end()), is_new); return std::make_tuple(i, is_new);
} }
std::vector<std::string> datablock::get_tag_order() const std::vector<std::string> datablock::get_tag_order() const
...@@ -171,7 +164,6 @@ std::vector<std::string> datablock::get_tag_order() const ...@@ -171,7 +164,6 @@ std::vector<std::string> datablock::get_tag_order() const
std::vector<std::string> result; std::vector<std::string> result;
// for entry and audit_conform on top // for entry and audit_conform on top
auto ci = find_if(begin(), end(), [](const category &cat) auto ci = find_if(begin(), end(), [](const category &cat)
{ return cat.name() == "entry"; }); { return cat.name() == "entry"; });
if (ci != end()) if (ci != end())
...@@ -253,13 +245,32 @@ void datablock::write(std::ostream &os) const ...@@ -253,13 +245,32 @@ void datablock::write(std::ostream &os) const
{ {
// If the dictionary declares an audit_conform category, put it in, // If the dictionary declares an audit_conform category, put it in,
// but only if it does not exist already! // but only if it does not exist already!
if (get("audit_conform") == nullptr and m_validator->get_validator_for_category("audit_conform") != nullptr)
if (m_validator->get_validator_for_category("audit_conform") != nullptr)
{
auto *audit_conform = get("audit_conform");
if (audit_conform == nullptr or audit_conform->size() != 1) // There should be one entry here, I guess
audit_conform = nullptr;
else
{
// And the name and version should be filled in of course
auto &e = audit_conform->front();
if (e["dict_name"].empty() or e["dict_version"].empty())
audit_conform = nullptr;
}
if (not audit_conform)
{ {
category auditConform("audit_conform"); category auditConform("audit_conform");
auditConform.emplace({ { "dict_name", m_validator->name() }, // clang-format off
{ "dict_version", m_validator->version() } }); auditConform.emplace({
{ "dict_name", m_validator->name() },
{ "dict_version", m_validator->version() }
});
// clang-format on
auditConform.write(os); auditConform.write(os);
} }
}
// base order on parent child relationships, parents first // base order on parent child relationships, parents first
......
...@@ -158,13 +158,6 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name) ...@@ -158,13 +158,6 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name)
if (iequals(name, i->name())) if (iequals(name, i->name()))
{ {
is_new = false; is_new = false;
if (i != begin())
{
auto n = std::next(i);
splice(begin(), *this, i, n);
}
break; break;
} }
...@@ -173,12 +166,12 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name) ...@@ -173,12 +166,12 @@ std::tuple<file::iterator, bool> file::emplace(std::string_view name)
if (is_new) if (is_new)
{ {
auto &db = emplace_back(name); i = insert(end(), { name });
db.set_validator(m_validator); i->set_validator(m_validator);
} }
assert(begin() != end()); assert(i != end());
return std::make_tuple(std::prev(end()), is_new); return std::make_tuple(i, is_new);
} }
void file::load(const std::filesystem::path &p) void file::load(const std::filesystem::path &p)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment