From 214e1736f0ed2ce613a75990caa98b521cbd726d Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 16 Jun 2024 21:40:28 +0200 Subject: [PATCH] Reading waiver comments on RVE database, automatically read associated .waived RVE DB file --- src/rdb/rdb/rdbRVEReader.cc | 35 +++++++++++++++++++++++-- src/rdb/unit_tests/rdbRVEReaderTests.cc | 10 +++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/rdb/rdb/rdbRVEReader.cc b/src/rdb/rdb/rdbRVEReader.cc index 96ddd466b..e29b48f1b 100644 --- a/src/rdb/rdb/rdbRVEReader.cc +++ b/src/rdb/rdb/rdbRVEReader.cc @@ -62,10 +62,32 @@ public: virtual void read (Database &db) { try { + // TODO: do not allow waivers here? + // (otherwise, description lines like "WE0 ..." would be read as waivers) do_read (db); } catch (tl::Exception &ex) { error (ex.msg ()); } + + try { + + // try to find a waiver database and apply it if possible + std::string waived_source = m_input_stream.source () + ".waived"; + + tl::InputStream is_waived (waived_source); + + try { + Database db_waived; + RVEReader reader_waived (is_waived); + reader_waived.do_read (db_waived); + db.apply (db_waived); + } catch (tl::Exception &ex) { + warn (ex.msg ()); + } + + } catch (...) { + // ignore stream errors + } } void do_read (Database &db) @@ -157,7 +179,16 @@ public: while (*cp && isspace (*cp)) { ++cp; } - waivers.insert (std::make_pair (n, std::string ())).first->second = cp; + + auto wi = waivers.insert (std::make_pair (n, std::string ())); + // NOTE: first line is skipped (author, time) + if (! wi.second) { + std::string &s = wi.first->second; + if (! s.empty ()) { + s += "\n"; + } + s += cp; + } } else { @@ -176,7 +207,6 @@ public: std::map::const_iterator w = waivers.find (shape); bool waived = (w != waivers.end ()); - // TODO: add waiver string somehow ... if (at_end ()) { warn (tl::to_string (tr ("Unexpected end of file before the specified number of shapes was read - stopping."))); @@ -406,6 +436,7 @@ public: Item *item = db.create_item (cell->id (), cath->id ()); if (waived) { db.add_item_tag (item, waived_tag_id); + item->set_comment (w->second); } item->values ().swap (values); diff --git a/src/rdb/unit_tests/rdbRVEReaderTests.cc b/src/rdb/unit_tests/rdbRVEReaderTests.cc index 66368ae81..94cc1c001 100644 --- a/src/rdb/unit_tests/rdbRVEReaderTests.cc +++ b/src/rdb/unit_tests/rdbRVEReaderTests.cc @@ -81,3 +81,13 @@ TEST(3) { run_rve_test (_this, "rve3.db", "rve3_au_2.txt"); } + +TEST(4) +{ + run_rve_test (_this, "rve4.db", "rve4_au.txt"); +} + +TEST(5) +{ + run_rve_test (_this, "rve5.db", "rve5_au.txt"); +}