Commit bd3723ee by Maarten L. Hekkelman

Do not crash on empty rows (find result)

parent 7ffda74e
...@@ -5839,6 +5839,9 @@ void PDBFileParser::Parse(std::istream &is, cif::file &result) ...@@ -5839,6 +5839,9 @@ void PDBFileParser::Parse(std::istream &is, cif::file &result)
auto a1 = atom_site.find1("label_asym_id"_key == asym1 and "label_seq_id"_key == seq1 and "label_atom_id"_key == atom1); auto a1 = atom_site.find1("label_asym_id"_key == asym1 and "label_seq_id"_key == seq1 and "label_atom_id"_key == atom1);
auto a2 = atom_site.find1("label_asym_id"_key == asym2 and "label_seq_id"_key == seq2 and "label_atom_id"_key == atom2); auto a2 = atom_site.find1("label_asym_id"_key == asym2 and "label_seq_id"_key == seq2 and "label_atom_id"_key == atom2);
if (not a1 or not a2)
throw std::runtime_error("cannot find atom");
const auto &[x1, y1, z1] = a1.get<float, float, float>("cartn_x", "cartn_y", "cartn_z"); const auto &[x1, y1, z1] = a1.get<float, float, float>("cartn_x", "cartn_y", "cartn_z");
const auto &[x2, y2, z2] = a2.get<float, float, float>("cartn_x", "cartn_y", "cartn_z"); const auto &[x2, y2, z2] = a2.get<float, float, float>("cartn_x", "cartn_y", "cartn_z");
......
...@@ -31,30 +31,41 @@ namespace cif ...@@ -31,30 +31,41 @@ namespace cif
void row_handle::assign(size_t column, std::string_view value, bool updateLinked, bool validate) void row_handle::assign(size_t column, std::string_view value, bool updateLinked, bool validate)
{ {
assert(m_category); if (not m_category)
throw std::runtime_error("uninitialized row");
m_category->update_value(m_row, column, value, updateLinked, validate); m_category->update_value(m_row, column, value, updateLinked, validate);
} }
uint16_t row_handle::get_column_ix(std::string_view name) const uint16_t row_handle::get_column_ix(std::string_view name) const
{ {
assert(m_category); if (not m_category)
throw std::runtime_error("uninitialized row");
return m_category->get_column_ix(name); return m_category->get_column_ix(name);
} }
std::string_view row_handle::get_column_name(uint16_t ix) const std::string_view row_handle::get_column_name(uint16_t ix) const
{ {
assert(m_category); if (not m_category)
throw std::runtime_error("uninitialized row");
return m_category->get_column_name(ix); return m_category->get_column_name(ix);
} }
uint16_t row_handle::add_column(std::string_view name) uint16_t row_handle::add_column(std::string_view name)
{ {
assert(m_category); if (not m_category)
throw std::runtime_error("uninitialized row");
return m_category->add_column(name); return m_category->add_column(name);
} }
void row_handle::swap(size_t column, row_handle &b) void row_handle::swap(size_t column, row_handle &b)
{ {
if (not m_category)
throw std::runtime_error("uninitialized row");
m_category->swap_item(column, *this, b); m_category->swap_item(column, *this, b);
} }
...@@ -62,7 +73,9 @@ void row_handle::swap(size_t column, row_handle &b) ...@@ -62,7 +73,9 @@ void row_handle::swap(size_t column, row_handle &b)
row_initializer::row_initializer(row_handle rh) row_initializer::row_initializer(row_handle rh)
{ {
assert(rh.m_category); if (not rh.m_category)
throw std::runtime_error("uninitialized row");
assert(rh.m_row); assert(rh.m_row);
row *r = rh.get_row(); row *r = rh.get_row();
......
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