Reading waiver comments on RVE database, automatically read associated .waived RVE DB file

This commit is contained in:
Matthias Koefferlein 2024-06-16 21:40:28 +02:00
parent 579da640ba
commit 214e1736f0
2 changed files with 43 additions and 2 deletions

View File

@ -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<size_t, std::string>::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);

View File

@ -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");
}