Commit a65431a1 authored by Volker Krause's avatar Volker Krause
Browse files

Implement nested element iteration a bit nicer

The previous implementation was driven by how this was implemented for VDV,
the way this is done now doesn't require the parent context anymore.
parent 2c9bb76c
......@@ -129,7 +129,7 @@ private Q_SLOTS:
QVERIFY(c.isValid());
int i = 0;
while (c.isValid()) {
c = e.next(c);
c = c.next();
++i;
}
QCOMPARE(i, childCount);
......
......@@ -164,8 +164,11 @@ BER::Element BER::Element::first() const
return BER::Element(m_data, contentOffset(), contentSize());
}
BER::Element BER::Element::next(const Element &prev) const
BER::Element BER::Element::next() const
{
const auto off = prev.m_offset + prev.size();
return BER::Element(m_data, off, contentSize() - (off - contentOffset()));
const auto s = size();
if (m_dataSize <= m_offset + s) {
return {};
}
return BER::Element(m_data, m_offset + s, m_dataSize - m_offset - s);
}
......@@ -65,7 +65,7 @@ public:
/** First child element, for nested types. */
Element first() const;
/** Next child element, for nested types. */
Element next(const Element &prev) const;
Element next() const;
private:
int typeSize() const;
......
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