diff --git a/src/db/db/dbLibrary.cc b/src/db/db/dbLibrary.cc index d590fef3a..87befc7cf 100644 --- a/src/db/db/dbLibrary.cc +++ b/src/db/db/dbLibrary.cc @@ -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); } } diff --git a/src/db/db/dbLibraryManager.cc b/src/db/db/dbLibraryManager.cc index 5ba169d65..24aa8b3f6 100644 --- a/src/db/db/dbLibraryManager.cc +++ b/src/db/db/dbLibraryManager.cc @@ -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 LibraryManager::lib_by_name (const std::string &name, const std::set &for_technologies) const { diff --git a/src/db/db/dbLibraryManager.h b/src/db/db/dbLibraryManager.h index 849daede4..9dd8f6489 100644 --- a/src/db/db/dbLibraryManager.h +++ b/src/db/db/dbLibraryManager.h @@ -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 * diff --git a/src/db/db/gsiDeclDbLibrary.cc b/src/db/db/gsiDeclDbLibrary.cc index 40351109a..d06caba5f 100644 --- a/src/db/db/gsiDeclDbLibrary.cc +++ b/src/db/db/gsiDeclDbLibrary.cc @@ -216,8 +216,8 @@ LibraryClass 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." ) + diff --git a/testdata/ruby/dbLibrary.rb b/testdata/ruby/dbLibrary.rb index cbe6ac78f..28286d2c7 100644 --- a/testdata/ruby/dbLibrary.rb +++ b/testdata/ruby/dbLibrary.rb @@ -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, "RBA-unit-test2.A") + end def test_5_reload