From 72dc94197e68a2ccc95f7fa037fce7d9b27d688b Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Mon, 28 Jun 2021 20:29:40 +0200 Subject: [PATCH] New method: Circuit#nets_by_name --- src/db/db/gsiDeclDbNetlist.cc | 44 +++++++++++++++++++++++++++++++++++ testdata/ruby/dbNetlist.rb | 3 +++ 2 files changed, 47 insertions(+) diff --git a/src/db/db/gsiDeclDbNetlist.cc b/src/db/db/gsiDeclDbNetlist.cc index f2b0bdcd3..4461534e1 100644 --- a/src/db/db/gsiDeclDbNetlist.cc +++ b/src/db/db/gsiDeclDbNetlist.cc @@ -1234,6 +1234,38 @@ static db::Pin *create_pin (db::Circuit *circuit, const std::string &name) return & circuit->add_pin (name); } +static std::vector +nets_by_name (db::Circuit *circuit, const std::string &name_pattern) +{ + std::vector res; + + tl::GlobPattern glob (name_pattern); + for (db::Circuit::net_iterator n = circuit->begin_nets (); n != circuit->end_nets (); ++n) { + db::Net *net = n.operator-> (); + if (glob.match (net->name ())) { + res.push_back (net); + } + } + + return res; +} + +static std::vector +nets_by_name_const (const db::Circuit *circuit, const std::string &name_pattern) +{ + std::vector res; + + tl::GlobPattern glob (name_pattern); + for (db::Circuit::const_net_iterator n = circuit->begin_nets (); n != circuit->end_nets (); ++n) { + const db::Net *net = n.operator-> (); + if (glob.match (net->name ())) { + res.push_back (net); + } + } + + return res; +} + Class decl_dbCircuit (decl_dbNetlistObject, "db", "Circuit", gsi::method_ext ("create_pin", &create_pin, gsi::arg ("name"), "@brief Creates a new \\Pin object inside the circuit\n" @@ -1347,6 +1379,18 @@ Class decl_dbCircuit (decl_dbNetlistObject, "db", "Circuit", "\n\n" "This constness variant has been introduced in version 0.26.8" ) + + gsi::method_ext ("nets_by_name", &nets_by_name, gsi::arg ("name_pattern"), + "@brief Gets the net objects for a given name filter.\n" + "The name filter is a glob pattern. This method will return all \\Net objects matching the glob pattern.\n" + "\n" + "This method has been introduced in version 0.27.3.\n" + ) + + gsi::method_ext ("nets_by_name", &nets_by_name_const, gsi::arg ("name_pattern"), + "@brief Gets the net objects for a given name filter (const version).\n" + "The name filter is a glob pattern. This method will return all \\Net objects matching the glob pattern.\n" + "\n\n" + "This constness variant has been introduced in version 0.27.3" + ) + gsi::method ("pin_by_id", (db::Pin *(db::Circuit::*) (size_t)) &db::Circuit::pin_by_id, gsi::arg ("id"), "@brief Gets the \\Pin object corresponding to a specific ID\n" "If the ID is not a valid pin ID, nil is returned." diff --git a/testdata/ruby/dbNetlist.rb b/testdata/ruby/dbNetlist.rb index bb1d34570..7e5670fd0 100644 --- a/testdata/ruby/dbNetlist.rb +++ b/testdata/ruby/dbNetlist.rb @@ -698,7 +698,9 @@ class DBNetlist_TestClass < TestBase assert_equal(c.net_by_cluster_id(17).name, "NET1") assert_equal(c.net_by_cluster_id(42).inspect, "nil") assert_equal(c.net_by_name("NET1").name, "NET1") + assert_equal(c.nets_by_name("NET*").collect(&:name), ["NET1"]) assert_equal(c.net_by_name("DOESNOTEXIST").inspect, "nil") + assert_equal(c.nets_by_name("DOESNOTEXIST").collect(&:name), []) net2 = c.create_net net2.name = "NET2" @@ -706,6 +708,7 @@ class DBNetlist_TestClass < TestBase names = [] c.each_net { |n| names << n.name } assert_equal(names, [ "NET1", "NET2" ]) + assert_equal(c.nets_by_name("NET*").collect(&:name), ["NET1", "NET2"]) assert_equal(net1.pin_count, 0) c.connect_pin(pina1, net1)