diff --git a/src/db/db/dbNetlist.cc b/src/db/db/dbNetlist.cc index d983c5391..e89aab1db 100644 --- a/src/db/db/dbNetlist.cc +++ b/src/db/db/dbNetlist.cc @@ -652,11 +652,13 @@ void Circuit::connect_pin (size_t pin_id, Net *net) // DeviceClass class implementation DeviceClass::DeviceClass () + : mp_netlist (0) { // .. nothing yet .. } DeviceClass::DeviceClass (const DeviceClass &other) + : mp_netlist (0) { operator= (other); } @@ -801,16 +803,19 @@ void Netlist::add_circuit (Circuit *circuit) void Netlist::remove_circuit (Circuit *circuit) { + circuit->set_netlist (0); m_circuits.erase (circuit); } void Netlist::add_device_class (DeviceClass *device_class) { m_device_classes.push_back (device_class); + device_class->set_netlist (this); } void Netlist::remove_device_class (DeviceClass *device_class) { + device_class->set_netlist (0); m_device_classes.erase (device_class); } diff --git a/src/db/db/dbNetlist.h b/src/db/db/dbNetlist.h index 656ff3d9a..83ebc36e9 100644 --- a/src/db/db/dbNetlist.h +++ b/src/db/db/dbNetlist.h @@ -28,6 +28,7 @@ #include "dbTrans.h" #include "tlObjectCollection.h" #include "tlVector.h" +#include "tlUniqueId.h" #include "gsiObject.h" #include @@ -1253,7 +1254,7 @@ private: * A device class describes a type of device. */ class DB_PUBLIC DeviceClass - : public gsi::ObjectBase, public tl::Object + : public gsi::ObjectBase, public tl::Object, public tl::UniqueId { public: typedef size_t port_id_type; @@ -1287,6 +1288,22 @@ public: return new DeviceClass (*this); } + /** + * @brief Gets the netlist the device class lives in + */ + db::Netlist *netlist () + { + return mp_netlist; + } + + /** + * @brief Gets the netlist the device class lives in (const version) + */ + const db::Netlist *netlist () const + { + return mp_netlist; + } + /** * @brief Gets the name of the device class * @@ -1353,8 +1370,16 @@ public: const DeviceParameterDefinition *parameter_definition (size_t id) const; private: + friend class Netlist; + std::vector m_port_definitions; std::vector m_parameter_definitions; + db::Netlist *mp_netlist; + + void set_netlist (db::Netlist *nl) + { + mp_netlist = nl; + } }; /** diff --git a/src/db/db/gsiDeclDbNetlist.cc b/src/db/db/gsiDeclDbNetlist.cc index 09026e21d..d388f1805 100644 --- a/src/db/db/gsiDeclDbNetlist.cc +++ b/src/db/db/gsiDeclDbNetlist.cc @@ -364,6 +364,11 @@ Class decl_dbDeviceParameterDefinition ("db", "De "This class has been added in version 0.26." ); +static tl::id_type id_of_device_class (const db::DeviceClass *cls) +{ + return tl::id_of (cls); +} + Class decl_dbDeviceClass ("db", "DeviceClass", gsi::method ("name", &db::DeviceClass::name, "@brief Gets the name of the device class." @@ -371,6 +376,15 @@ Class decl_dbDeviceClass ("db", "DeviceClass", gsi::method ("description", &db::DeviceClass::description, "@brief Gets the description text of the device class." ) + + gsi::method ("netlist", (db::Netlist *(db::DeviceClass::*) ()) &db::DeviceClass::netlist, + "@brief Gets the netlist the device class lives in." + ) + + gsi::method_ext ("id", &gsi::id_of_device_class, + "@brief Gets the unique ID of the device class\n" + "The ID is a unique integer that identifies the device class. Use the ID " + "to check for object identity - i.e. to determine whether two devices share the " + "same device class." + ) + gsi::method ("port_definitions", &db::DeviceClass::port_definitions, "@brief Gets the list of port definitions of the device.\n" "See the \\DevicePortDefinition class description for details." diff --git a/testdata/ruby/dbNetlist.rb b/testdata/ruby/dbNetlist.rb index e38207b35..a5fdecad4 100644 --- a/testdata/ruby/dbNetlist.rb +++ b/testdata/ruby/dbNetlist.rb @@ -137,6 +137,7 @@ class DBNetlist_TestClass < TestBase dc = RBA::GenericDeviceClass::new nl.add(dc) + assert_equal(dc.netlist.object_id, nl.object_id) dc.name = "DC" dc.description = "A device class" @@ -158,6 +159,8 @@ class DBNetlist_TestClass < TestBase assert_equal(d1.name, "D1") d2 = c.create_device(dc) + assert_equal(d2.device_class.id, dc.id) + assert_equal(d2.device_class.object_id, dc.object_id) # by virtue of Ruby-to-C++ object mapping d2.name = "D2" names = []