mirror of https://github.com/KLayout/klayout.git
On same name, creating a RDB category would return the original one.
This commit is contained in:
parent
fecb8a8c8a
commit
0f438cdbd2
|
|
@ -881,6 +881,13 @@ Categories::category_by_name (const char *path)
|
|||
return 0;
|
||||
}
|
||||
|
||||
Category *
|
||||
Categories::category_by_raw_name (const std::string &name)
|
||||
{
|
||||
auto c = m_categories_by_name.find (name);
|
||||
return c == m_categories_by_name.end () ? 0 : c->second;
|
||||
}
|
||||
|
||||
void
|
||||
Categories::import_category (Category *category)
|
||||
{
|
||||
|
|
@ -1353,6 +1360,11 @@ Database::create_category (const std::string &name)
|
|||
Category *
|
||||
Database::create_category (Categories *container, const std::string &name)
|
||||
{
|
||||
Category *existing = container->category_by_raw_name (name);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
set_modified ();
|
||||
|
||||
Category *cat = new Category (name);
|
||||
|
|
|
|||
|
|
@ -413,8 +413,8 @@ public:
|
|||
}
|
||||
|
||||
void add_category (Category *cath);
|
||||
|
||||
void set_database (Database *database);
|
||||
Category *category_by_raw_name (const std::string &name);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -952,6 +952,26 @@ class RDB_TestClass(unittest.TestCase):
|
|||
self.assertEqual(item1._is_const_object(), False)
|
||||
self.assertEqual(item1.has_tag(17), True)
|
||||
|
||||
def test_14(self):
|
||||
|
||||
# same names do not generate a new category
|
||||
rdb = pya.ReportDatabase("")
|
||||
|
||||
_cell = rdb.create_cell("CELL")
|
||||
|
||||
_cat = rdb.create_category("cat")
|
||||
_cat_same = rdb.create_category("cat")
|
||||
self.assertEqual(_cat.rdb_id(), _cat_same.rdb_id())
|
||||
|
||||
_subcat = rdb.create_category(_cat, "subcat")
|
||||
_subcat_same = rdb.create_category(_cat_same, "subcat")
|
||||
self.assertEqual(_subcat.rdb_id(), _subcat_same.rdb_id())
|
||||
|
||||
# testing whether decrementing the reference count would do harm
|
||||
_cat = None
|
||||
_cat_same = None
|
||||
self.assertEqual(_subcat.rdb_id(), _subcat_same.rdb_id())
|
||||
|
||||
# run unit tests
|
||||
if __name__ == '__main__':
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(RDB_TestClass)
|
||||
|
|
|
|||
|
|
@ -1017,6 +1017,23 @@ class RDB_TestClass < TestBase
|
|||
|
||||
end
|
||||
|
||||
def test_14
|
||||
|
||||
# same names do not generate a new category
|
||||
rdb = RBA::ReportDatabase::new("")
|
||||
|
||||
_cell = rdb.create_cell("CELL")
|
||||
|
||||
_cat = rdb.create_category("cat")
|
||||
_cat_same = rdb.create_category("cat")
|
||||
assert_equal(_cat.rdb_id, _cat_same.rdb_id)
|
||||
|
||||
_subcat = rdb.create_category(_cat, "subcat")
|
||||
_subcat_same = rdb.create_category(_cat_same, "subcat")
|
||||
assert_equal(_subcat.rdb_id, _subcat_same.rdb_id)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
load("test_epilogue.rb")
|
||||
|
|
|
|||
Loading…
Reference in New Issue