Renaming a library will also change the references

This commit is contained in:
Matthias Koefferlein 2025-10-14 23:13:10 +02:00
parent d1e440d565
commit b3cc5d73fe
5 changed files with 50 additions and 8 deletions

View File

@ -149,12 +149,7 @@ void
Library::rename (const std::string &name)
{
if (name != get_name () && db::LibraryManager::initialized ()) {
// if the name changed, reregister the library under the new name
db::LibraryManager::instance ().unregister_lib (this);
set_name (name);
db::LibraryManager::instance ().register_lib (this);
db::LibraryManager::instance ().rename (get_id (), name);
}
}

View File

@ -67,6 +67,39 @@ LibraryManager::~LibraryManager ()
clear ();
}
void
LibraryManager::rename (lib_id_type lib_id, const std::string &name)
{
db::Library *lib = 0;
{
tl::MutexLocker locker (&m_lock);
lib = lib_internal (lib_id);
if (! lib) {
return;
}
std::string org_name = lib->get_name ();
for (auto it = m_lib_by_name.find (org_name);it != m_lib_by_name.end () && it->first == org_name; ++it) {
if (it->second == lib_id) {
m_lib_by_name.erase (it);
break;
}
}
m_lib_by_name.insert (std::make_pair (name, lib_id));
lib->set_name (name);
}
// triggers a layout update
lib->remap_to (lib);
// issue the change notification
changed_event ();
}
std::pair<bool, lib_id_type>
LibraryManager::lib_by_name (const std::string &name, const std::set<std::string> &for_technologies) const
{

View File

@ -91,6 +91,11 @@ public:
return m_lib_by_name.end ();
}
/**
* @brief Renames a library
*/
void rename (lib_id_type lib_id, const std::string &name);
/**
* @brief Get the library by name which is valid for all given technologies
*

View File

@ -216,8 +216,8 @@ LibraryClass<db::Library> decl_Library ("db", "LibraryBase",
gsi::method ("rename", &db::Library::rename, gsi::arg ("name"),
"@brief Renames the library\n"
"\n"
"Re-registers the library under a new name. Note that this will not change library references - "
"i.e. references to the old name will become invalid after calling this method.\n"
"Re-registers the library under a new name. Note that this method will also change the references "
"to the library.\n"
"\n"
"This method has been introduced in version 0.30.5."
) +

View File

@ -127,6 +127,7 @@ class DBLibrary_TestClass < TestBase
assert_equal(lib.destroyed?, true)
lib = RBA::Library::new
lib.layout.create_cell("A")
lib.description = "LIB1"
lib.register("RBA-unit-test")
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
@ -138,14 +139,22 @@ class DBLibrary_TestClass < TestBase
lib.register("RBA-unit-test")
assert_equal(RBA::Library::library_by_name("RBA-unit-test").description, "LIB1")
ly = RBA::Layout::new
ci = ly.create_cell("A", "RBA-unit-test").cell_index
assert_equal(ly.cell(ci).qname, "RBA-unit-test.A")
lib.rename("RBA-unit-test2")
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
assert_equal(RBA::Library::library_by_name("RBA-unit-test2").description, "LIB1")
assert_equal(ly.cell(ci).qname, "RBA-unit-test2.A")
lib.delete
assert_equal(RBA::Library::library_by_name("RBA-unit-test"), nil)
assert_equal(RBA::Library::library_by_name("RBA-unit-test2"), nil)
assert_equal(ly.cell(ci).qname, "<defunct>RBA-unit-test2.A")
end
def test_5_reload