diff --git a/src/db/db/db.pro b/src/db/db/db.pro index 63b3c2fdc..8b10ea896 100644 --- a/src/db/db/db.pro +++ b/src/db/db/db.pro @@ -143,7 +143,8 @@ SOURCES = \ dbDeepRegion.cc \ dbHierNetworkProcessor.cc \ dbNetlistProperty.cc \ - gsiDeclDbNetlistProperty.cc + gsiDeclDbNetlistProperty.cc \ + dbNetlist.cc HEADERS = \ dbArray.h \ @@ -253,7 +254,8 @@ HEADERS = \ dbHierarchyBuilder.h \ dbLocalOperation.h \ dbHierProcessor.h \ - dbNetlistProperty.h + dbNetlistProperty.h \ + dbNetlist.h !equals(HAVE_QT, "0") { diff --git a/src/db/db/dbNetlist.cc b/src/db/db/dbNetlist.cc new file mode 100644 index 000000000..61b954c79 --- /dev/null +++ b/src/db/db/dbNetlist.cc @@ -0,0 +1,383 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#include "dbNetlist.h" + +namespace db +{ + +// -------------------------------------------------------------------------------- +// Pin class implementation + +Pin::Pin () +{ + // .. nothing yet .. +} + +Pin::Pin (Circuit *circuit, const std::string &name) + : m_circuit (circuit), m_name (name) +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------------------- +// Port class implementation + +Port::Port () +{ + // .. nothing yet .. +} + +Port::Port (Device *device, port_id_type port_id) + : m_device (device), m_port_id (port_id) +{ + // .. nothing yet .. +} + +const DevicePortDefinition * +Port::port_def () const +{ + const DeviceClass *dc = device_class (); + if (dc && m_port_id < dc->port_definitions ().size ()) { + return &dc->port_definitions ()[m_port_id]; + } else { + return 0; + } +} + +const DeviceClass * +Port::device_class () const +{ + const Device *device = m_device.get (); + return device ? device->device_class () : 0; +} + +// -------------------------------------------------------------------------------- +// Device class implementation + +Device::Device (DeviceClass *device_class) + : m_device_class (device_class) +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------------------- +// SubCircuit class implementation + +SubCircuit::SubCircuit () +{ + // .. nothing yet .. +} + +SubCircuit::SubCircuit (Circuit *circuit) + : m_circuit (circuit) +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------------------- +// NetPortRef class implementation + +NetPortRef::NetPortRef () +{ + // .. nothing yet .. +} + +NetPortRef::NetPortRef (Port *port) + : m_port (port) +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------------------- +// NetPinRef class implementation + +NetPinRef::NetPinRef () +{ + // .. nothing yet .. +} + +NetPinRef::NetPinRef (Pin *pin) + : m_pin (pin) +{ + // .. nothing yet .. +} + +NetPinRef::NetPinRef (Pin *pin, SubCircuit *circuit) + : m_pin (pin), m_subcircuit (circuit) +{ + // .. nothing yet .. +} + +// -------------------------------------------------------------------------------- +// Net class implementation + +Net::Net () +{ + // .. nothing yet .. +} + +Net::Net (const Net &other) +{ + operator= (other); +} + +Net &Net::operator= (const Net &other) +{ + if (this != &other) { + m_name = other.m_name; + m_pins = other.m_pins; + m_ports = other.m_ports; + } + return *this; +} + +void Net::clear () +{ + m_name.clear (); + m_ports.clear (); + m_pins.clear (); +} + +void Net::set_name (const std::string &name) +{ + m_name = name; +} + +void Net::add_pin (const NetPinRef &pin) +{ + m_pins.push_back (pin); +} + +void Net::add_port (const NetPortRef &port) +{ + m_ports.push_back (port); +} + +// -------------------------------------------------------------------------------- +// Circuit class implementation + +Circuit::Circuit () +{ + // .. nothing yet .. +} + +Circuit::Circuit (const Circuit &other) +{ + operator= (other); +} + +Circuit &Circuit::operator= (const Circuit &other) +{ + if (this != &other) { + m_name = other.m_name; + for (const_pin_iterator i = other.begin_pins (); i != other.end_pins (); ++i) { + add_pin (new Pin (*i)); + } + for (const_device_iterator i = other.begin_devices (); i != other.end_devices (); ++i) { + add_device (new Device (*i)); + } + for (const_net_iterator i = other.begin_nets (); i != other.end_nets (); ++i) { + add_net (new Net (*i)); + } + for (const_sub_circuit_iterator i = other.begin_sub_circuits (); i != other.end_sub_circuits (); ++i) { + add_sub_circuit (new SubCircuit (*i)); + } + } + return *this; +} + +void Circuit::clear () +{ + m_name.clear (); + m_pins.clear (); + m_devices.clear (); + m_nets.clear (); + m_sub_circuits.clear (); +} + +void Circuit::set_name (const std::string &name) +{ + m_name = name; +} + +void Circuit::set_cell_index (const db::cell_index_type ci) +{ + m_cell_index = ci; +} + +void Circuit::add_pin (Pin *pin) +{ + m_pins.push_back (pin); +} + +void Circuit::remove_pin (Pin *pin) +{ + m_pins.erase (pin); +} + +void Circuit::add_net (Net *net) +{ + m_nets.push_back (net); +} + +void Circuit::remove_net (Net *net) +{ + m_nets.erase (net); +} + +void Circuit::add_device (Device *device) +{ + m_devices.push_back (device); +} + +void Circuit::remove_device (Device *device) +{ + m_devices.erase (device); +} + +void Circuit::add_sub_circuit (SubCircuit *sub_circuit) +{ + m_sub_circuits.push_back (sub_circuit); +} + +void Circuit::remove_sub_circuit (SubCircuit *sub_circuit) +{ + m_sub_circuits.erase (sub_circuit); +} + +// -------------------------------------------------------------------------------- +// DeviceClass class implementation + +DeviceClass::DeviceClass () +{ + // .. nothing yet .. +} + +DeviceClass::DeviceClass (const DeviceClass & /*other*/) +{ + // .. nothing yet .. +} + +DeviceClass &DeviceClass::operator= (const DeviceClass & /*other*/) +{ + // .. nothing yet .. + return *this; +} + +const std::string &DeviceClass::name () const +{ + static std::string no_name; + return no_name; +} + +const std::string &DeviceClass::description () const +{ + static std::string no_description; + return no_description; +} + +const std::vector &DeviceClass::port_definitions () const +{ + static std::vector no_defs; + return no_defs; +} + +// -------------------------------------------------------------------------------- +// GenericDeviceClass class implementation + +GenericDeviceClass::GenericDeviceClass () +{ + // .. nothing yet .. +} + +GenericDeviceClass::GenericDeviceClass (const GenericDeviceClass &other) +{ + operator= (other); +} + +GenericDeviceClass &GenericDeviceClass::operator= (const GenericDeviceClass &other) +{ + if (this != &other) { + m_port_definitions = other.m_port_definitions; + m_name = other.m_name; + m_description = other.m_description; + } + return *this; +} + +// -------------------------------------------------------------------------------- +// Netlist class implementation + +Netlist::Netlist () +{ + // .. nothing yet .. +} + +Netlist::Netlist (const Netlist &other) +{ + operator= (other); +} + +Netlist &Netlist::operator= (const Netlist &other) +{ + if (this != &other) { + for (const_circuit_iterator i = other.begin_circuits (); i != other.end_circuits (); ++i) { + add_circuit (new Circuit (*i)); + } + + m_device_classes.clear (); + for (const_device_class_iterator dc = other.begin_device_classes (); dc != other.end_device_classes (); ++dc) { + m_device_classes.push_back (dc->clone ()); + } + } + + return *this; +} + +void Netlist::clear () +{ + m_device_classes.clear (); + m_circuits.clear (); +} + +void Netlist::add_circuit (Circuit *circuit) +{ + m_circuits.push_back (circuit); +} + +void Netlist::remove_circuit (Circuit *circuit) +{ + m_circuits.erase (circuit); +} + +void Netlist::add_device_class (DeviceClass *device_class) +{ + m_device_classes.push_back (device_class); +} + +void Netlist::remove_device_class (DeviceClass *device_class) +{ + m_device_classes.erase (device_class); +} + +} diff --git a/src/db/db/dbNetlist.h b/src/db/db/dbNetlist.h new file mode 100644 index 000000000..958a91263 --- /dev/null +++ b/src/db/db/dbNetlist.h @@ -0,0 +1,1022 @@ + +/* + + KLayout Layout Viewer + Copyright (C) 2006-2018 Matthias Koefferlein + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +*/ + +#ifndef _HDR_dbNetlist +#define _HDR_dbNetlist + +#include "dbCommon.h" +#include "dbTypes.h" +#include "tlObjectCollection.h" + +#include + +namespace db +{ + +class Circuit; +class Device; +class DeviceClass; +class DevicePortDefinition; + +/** + * @brief The definition of a pin of a circuit + * + * A pin is some place other nets can connect to a circuit. + */ +class DB_PUBLIC Pin + : public tl::Object +{ +public: + /** + * @brief Default constructor + */ + Pin (); + + /** + * @brief Creates a port of the given circuit with the given name. + */ + Pin (Circuit *circuit, const std::string &name); + + /** + * @brief Gets the circuit reference + */ + const Circuit *circuit () const + { + return m_circuit.get (); + } + + /** + * @brief Gets the name of the pin + */ + const std::string &name () const + { + return m_name; + } + +private: + tl::weak_ptr m_circuit; + std::string m_name; +}; + +/** + * @brief The definition of a port of a device + * + * A port is a connection a device can make. This is the port + * of an actual device. It corresponds to a device class by + * the port ID which is essentially the index of the port + * in the device classes' port list. + */ +class DB_PUBLIC Port + : public tl::Object +{ +public: + typedef size_t port_id_type; + + /** + * @brief Default constructor + */ + Port (); + + /** + * @brief Creates a port of the given device and port ID + */ + Port (Device *device, port_id_type port_id); + + /** + * @brief Gets the device reference + */ + const Device *device () const + { + return m_device.get (); + } + + /** + * @brief Gets the port id + */ + port_id_type port_id () const + { + return m_port_id; + } + + /** + * @brief Gets the port definition + * + * Returns 0 if the port is not a valid port reference. + */ + const DevicePortDefinition *port_def () const; + + /** + * @brief Returns the device class + */ + const DeviceClass *device_class () const; + +private: + tl::weak_ptr m_device; + port_id_type m_port_id; +}; + +/** + * @brief An actual device + * + * This class represents the incarnation of a specific device. + * The device has a class which specifies a type. This class + * is intended for subclassing. + * A specific device subclass is supposed to correspond to + * a specific device class. + */ +class DB_PUBLIC Device + : public tl::Object +{ +public: + /** + * @brief The constructor + */ + Device (DeviceClass *device_class); + + /** + * @brief Gets the device class + */ + const DeviceClass *device_class () const + { + return m_device_class.get (); + } + +private: + tl::weak_ptr m_device_class; +}; + +/** + * @brief A subcircuit of a circuit + * + * This class essentially is a reference to another circuit + */ +class DB_PUBLIC SubCircuit + : public tl::Object +{ +public: + /** + * @brief Default constructor + */ + SubCircuit (); + + /** + * @brief Creates a subcircuit reference to the given circuit + */ + SubCircuit (Circuit *circuit); + + /** + * @brief Gets the circuit the reference points to (const version) + */ + const Circuit *circuit () const + { + return m_circuit.get (); + } + + /** + * @brief Gets the circuit the reference points to (non-const version) + */ + Circuit *circuit () + { + return m_circuit.get (); + } + + +private: + tl::weak_ptr m_circuit; +}; + +/** + * @brief A reference to a port of a device + * + * A port must always refer to a device inside the current circuit. + */ +class DB_PUBLIC NetPortRef +{ + /** + * @brief Default constructor + */ + NetPortRef (); + + /** + * @brief Creates a pin reference to the given pin of the current circuit + */ + NetPortRef (Port *port); + + /** + * @brief Gets the port reference + */ + Port *port () + { + return m_port.get (); + } + + /** + * @brief Gets the port reference (const version) + */ + const Port *port () const + { + return m_port.get (); + } + +private: + tl::weak_ptr m_port; +}; + +/** + * @brief A reference to a pin inside a net + * + * A pin belongs to a subcircuit. + * If the subcircuit reference is 0, the pin is a pin of the current circuit + * (upward pin). + */ +class DB_PUBLIC NetPinRef +{ + /** + * @brief Default constructor + */ + NetPinRef (); + + /** + * @brief Creates a pin reference to the given pin of the current circuit + */ + NetPinRef (Pin *pin); + + /** + * @brief Creates a pin reference to the given pin of the given subcircuit + */ + NetPinRef (Pin *pin, SubCircuit *circuit); + + /** + * @brief Gets the pin reference + */ + Pin *pin () + { + return m_pin.get (); + } + + /** + * @brief Gets the pin reference (const version) + */ + const Pin *pin () const + { + return m_pin.get (); + } + + /** + * @brief Gets the subcircuit reference + */ + SubCircuit *subcircuit () + { + return m_subcircuit.get (); + } + + /** + * @brief Gets the subcircuit reference (const version) + */ + const SubCircuit *subcircuit () const + { + return m_subcircuit.get (); + } + +private: + tl::weak_ptr m_pin; + tl::weak_ptr m_subcircuit; +}; + +/** + * @brief A net + * + * A net connects ports of devices and pins or circuits + */ +class DB_PUBLIC Net + : public tl::Object +{ +public: + typedef std::list port_list; + typedef port_list::const_iterator const_port_iterator; + typedef std::list pin_list; + typedef pin_list::const_iterator const_pin_iterator; + + /** + * @brief Constructor + * + * Creates an empty circuit. + */ + Net (); + + /** + * @brief Copy constructor + */ + Net (const Net &other); + + /** + * @brief Assignment + */ + Net &operator= (const Net &other); + + /** + * @brief Clears the circuit + */ + void clear (); + + /** + * @brief Sets the name of the circuit + */ + void set_name (const std::string &name); + + /** + * @brief Gets the name of the circuit + */ + const std::string &name () const + { + return m_name; + } + + /** + * @brief Adds a pin to this net + */ + void add_pin (const NetPinRef &pin); + + /** + * @brief Begin iterator for the pins of the net (const version) + */ + const_pin_iterator begin_pins () const + { + return m_pins.begin (); + } + + /** + * @brief End iterator for the pins of the net (const version) + */ + const_pin_iterator end_pins () const + { + return m_pins.end (); + } + + /** + * @brief Adds a port to this net + */ + void add_port (const NetPortRef &port); + + /** + * @brief Begin iterator for the ports of the net (const version) + */ + const_port_iterator begin_ports () const + { + return m_ports.begin (); + } + + /** + * @brief End iterator for the ports of the net (const version) + */ + const_port_iterator end_ports () const + { + return m_ports.end (); + } + +private: + port_list m_ports; + pin_list m_pins; + std::string m_name; +}; + +/** + * @brief A circuit + * + * A circuit is a list of nets, of subcircuit references and actual + * devices. + */ +class DB_PUBLIC Circuit + : public tl::Object +{ +public: + typedef tl::shared_collection pin_list; + typedef pin_list::const_iterator const_pin_iterator; + typedef pin_list::iterator pin_iterator; + typedef tl::shared_collection device_list; + typedef device_list::const_iterator const_device_iterator; + typedef device_list::iterator device_iterator; + typedef tl::shared_collection net_list; + typedef net_list::const_iterator const_net_iterator; + typedef net_list::iterator net_iterator; + typedef tl::shared_collection sub_circuit_list; + typedef sub_circuit_list::const_iterator const_sub_circuit_iterator; + typedef sub_circuit_list::iterator sub_circuit_iterator; + + /** + * @brief Constructor + * + * Creates an empty circuit. + */ + Circuit (); + + /** + * @brief Copy constructor + */ + Circuit (const Circuit &other); + + /** + * @brief Assignment + */ + Circuit &operator= (const Circuit &other); + + /** + * @brief Clears the circuit + */ + void clear (); + + /** + * @brief Sets the name of the circuit + */ + void set_name (const std::string &name); + + /** + * @brief Gets the name of the circuit + */ + const std::string &name () const + { + return m_name; + } + + /** + * @brief Sets the layout cell reference for this circuit + * + * The layout cell reference links a circuit to a layout cell. + */ + void set_cell_index (const db::cell_index_type ci); + + /** + * @brief Gets the layout cell index + */ + db::cell_index_type cell_index () const + { + return m_cell_index; + } + + /** + * @brief Adds a pin to this circuit + * + * The circuit takes over ownership of the object. + */ + void add_pin (Pin *pin); + + /** + * @brief Deletes a pin from the circuit + */ + void remove_pin (Pin *pin); + + /** + * @brief Begin iterator for the pins of the circuit (non-const version) + */ + pin_iterator begin_pins () + { + return m_pins.begin (); + } + + /** + * @brief End iterator for the pins of the circuit (non-const version) + */ + pin_iterator end_pins () + { + return m_pins.end (); + } + + /** + * @brief Begin iterator for the pins of the circuit (const version) + */ + const_pin_iterator begin_pins () const + { + return m_pins.begin (); + } + + /** + * @brief End iterator for the pins of the circuit (const version) + */ + const_pin_iterator end_pins () const + { + return m_pins.end (); + } + + /** + * @brief Adds a net to this circuit + * + * The circuit takes over ownership of the object. + */ + void add_net (Net *net); + + /** + * @brief Deletes a net from the circuit + */ + void remove_net (Net *net); + + /** + * @brief Begin iterator for the nets of the circuit (non-const version) + */ + net_iterator begin_nets () + { + return m_nets.begin (); + } + + /** + * @brief End iterator for the nets of the circuit (non-const version) + */ + net_iterator end_nets () + { + return m_nets.end (); + } + + /** + * @brief Begin iterator for the nets of the circuit (const version) + */ + const_net_iterator begin_nets () const + { + return m_nets.begin (); + } + + /** + * @brief End iterator for the nets of the circuit (const version) + */ + const_net_iterator end_nets () const + { + return m_nets.end (); + } + + /** + * @brief Adds a device to this circuit + * + * The circuit takes over ownership of the object. + */ + void add_device (Device *device); + + /** + * @brief Deletes a device from the circuit + */ + void remove_device (Device *device); + + /** + * @brief Begin iterator for the devices of the circuit (non-const version) + */ + device_iterator begin_devices () + { + return m_devices.begin (); + } + + /** + * @brief End iterator for the devices of the circuit (non-const version) + */ + device_iterator end_devices () + { + return m_devices.end (); + } + + /** + * @brief Begin iterator for the devices of the circuit (const version) + */ + const_device_iterator begin_devices () const + { + return m_devices.begin (); + } + + /** + * @brief End iterator for the devices of the circuit (const version) + */ + const_device_iterator end_devices () const + { + return m_devices.end (); + } + + /** + * @brief Adds a subcircuit to this circuit + * + * The circuit takes over ownership of the object. + */ + void add_sub_circuit (SubCircuit *sub_circuit); + + /** + * @brief Deletes a subcircuit from the circuit + */ + void remove_sub_circuit (SubCircuit *sub_circuit); + + /** + * @brief Begin iterator for the subcircuits of the circuit (non-const version) + */ + sub_circuit_iterator begin_sub_circuits () + { + return m_sub_circuits.begin (); + } + + /** + * @brief End iterator for the subcircuits of the circuit (non-const version) + */ + sub_circuit_iterator end_sub_circuits () + { + return m_sub_circuits.end (); + } + + /** + * @brief Begin iterator for the subcircuits of the circuit (const version) + */ + const_sub_circuit_iterator begin_sub_circuits () const + { + return m_sub_circuits.begin (); + } + + /** + * @brief End iterator for the subcircuits of the circuit (const version) + */ + const_sub_circuit_iterator end_sub_circuits () const + { + return m_sub_circuits.end (); + } + +private: + std::string m_name; + db::cell_index_type m_cell_index; + net_list m_nets; + pin_list m_pins; + device_list m_devices; + sub_circuit_list m_sub_circuits; +}; + +/** + * @brief A device port definition + */ +class DB_PUBLIC DevicePortDefinition +{ +public: + /** + * @brief Creates an empty device port definition + */ + DevicePortDefinition () + : m_name (), m_description () + { + // .. nothing yet .. + } + + /** + * @brief Creates a device port definition with the given name and description + */ + DevicePortDefinition (const std::string &name, const std::string &description) + : m_name (name), m_description (description) + { + // .. nothing yet .. + } + + /** + * @brief Gets the port name + */ + const std::string &name () const + { + return m_name; + } + + /** + * @brief Sets the port name + */ + void set_name (const std::string &n) + { + m_name = n; + } + + /** + * @brief Gets the port description + */ + const std::string &description () const + { + return m_description; + } + + /** + * @brief Sets the port description + */ + void set_description (const std::string &d) + { + m_description = d; + } + +private: + std::string m_name, m_description; +}; + +/** + * @brief A device class + * + * A device class describes a type of device. + */ +class DB_PUBLIC DeviceClass + : public tl::Object +{ +public: + /** + * @brief Constructor + * + * Creates an empty circuit. + */ + DeviceClass (); + + /** + * @brief Copy constructor + * NOTE: do not use this copy constructor as the device class + * is intended to subclassing. + */ + DeviceClass (const DeviceClass &other); + + /** + * @brief Assignment + * NOTE: do not use this copy constructor as the device class + * is intended to subclassing. + */ + DeviceClass &operator= (const DeviceClass &other); + + /** + * @brief Clears the circuit + */ + virtual DeviceClass *clone () const + { + return new DeviceClass (*this); + } + + /** + * @brief Gets the name of the device class + * + * The name is a formal name which identifies the class. + */ + virtual const std::string &name () const; + + /** + * @brief Gets the description text for the device class + * + * The description text is a human-readable text that + * identifies the device class. + */ + virtual const std::string &description () const; + + /** + * @brief Gets the port definitions + * + * The port definitions indicate what ports the device offers. + * The number of ports is constant per class. The index of the port + * is used as an ID of the port, hence the order must be static. + */ + virtual const std::vector &port_definitions () const; +}; + +/** + * @brief A generic device class + * + * The generic device class is a push version of the DeviceClassBase + */ +class DB_PUBLIC GenericDeviceClass + : public DeviceClass +{ +public: + /** + * @brief Constructor + * + * Creates an empty circuit. + */ + GenericDeviceClass (); + + /** + * @brief Copy constructor + */ + GenericDeviceClass (const GenericDeviceClass &other); + + /** + * @brief Assignment + */ + GenericDeviceClass &operator= (const GenericDeviceClass &other); + + /** + * @brief Clears the circuit + */ + virtual DeviceClass *clone () const + { + return new GenericDeviceClass (*this); + } + + /** + * @brief Gets the name of the device class + * + * The name is a formal name which identifies the class. + */ + virtual const std::string &name () const + { + return m_name; + } + + /** + * @brief Sets the device name + */ + void set_name (const std::string &n) + { + m_name = n; + } + + /** + * @brief Gets the description text for the device class + * + * The description text is a human-readable text that + * identifies the device class. + */ + virtual const std::string &description () const + { + return m_description; + } + + /** + * @brief Sets the description text + */ + void set_description (const std::string &d) + { + m_description = d; + } + + /** + * @brief Gets the port definitions + * + * The port definitions indicate what ports the device offers. + * The number of ports is constant per class. The index of the port + * is used as an ID of the port, hence the order must be static. + */ + virtual const std::vector &port_definitions () const + { + return m_port_definitions; + } + + /** + * @brief Adds a port definition + */ + void add_port_definition (const DevicePortDefinition &pd) + { + m_port_definitions.push_back (pd); + } + + /** + * @brief Clears the port definition + */ + void clear_port_definitions () + { + m_port_definitions.clear (); + } + +private: + std::vector m_port_definitions; + std::string m_name, m_description; +}; + +/** + * @brief The netlist class + * + * This class represents a hierarchical netlist. + * The main components of a netlist are circuits and device classes. + * The circuits represent cells, the device classes type of devices. + */ +class DB_PUBLIC Netlist + : public tl::Object +{ +public: + typedef tl::shared_collection circuit_list; + typedef circuit_list::const_iterator const_circuit_iterator; + typedef circuit_list::iterator circuit_iterator; + typedef tl::shared_collection device_class_list; + typedef device_class_list::const_iterator const_device_class_iterator; + typedef device_class_list::iterator device_class_iterator; + + /** + * @brief Constructor + * + * This constructor creates an empty hierarchical netlist + */ + Netlist (); + + /** + * @brief Copy constructor + */ + Netlist (const Netlist &other); + + /** + * @brief Assignment + */ + Netlist &operator= (const Netlist &other); + + /** + * @brief Clears the netlist + */ + void clear (); + + /** + * @brief Adds a circuit to this netlist + * + * The netlist takes over ownership of the object. + */ + void add_circuit (Circuit *circuit); + + /** + * @brief Deletes a circuit from the netlist + */ + void remove_circuit (Circuit *circuit); + + /** + * @brief Begin iterator for the circuits of the netlist (non-const version) + */ + circuit_iterator begin_circuits () + { + return m_circuits.begin (); + } + + /** + * @brief End iterator for the circuits of the netlist (non-const version) + */ + circuit_iterator end_circuits () + { + return m_circuits.end (); + } + + /** + * @brief Begin iterator for the circuits of the netlist (const version) + */ + const_circuit_iterator begin_circuits () const + { + return m_circuits.begin (); + } + + /** + * @brief End iterator for the circuits of the netlist (const version) + */ + const_circuit_iterator end_circuits () const + { + return m_circuits.end (); + } + + /** + * @brief Adds a device class to this netlist + * + * The netlist takes over ownership of the object. + */ + void add_device_class (DeviceClass *device_class); + + /** + * @brief Deletes a device class from the netlist + */ + void remove_device_class (DeviceClass *device_class); + + /** + * @brief Begin iterator for the device classes of the netlist (non-const version) + */ + device_class_iterator begin_device_classes () + { + return m_device_classes.begin (); + } + + /** + * @brief End iterator for the device classes of the netlist (non-const version) + */ + device_class_iterator end_device_classes () + { + return m_device_classes.end (); + } + + /** + * @brief Begin iterator for the device classes of the netlist (const version) + */ + const_device_class_iterator begin_device_classes () const + { + return m_device_classes.begin (); + } + + /** + * @brief End iterator for the device classes of the netlist (const version) + */ + const_device_class_iterator end_device_classes () const + { + return m_device_classes.end (); + } + +private: + circuit_list m_circuits; + device_class_list m_device_classes; +}; + +} + +#endif diff --git a/src/db/db/dbNetlistProperty.h b/src/db/db/dbNetlistProperty.h index efb41136a..76c47bd40 100644 --- a/src/db/db/dbNetlistProperty.h +++ b/src/db/db/dbNetlistProperty.h @@ -20,7 +20,11 @@ */ +#ifndef _HDR_dbNetlistProperty +#define _HDR_dbNetlistProperty + #include "dbCommon.h" +#include "dbNetlist.h" #include "tlVariant.h" #include @@ -232,4 +236,51 @@ private: std::string m_name; }; +#if 0 // @@@ +/** + * @brief A reference to an actual port + */ +class DB_PUBLIC DevicePortRef + : public db::NetlistProperty +{ +public: + DevicePortRef (db::NetPortRef *port); + + // ... + +private: + tl::weak_ptr mp_port; +}; + +/** + * @brief An abstrace reference to a port + * + * Abstract references are created when turning a string back into a port. + * Abstract references can be turned into actual port references using + * "to_actual_ref". + */ +class DB_PUBLIC DevicePortAbstractRef + : public db::NetlistProperty +{ +public: + DevicePortAbstractRef (const std::string &device_name, const std::string &port_name); + + // ... + + /** + * @brief Turns an abstract reference into an actual one + * + * The returned object is either 0, if the translation cannot be done or + * and new'd NetPortRef object. It's the responsibility of the caller + * to delete this object when it's no longer used. + */ + NetPortRef *to_actual_ref (const db::Netlist *netlist) const; + +private: + std::string m_device_name, m_port_name; +}; +#endif + } + +#endif