Commit e853cd1c by Maarten L. Hekkelman

set_validator changes

parent b9544033
...@@ -49,6 +49,7 @@ void datablock::set_validator(const validator *v) ...@@ -49,6 +49,7 @@ void datablock::set_validator(const validator *v)
} }
catch (const std::exception &) catch (const std::exception &)
{ {
m_validator = nullptr;
throw_with_nested(std::runtime_error("Error while setting validator in datablock " + m_name)); throw_with_nested(std::runtime_error("Error while setting validator in datablock " + m_name));
} }
} }
......
...@@ -31,11 +31,32 @@ namespace cif ...@@ -31,11 +31,32 @@ namespace cif
{ {
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// TODO: This is wrong. A validator should be assigned to datablocks,
// not to a file. Since audit_conform is a category specifying the
// content of a datablock. Not the entire file.
void file::set_validator(const validator *v) void file::set_validator(const validator *v)
{ {
m_validator = v; m_validator = v;
for (auto &db : *this) for (bool first = true; auto &db : *this)
db.set_validator(v); {
try
{
db.set_validator(v);
}
catch (const std::exception &e)
{
if (first)
throw;
// Accept failure on secondary datablocks
// now that many mmCIF files have invalid
// restraint data concatenated.
std::cerr << e.what() << '\n';
}
first = false;
}
} }
bool file::is_valid() const bool file::is_valid() const
...@@ -78,12 +99,12 @@ bool file::validate_links() const ...@@ -78,12 +99,12 @@ bool file::validate_links() const
{ {
if (m_validator == nullptr) if (m_validator == nullptr)
std::runtime_error("No validator loaded explicitly, cannot continue"); std::runtime_error("No validator loaded explicitly, cannot continue");
bool result = true; bool result = true;
for (auto &db : *this) for (auto &db : *this)
result = db.validate_links() and result; result = db.validate_links() and result;
return result; return result;
} }
...@@ -97,7 +118,7 @@ void file::load_dictionary() ...@@ -97,7 +118,7 @@ void file::load_dictionary()
std::string name = audit_conform->front().get<std::string>("dict_name"); std::string name = audit_conform->front().get<std::string>("dict_name");
if (name == "mmcif_pdbx_v50") if (name == "mmcif_pdbx_v50")
name = "mmcif_pdbx.dic"; // we had a bug here in libcifpp... name = "mmcif_pdbx.dic"; // we had a bug here in libcifpp...
if (not name.empty()) if (not name.empty())
{ {
...@@ -125,7 +146,8 @@ void file::load_dictionary(std::string_view name) ...@@ -125,7 +146,8 @@ void file::load_dictionary(std::string_view name)
bool file::contains(std::string_view name) const bool file::contains(std::string_view name) const
{ {
return std::find_if(begin(), end(), [name](const datablock &db) { return iequals(db.name(), name); }) != end(); return std::find_if(begin(), end(), [name](const datablock &db)
{ return iequals(db.name(), name); }) != end();
} }
datablock &file::operator[](std::string_view name) datablock &file::operator[](std::string_view name)
......
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