Spice writer delegate fix

- Changed to const & objects in the Spice writer delegate
  to non-const & for Ruby/Python reimplementation (as const/non-const
  ambiguity is an issue for Ruby/Python we cannot efficiently
  work with const refs)
- Updated test data because the previous implementation wasn't
  using refs but rather copies of device and device class
  objects.
This commit is contained in:
Matthias Koefferlein 2019-01-31 22:23:58 +01:00
parent 30e26c4f96
commit 57305977a4
2 changed files with 37 additions and 18 deletions

View File

@ -1038,25 +1038,44 @@ public:
} }
} }
virtual void write_device_intro (const db::DeviceClass &cls) const virtual void write_device_intro (const db::DeviceClass &ccls) const
{
reimpl_write_device_intro (const_cast<db::DeviceClass &> (ccls));
}
// NOTE: we pass non-const refs to Ruby/Python - everthing else is a bit of a nightmare.
// Still that's not really clean. Just say, the implementation promises not to change the objects.
void reimpl_write_device_intro (db::DeviceClass &cls) const
{ {
if (cb_write_device_intro.can_issue ()) { if (cb_write_device_intro.can_issue ()) {
cb_write_device_intro.issue<db::NetlistSpiceWriterDelegate, const db::DeviceClass &> (&db::NetlistSpiceWriterDelegate::write_device_intro, cls); cb_write_device_intro.issue<NetlistSpiceWriterDelegateImpl, db::DeviceClass &> (&NetlistSpiceWriterDelegateImpl::org_write_device_intro, const_cast<db::DeviceClass &> (cls));
} else { } else {
db::NetlistSpiceWriterDelegate::write_device_intro (cls); org_write_device_intro (cls);
} }
} }
virtual void write_device (const db::Device &dev) const void org_write_device_intro (db::DeviceClass &cls) const
{
db::NetlistSpiceWriterDelegate::write_device_intro (cls);
}
virtual void write_device (const db::Device &cdev) const
{
reimpl_write_device (const_cast<db::Device &> (cdev));
}
// NOTE: we pass non-const refs to Ruby/Python - everthing else is a bit of a nightmare.
// Still that's not really clean. Just say, the implementation promises not to change the objects.
void reimpl_write_device (db::Device &dev) const
{ {
if (cb_write_device.can_issue ()) { if (cb_write_device.can_issue ()) {
cb_write_device.issue<db::NetlistSpiceWriterDelegate, const db::Device &> (&db::NetlistSpiceWriterDelegate::write_device, dev); cb_write_device.issue<NetlistSpiceWriterDelegateImpl, db::Device &> (&NetlistSpiceWriterDelegateImpl::org_write_device, dev);
} else { } else {
org_write_device (dev); org_write_device (dev);
} }
} }
virtual void org_write_device (const db::Device &dev) const void org_write_device (db::Device &dev) const
{ {
db::NetlistSpiceWriterDelegate::write_device (dev); db::NetlistSpiceWriterDelegate::write_device (dev);
} }
@ -1076,11 +1095,11 @@ Class<NetlistSpiceWriterDelegateImpl> db_NetlistSpiceWriterDelegate ("db", "Netl
"@brief Writes the text at the beginning of the SPICE netlist\n" "@brief Writes the text at the beginning of the SPICE netlist\n"
"Reimplement this method to insert your own text at the beginning of the file" "Reimplement this method to insert your own text at the beginning of the file"
) + ) +
gsi::callback ("write_device_intro", &NetlistSpiceWriterDelegateImpl::write_device_intro, &NetlistSpiceWriterDelegateImpl::cb_write_device_intro, gsi::arg ("device_class"), gsi::callback ("write_device_intro", &NetlistSpiceWriterDelegateImpl::reimpl_write_device_intro, &NetlistSpiceWriterDelegateImpl::cb_write_device_intro, gsi::arg ("device_class"),
"@brief Inserts a text for the given device class\n" "@brief Inserts a text for the given device class\n"
"Reimplement this method to insert your own text at the beginning of the file for the given device class" "Reimplement this method to insert your own text at the beginning of the file for the given device class"
) + ) +
gsi::callback ("write_device", &NetlistSpiceWriterDelegateImpl::write_device, &NetlistSpiceWriterDelegateImpl::cb_write_device, gsi::arg ("device"), gsi::callback ("write_device", &NetlistSpiceWriterDelegateImpl::reimpl_write_device, &NetlistSpiceWriterDelegateImpl::cb_write_device, gsi::arg ("device"),
"@brief Inserts a text for the given device\n" "@brief Inserts a text for the given device\n"
"Reimplement this method to write the given device in the desired way" "Reimplement this method to write the given device in the desired way"
) + ) +

View File

@ -15,15 +15,15 @@
* net 2 n2 * net 2 n2
* net 3 n3 * net 3 n3
* device instance $1 0,0 RCLS * device instance $1 0,0 RCLS
* Before device $0 * Before device $1
* Terminal #1: 0 * Terminal #1: 1
* Terminal #2: 0 * Terminal #2: 3
R$0 0 0 1.7 R$1 1 3 1.7
* After device $0 * After device $1
* device instance $2 0,0 RCLS * device instance $2 0,0 RCLS
* Before device $0 * Before device $2
* Terminal #1: 0 * Terminal #1: 3
* Terminal #2: 0 * Terminal #2: 2
R$0 0 0 4.2e-05 R$2 3 2 4.2e-05
* After device $0 * After device $2
.ENDS C1 .ENDS C1