mirror of https://github.com/KLayout/klayout.git
Upward references for db::Net and db::Circuit.
This commit is contained in:
parent
83a38037e5
commit
654afa3ec2
|
|
@ -62,8 +62,8 @@ SubCircuit::SubCircuit ()
|
|||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
SubCircuit::SubCircuit (Circuit *circuit)
|
||||
: m_circuit (circuit)
|
||||
SubCircuit::SubCircuit (Circuit *circuit, const std::string &name)
|
||||
: m_circuit (circuit), m_name (name)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
|
@ -145,13 +145,13 @@ const Pin *NetPinRef::pin (const db::Circuit *c) const
|
|||
// Net class implementation
|
||||
|
||||
Net::Net ()
|
||||
: m_cluster_id (0)
|
||||
: m_cluster_id (0), mp_circuit (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
Net::Net (const Net &other)
|
||||
: m_cluster_id (0)
|
||||
: m_cluster_id (0), mp_circuit (0)
|
||||
{
|
||||
operator= (other);
|
||||
}
|
||||
|
|
@ -215,15 +215,22 @@ void Net::translate_subcircuits (const std::map<const SubCircuit *, SubCircuit *
|
|||
}
|
||||
}
|
||||
|
||||
void Net::set_circuit (Circuit *circuit)
|
||||
{
|
||||
mp_circuit = circuit;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------------
|
||||
// Circuit class implementation
|
||||
|
||||
Circuit::Circuit ()
|
||||
: mp_netlist (0)
|
||||
{
|
||||
// .. nothing yet ..
|
||||
}
|
||||
|
||||
Circuit::Circuit (const Circuit &other)
|
||||
: mp_netlist (0)
|
||||
{
|
||||
operator= (other);
|
||||
}
|
||||
|
|
@ -263,6 +270,11 @@ Circuit &Circuit::operator= (const Circuit &other)
|
|||
return *this;
|
||||
}
|
||||
|
||||
void Circuit::set_netlist (Netlist *netlist)
|
||||
{
|
||||
mp_netlist = netlist;
|
||||
}
|
||||
|
||||
const Pin *Circuit::pin_by_id (size_t id) const
|
||||
{
|
||||
if (id >= m_pins.size ()) {
|
||||
|
|
@ -300,6 +312,7 @@ void Circuit::add_pin (const Pin &pin)
|
|||
void Circuit::add_net (Net *net)
|
||||
{
|
||||
m_nets.push_back (net);
|
||||
net->set_circuit (this);
|
||||
}
|
||||
|
||||
void Circuit::remove_net (Net *net)
|
||||
|
|
@ -471,6 +484,7 @@ void Netlist::clear ()
|
|||
void Netlist::add_circuit (Circuit *circuit)
|
||||
{
|
||||
m_circuits.push_back (circuit);
|
||||
circuit->set_netlist (this);
|
||||
}
|
||||
|
||||
void Netlist::remove_circuit (Circuit *circuit)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Circuit;
|
|||
class Device;
|
||||
class DeviceClass;
|
||||
class DevicePortDefinition;
|
||||
|
||||
class Netlist;
|
||||
/**
|
||||
* @brief The definition of a pin of a circuit
|
||||
*
|
||||
|
|
@ -115,14 +115,6 @@ public:
|
|||
return m_device_class.get ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the device class
|
||||
*/
|
||||
void set_device_class (DeviceClass *cls)
|
||||
{
|
||||
m_device_class.reset (cls);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the name
|
||||
*/
|
||||
|
|
@ -137,8 +129,18 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
friend class Circuit;
|
||||
|
||||
tl::weak_ptr<DeviceClass> m_device_class;
|
||||
std::string m_name;
|
||||
|
||||
/**
|
||||
* @brief Sets the device class
|
||||
*/
|
||||
void set_device_class (DeviceClass *dc)
|
||||
{
|
||||
m_device_class.reset (dc);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -158,7 +160,7 @@ public:
|
|||
/**
|
||||
* @brief Creates a subcircuit reference to the given circuit
|
||||
*/
|
||||
SubCircuit (Circuit *circuit);
|
||||
SubCircuit (Circuit *circuit, const std::string &name = std::string ());
|
||||
|
||||
/**
|
||||
* @brief Gets the circuit the reference points to (const version)
|
||||
|
|
@ -176,14 +178,6 @@ public:
|
|||
return m_circuit.get ();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the circuit reference
|
||||
*/
|
||||
void set_circuit (Circuit *c)
|
||||
{
|
||||
m_circuit.reset (c);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Sets the name of the subcircuit
|
||||
*
|
||||
|
|
@ -216,11 +210,20 @@ public:
|
|||
return m_trans;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
friend class Circuit;
|
||||
|
||||
tl::weak_ptr<Circuit> m_circuit;
|
||||
std::string m_name;
|
||||
db::DCplxTrans m_trans;
|
||||
|
||||
/**
|
||||
* @brief Sets the circuit reference
|
||||
*/
|
||||
void set_circuit (Circuit *c)
|
||||
{
|
||||
m_circuit.reset (c);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -391,6 +394,24 @@ public:
|
|||
*/
|
||||
Net &operator= (const Net &other);
|
||||
|
||||
/**
|
||||
* @brief Gets the circuit the net lives in
|
||||
* This pointer is 0 if the net is not part of a circuit.
|
||||
*/
|
||||
Circuit *circuit ()
|
||||
{
|
||||
return mp_circuit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the circuit the net lives in (const version)
|
||||
* This pointer is 0 if the net is not part of a circuit.
|
||||
*/
|
||||
const Circuit *circuit () const
|
||||
{
|
||||
return mp_circuit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the circuit
|
||||
*/
|
||||
|
|
@ -474,9 +495,11 @@ private:
|
|||
pin_list m_pins;
|
||||
std::string m_name;
|
||||
size_t m_cluster_id;
|
||||
Circuit *mp_circuit;
|
||||
|
||||
void translate_devices (const std::map<const Device *, Device *> &map);
|
||||
void translate_subcircuits (const std::map<const SubCircuit *, SubCircuit *> &map);
|
||||
void set_circuit (Circuit *circuit);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -519,6 +542,24 @@ public:
|
|||
*/
|
||||
Circuit &operator= (const Circuit &other);
|
||||
|
||||
/**
|
||||
* @brief Gets the netlist the circuit lives in
|
||||
* This pointer is 0 if the circuit is not part of a netlist.
|
||||
*/
|
||||
Netlist *netlist ()
|
||||
{
|
||||
return mp_netlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Gets the netlist the circuit lives in (const version)
|
||||
* This pointer is 0 if the circuit is not part of a netlist.
|
||||
*/
|
||||
const Netlist *netlist () const
|
||||
{
|
||||
return mp_netlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Clears the circuit
|
||||
*/
|
||||
|
|
@ -742,9 +783,11 @@ private:
|
|||
pin_list m_pins;
|
||||
device_list m_devices;
|
||||
sub_circuit_list m_sub_circuits;
|
||||
Netlist *mp_netlist;
|
||||
|
||||
void translate_circuits (const std::map<const Circuit *, Circuit *> &map);
|
||||
void translate_device_classes (const std::map<const db::DeviceClass *, db::DeviceClass *> &map);
|
||||
void set_netlist (Netlist *netlist);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -186,9 +186,11 @@ TEST(4_CircuitDevices)
|
|||
c->add_device (d2b);
|
||||
|
||||
db::Net *n1 = new db::Net ();
|
||||
EXPECT_EQ (n1->circuit (), 0);
|
||||
c->add_net (n1);
|
||||
n1->add_port (db::NetPortRef (d1, 0));
|
||||
n1->add_port (db::NetPortRef (d2a, 0));
|
||||
EXPECT_EQ (n1->circuit (), c.get ());
|
||||
|
||||
db::Net *n2 = new db::Net ();
|
||||
c->add_net (n2);
|
||||
|
|
@ -209,6 +211,7 @@ TEST(4_CircuitDevices)
|
|||
|
||||
db::Circuit cc = *c;
|
||||
c.reset (0);
|
||||
EXPECT_EQ (cc.begin_nets ()->circuit (), &cc);
|
||||
|
||||
EXPECT_EQ (nets2string (cc),
|
||||
"d1:S,d2a:A\n"
|
||||
|
|
@ -238,10 +241,12 @@ TEST(4_NetlistSubcircuits)
|
|||
nl->add_device_class (dc);
|
||||
|
||||
db::Circuit *c1 = new db::Circuit ();
|
||||
EXPECT_EQ (c1->netlist (), 0);
|
||||
c1->set_name ("c1");
|
||||
c1->add_pin (db::Pin ("c1p1"));
|
||||
c1->add_pin (db::Pin ("c1p2"));
|
||||
nl->add_circuit (c1);
|
||||
EXPECT_EQ (c1->netlist (), nl.get ());
|
||||
|
||||
db::Circuit *c2 = new db::Circuit ();
|
||||
c2->set_name ("c2");
|
||||
|
|
@ -296,6 +301,8 @@ TEST(4_NetlistSubcircuits)
|
|||
db::Netlist nl2 = *nl;
|
||||
nl.reset (0);
|
||||
|
||||
EXPECT_EQ (nl2.begin_circuits ()->netlist (), &nl2);
|
||||
|
||||
EXPECT_EQ (netlist2string (nl2),
|
||||
"[c1]\n"
|
||||
"+c1p1,c2:c2p1\n"
|
||||
|
|
|
|||
Loading…
Reference in New Issue