mirror of https://github.com/KLayout/klayout.git
WIP: generlizing parameter values for spice reader - can be strings too
This commit is contained in:
parent
51c4b7ed28
commit
18f2b57c3d
|
|
@ -181,34 +181,6 @@ SpiceReaderStream::set_stream (tl::InputStream *stream)
|
|||
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
|
||||
// @@@ remove
|
||||
struct ParametersLessFunction
|
||||
{
|
||||
typedef std::map<std::string, double> parameters_type;
|
||||
|
||||
bool operator() (const parameters_type &a, const parameters_type &b) const
|
||||
{
|
||||
if (a.size () != b.size ()) {
|
||||
return a.size () < b.size ();
|
||||
}
|
||||
|
||||
auto ia = a.begin ();
|
||||
auto ib = b.begin ();
|
||||
while (ia != a.end ()) {
|
||||
if (ia->first != ib->first) {
|
||||
return ia->first < ib->first;
|
||||
}
|
||||
double avg = 0.5 * fabs (ia->second + ib->second);
|
||||
if (fabs (ia->second - ib->second) > avg * 1e-13) {
|
||||
return ia->second < ib->second;
|
||||
}
|
||||
++ia, ++ib;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
struct SpiceCard
|
||||
{
|
||||
SpiceCard (int _file_id, int _line, const std::string &_text)
|
||||
|
|
@ -225,7 +197,7 @@ class SpiceCachedCircuit
|
|||
public:
|
||||
typedef std::list<SpiceCard> cards_type;
|
||||
typedef cards_type::const_iterator cards_iterator;
|
||||
typedef std::map<std::string, double> parameters_type;
|
||||
typedef NetlistSpiceReader::parameters_type parameters_type;
|
||||
typedef std::vector<std::string> pin_list_type;
|
||||
typedef pin_list_type::const_iterator pin_const_iterator;
|
||||
|
||||
|
|
@ -250,7 +222,7 @@ public:
|
|||
return m_parameters;
|
||||
}
|
||||
|
||||
void make_parameter (const std::string &name, double value)
|
||||
void make_parameter (const std::string &name, const tl::Variant &value)
|
||||
{
|
||||
for (auto p = m_pins.begin (); p != m_pins.end (); ++p) {
|
||||
if (*p == name) {
|
||||
|
|
@ -321,7 +293,7 @@ read_name (tl::Extractor &ex, const db::Netlist *netlist)
|
|||
class SpiceCircuitDict
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, double> parameters_type;
|
||||
typedef NetlistSpiceReader::parameters_type parameters_type;
|
||||
typedef std::map<std::string, SpiceCachedCircuit *> circuits_type;
|
||||
typedef circuits_type::const_iterator circuits_iterator;
|
||||
typedef std::vector<std::string> global_nets_type;
|
||||
|
|
@ -381,7 +353,7 @@ private:
|
|||
SpiceCachedCircuit *mp_circuit;
|
||||
SpiceCachedCircuit *mp_anonymous_top_level_circuit;
|
||||
std::set<std::string> m_called_circuits;
|
||||
std::map<std::string, double> m_variables;
|
||||
NetlistSpiceReader::parameters_type m_variables;
|
||||
std::set<std::string> m_global_net_names;
|
||||
std::vector<std::string> m_global_nets;
|
||||
|
||||
|
|
@ -664,7 +636,7 @@ SpiceCircuitDict::read_card ()
|
|||
|
||||
name = tl::to_upper_case (name);
|
||||
|
||||
double value = NetlistSpiceReaderDelegate::read_value (ex, m_variables);
|
||||
tl::Variant value = NetlistSpiceReaderDelegate::read_value (ex, m_variables);
|
||||
m_variables [name] = value;
|
||||
|
||||
mp_circuit->make_parameter (name, value);
|
||||
|
|
@ -716,7 +688,7 @@ void
|
|||
SpiceCircuitDict::read_circuit (tl::Extractor &ex, const std::string &nc)
|
||||
{
|
||||
std::vector<std::string> nn;
|
||||
std::map<std::string, double> pv;
|
||||
NetlistSpiceReader::parameters_type pv;
|
||||
NetlistSpiceReaderDelegate::parse_element_components (ex.skip (), nn, pv, m_variables);
|
||||
|
||||
if (cached_circuit (nc)) {
|
||||
|
|
@ -728,7 +700,7 @@ SpiceCircuitDict::read_circuit (tl::Extractor &ex, const std::string &nc)
|
|||
cc->set_parameters (pv);
|
||||
|
||||
std::swap (cc, mp_circuit);
|
||||
std::map<std::string, double> vars = pv;
|
||||
NetlistSpiceReader::parameters_type vars = pv;
|
||||
m_variables.swap (vars);
|
||||
|
||||
while (! at_end ()) {
|
||||
|
|
@ -753,7 +725,7 @@ SpiceCircuitDict::finish ()
|
|||
class SpiceNetlistBuilder
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, double> parameters_type;
|
||||
typedef NetlistSpiceReader::parameters_type parameters_type;
|
||||
|
||||
SpiceNetlistBuilder (SpiceCircuitDict *dict, Netlist *netlist, NetlistSpiceReaderDelegate *delegate);
|
||||
|
||||
|
|
@ -770,12 +742,12 @@ private:
|
|||
Netlist *mp_netlist;
|
||||
bool m_strict;
|
||||
const SpiceCachedCircuit *mp_circuit;
|
||||
std::map<const SpiceCachedCircuit *, std::map<parameters_type, db::Circuit *, ParametersLessFunction> > m_circuits;
|
||||
std::map<const SpiceCachedCircuit *, std::map<parameters_type, db::Circuit *> > m_circuits;
|
||||
db::Circuit *mp_netlist_circuit;
|
||||
db::Circuit *mp_anonymous_top_level_netlist_circuit;
|
||||
std::unique_ptr<std::map<std::string, db::Net *> > mp_nets_by_name;
|
||||
std::map<std::string, bool> m_captured;
|
||||
std::map<std::string, double> m_variables;
|
||||
NetlistSpiceReader::parameters_type m_variables;
|
||||
const SpiceCard *mp_current_card;
|
||||
|
||||
db::Circuit *circuit_for (const SpiceCachedCircuit *cached_circuit, const parameters_type &pv);
|
||||
|
|
@ -878,7 +850,7 @@ SpiceNetlistBuilder::build ()
|
|||
}
|
||||
|
||||
static std::string
|
||||
make_circuit_name (const std::string &name, const std::map<std::string, double> &pv)
|
||||
make_circuit_name (const std::string &name, const NetlistSpiceReader::parameters_type &pv)
|
||||
{
|
||||
std::string res = name;
|
||||
|
||||
|
|
@ -889,29 +861,30 @@ make_circuit_name (const std::string &name, const std::map<std::string, double>
|
|||
}
|
||||
res += p->first;
|
||||
res += "=";
|
||||
double va = fabs (p->second);
|
||||
double v = p->second.to_double ();
|
||||
double va = fabs (v);
|
||||
if (va < 1e-15) {
|
||||
res += tl::sprintf ("%g", p->second);
|
||||
res += tl::sprintf ("%g", v);
|
||||
} else if (va < 0.1e-12) {
|
||||
res += tl::sprintf ("%gF", p->second * 1e15);
|
||||
res += tl::sprintf ("%gF", v * 1e15);
|
||||
} else if (va < 0.1e-9) {
|
||||
res += tl::sprintf ("%gP", p->second * 1e12);
|
||||
res += tl::sprintf ("%gP", v * 1e12);
|
||||
} else if (va < 0.1e-6) {
|
||||
res += tl::sprintf ("%gN", p->second * 1e9);
|
||||
res += tl::sprintf ("%gN", v * 1e9);
|
||||
} else if (va < 0.1e-3) {
|
||||
res += tl::sprintf ("%gU", p->second * 1e6);
|
||||
res += tl::sprintf ("%gU", v * 1e6);
|
||||
} else if (va< 0.1) {
|
||||
res += tl::sprintf ("%gM", p->second * 1e3);
|
||||
res += tl::sprintf ("%gM", v * 1e3);
|
||||
} else if (va < 0.1e3) {
|
||||
res += tl::sprintf ("%g", p->second);
|
||||
res += tl::sprintf ("%g", v);
|
||||
} else if (va < 0.1e6) {
|
||||
res += tl::sprintf ("%gK", p->second * 1e-3);
|
||||
res += tl::sprintf ("%gK", v * 1e-3);
|
||||
} else if (va < 0.1e9) {
|
||||
res += tl::sprintf ("%gMEG", p->second * 1e-6);
|
||||
res += tl::sprintf ("%gMEG", v * 1e-6);
|
||||
} else if (va < 0.1e12) {
|
||||
res += tl::sprintf ("%gG", p->second * 1e-9);
|
||||
res += tl::sprintf ("%gG", v * 1e-9);
|
||||
} else {
|
||||
res += tl::sprintf ("%g", p->second);
|
||||
res += tl::sprintf ("%g", v);
|
||||
}
|
||||
}
|
||||
res += ")";
|
||||
|
|
@ -940,7 +913,7 @@ SpiceNetlistBuilder::build_circuit (const SpiceCachedCircuit *cc, const paramete
|
|||
std::unique_ptr<std::map<std::string, db::Net *> > n2n (mp_nets_by_name.release ());
|
||||
mp_nets_by_name.reset (0);
|
||||
|
||||
std::map<std::string, double> vars;
|
||||
NetlistSpiceReader::parameters_type vars;
|
||||
|
||||
std::swap (vars, m_variables);
|
||||
std::swap (c, mp_netlist_circuit);
|
||||
|
|
@ -1052,7 +1025,7 @@ SpiceNetlistBuilder::process_element (tl::Extractor &ex, const std::string &pref
|
|||
{
|
||||
// generic parse
|
||||
std::vector<std::string> nn;
|
||||
std::map<std::string, double> pv;
|
||||
NetlistSpiceReader::parameters_type pv;
|
||||
std::string model;
|
||||
double value = 0.0;
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,13 @@
|
|||
|
||||
#include "dbCommon.h"
|
||||
#include "dbNetlistReader.h"
|
||||
|
||||
#include "tlStream.h"
|
||||
#include "tlObject.h"
|
||||
#include "tlVariant.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace db
|
||||
{
|
||||
|
|
@ -53,6 +58,8 @@ class DB_PUBLIC NetlistSpiceReader
|
|||
: public NetlistReader
|
||||
{
|
||||
public:
|
||||
typedef std::map<std::string, tl::Variant> parameters_type;
|
||||
|
||||
NetlistSpiceReader (NetlistSpiceReaderDelegate *delegate = 0);
|
||||
virtual ~NetlistSpiceReader ();
|
||||
|
||||
|
|
|
|||
|
|
@ -176,7 +176,7 @@ static std::string parse_component (tl::Extractor &ex)
|
|||
return std::string (cp0, cp - cp0);
|
||||
}
|
||||
|
||||
void NetlistSpiceReaderDelegate::parse_element_components (const std::string &s, std::vector<std::string> &strings, std::map<std::string, double> &pv, const std::map<std::string, double> &variables)
|
||||
void NetlistSpiceReaderDelegate::parse_element_components (const std::string &s, std::vector<std::string> &strings, std::map<std::string, tl::Variant> &pv, const std::map<std::string, tl::Variant> &variables)
|
||||
{
|
||||
tl::Extractor ex (s.c_str ());
|
||||
bool in_params = false;
|
||||
|
|
@ -208,7 +208,7 @@ void NetlistSpiceReaderDelegate::parse_element_components (const std::string &s,
|
|||
}
|
||||
}
|
||||
|
||||
void NetlistSpiceReaderDelegate::parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, std::map<std::string, double> &pv, const std::map<std::string, double> &variables)
|
||||
void NetlistSpiceReaderDelegate::parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, std::map<std::string, tl::Variant> &pv, const std::map<std::string, tl::Variant> &variables)
|
||||
{
|
||||
parse_element_components (s, nn, pv, variables);
|
||||
|
||||
|
|
@ -242,11 +242,11 @@ void NetlistSpiceReaderDelegate::parse_element (const std::string &s, const std:
|
|||
error (tl::to_string (tr ("Not enough specs for a R, C or L device")));
|
||||
}
|
||||
|
||||
std::map<std::string, double>::const_iterator rv = pv.find (element);
|
||||
auto rv = pv.find (element);
|
||||
if (rv != pv.end ()) {
|
||||
|
||||
// value given by parameter
|
||||
value = rv->second;
|
||||
value = rv->second.to_double ();
|
||||
|
||||
if (nn.size () >= 3) {
|
||||
// Rname n1 n2 model [params]
|
||||
|
|
@ -309,14 +309,14 @@ void NetlistSpiceReaderDelegate::parse_element (const std::string &s, const std:
|
|||
}
|
||||
}
|
||||
|
||||
bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, double> &pv)
|
||||
bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, tl::Variant> &pv)
|
||||
{
|
||||
std::map<std::string, double> params = pv;
|
||||
std::map<std::string, tl::Variant> params = pv;
|
||||
|
||||
double mult = 1.0;
|
||||
std::map<std::string, double>::const_iterator mp = params.find ("M");
|
||||
auto mp = params.find ("M");
|
||||
if (mp != params.end ()) {
|
||||
mult = mp->second;
|
||||
mult = mp->second.to_double ();
|
||||
}
|
||||
|
||||
if (mult < 1e-10) {
|
||||
|
|
@ -422,10 +422,9 @@ bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::strin
|
|||
}
|
||||
|
||||
// Apply multiplier to "A"
|
||||
std::map<std::string, double>::iterator p;
|
||||
p = params.find ("A");
|
||||
auto p = params.find ("A");
|
||||
if (p != params.end ()) {
|
||||
p->second *= mult;
|
||||
p->second = tl::Variant (p->second.to_double () * mult);
|
||||
}
|
||||
|
||||
} else if (element == "Q") {
|
||||
|
|
@ -457,10 +456,9 @@ bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::strin
|
|||
}
|
||||
|
||||
// Apply multiplier to "AE"
|
||||
std::map<std::string, double>::iterator p;
|
||||
p = params.find ("AE");
|
||||
auto p = params.find ("AE");
|
||||
if (p != params.end ()) {
|
||||
p->second *= mult;
|
||||
p->second = tl::Variant (p->second.to_double () * mult);
|
||||
}
|
||||
|
||||
} else if (element == "M") {
|
||||
|
|
@ -481,10 +479,9 @@ bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::strin
|
|||
}
|
||||
|
||||
// Apply multiplier to "W"
|
||||
std::map<std::string, double>::iterator p;
|
||||
p = params.find ("W");
|
||||
auto p = params.find ("W");
|
||||
if (p != params.end ()) {
|
||||
p->second *= mult;
|
||||
p->second = tl::Variant (p->second.to_double () * mult);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
@ -514,9 +511,9 @@ bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::strin
|
|||
|
||||
std::vector<db::DeviceParameterDefinition> &pd = cls->parameter_definitions_non_const ();
|
||||
for (std::vector<db::DeviceParameterDefinition>::iterator i = pd.begin (); i != pd.end (); ++i) {
|
||||
std::map<std::string, double>::const_iterator v = params.find (i->name ());
|
||||
auto v = params.find (i->name ());
|
||||
if (v != params.end ()) {
|
||||
device->set_parameter_value (i->id (), v->second / i->si_scaling ());
|
||||
device->set_parameter_value (i->id (), v->second.to_double () / i->si_scaling ());
|
||||
} else if (i->id () == defp) {
|
||||
device->set_parameter_value (i->id (), value / i->si_scaling ());
|
||||
}
|
||||
|
|
@ -526,7 +523,7 @@ bool NetlistSpiceReaderDelegate::element (db::Circuit *circuit, const std::strin
|
|||
}
|
||||
|
||||
double
|
||||
NetlistSpiceReaderDelegate::read_value (tl::Extractor &ex, const std::map<std::string, double> &variables)
|
||||
NetlistSpiceReaderDelegate::read_value (tl::Extractor &ex, const std::map<std::string, tl::Variant> &variables)
|
||||
{
|
||||
std::map<std::string, tl::Variant> vvariables;
|
||||
for (auto i = variables.begin (); i != variables.end (); ++i) {
|
||||
|
|
@ -538,7 +535,7 @@ NetlistSpiceReaderDelegate::read_value (tl::Extractor &ex, const std::map<std::s
|
|||
}
|
||||
|
||||
bool
|
||||
NetlistSpiceReaderDelegate::try_read_value (const std::string &s, double &v, const std::map<std::string, double> &variables)
|
||||
NetlistSpiceReaderDelegate::try_read_value (const std::string &s, double &v, const std::map<std::string, tl::Variant> &variables)
|
||||
{
|
||||
std::map<std::string, tl::Variant> vvariables;
|
||||
for (auto i = variables.begin (); i != variables.end (); ++i) {
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public:
|
|||
*
|
||||
* This method returns true, if the element was read.
|
||||
*/
|
||||
virtual bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, double> ¶ms);
|
||||
virtual bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, tl::Variant> ¶ms);
|
||||
|
||||
/**
|
||||
* @brief Parses an element from a line
|
||||
|
|
@ -113,7 +113,7 @@ public:
|
|||
* @param nn Out parameter: the net names
|
||||
* @param pv Out parameter: the parameter values (key/value pairs)
|
||||
*/
|
||||
virtual void parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, std::map<std::string, double> &pv, const std::map<std::string, double> ¶ms);
|
||||
virtual void parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, std::map<std::string, tl::Variant> &pv, const std::map<std::string, tl::Variant> ¶ms);
|
||||
|
||||
/**
|
||||
* @brief Produces an error with the given message
|
||||
|
|
@ -124,17 +124,17 @@ public:
|
|||
* @brief Reads a set of string components and parameters from the string
|
||||
* A special key "param:" is recognized for starting a parameter list.
|
||||
*/
|
||||
static void parse_element_components (const std::string &s, std::vector<std::string> &strings, std::map<std::string, double> &pv, const std::map<std::string, double> &variables);
|
||||
static void parse_element_components (const std::string &s, std::vector<std::string> &strings, std::map<std::string, tl::Variant> &pv, const std::map<std::string, tl::Variant> &variables);
|
||||
|
||||
/**
|
||||
* @brief Reads a value from the extractor (with formula evaluation)
|
||||
*/
|
||||
static double read_value (tl::Extractor &ex, const std::map<std::string, double> &variables);
|
||||
static double read_value (tl::Extractor &ex, const std::map<std::string, tl::Variant> &variables);
|
||||
|
||||
/**
|
||||
* @brief Tries to read a value from the extractor (with formula evaluation)
|
||||
*/
|
||||
static bool try_read_value (const std::string &s, double &v, const std::map<std::string, double> &variables);
|
||||
static bool try_read_value (const std::string &s, double &v, const std::map<std::string, tl::Variant> &variables);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2418,15 +2418,15 @@ public:
|
|||
const std::vector<std::string> &net_names () const { return m_net_names; }
|
||||
std::vector<std::string> &net_names_nc () { return m_net_names; }
|
||||
void set_net_names (const std::vector<std::string> &nn) { m_net_names = nn; }
|
||||
const std::map<std::string, double> ¶meters () const { return m_parameters; }
|
||||
std::map<std::string, double> ¶meters_nc () { return m_parameters; }
|
||||
void set_parameters (const std::map<std::string, double> ¶meters) { m_parameters = parameters; }
|
||||
const db::NetlistSpiceReader::parameters_type ¶meters () const { return m_parameters; }
|
||||
db::NetlistSpiceReader::parameters_type ¶meters_nc () { return m_parameters; }
|
||||
void set_parameters (const db::NetlistSpiceReader::parameters_type ¶meters) { m_parameters = parameters; }
|
||||
|
||||
private:
|
||||
std::string m_model;
|
||||
double m_value;
|
||||
std::vector<std::string> m_net_names;
|
||||
std::map<std::string, double> m_parameters;
|
||||
db::NetlistSpiceReader::parameters_type m_parameters;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -2440,13 +2440,13 @@ public:
|
|||
const std::vector<std::string> &strings () const { return m_strings; }
|
||||
std::vector<std::string> &strings_nc () { return m_strings; }
|
||||
void set_strings (const std::vector<std::string> &nn) { m_strings = nn; }
|
||||
const std::map<std::string, double> ¶meters () const { return m_parameters; }
|
||||
std::map<std::string, double> ¶meters_nc () { return m_parameters; }
|
||||
void set_parameters (const std::map<std::string, double> ¶meters) { m_parameters = parameters; }
|
||||
const db::NetlistSpiceReader::parameters_type ¶meters () const { return m_parameters; }
|
||||
db::NetlistSpiceReader::parameters_type ¶meters_nc () { return m_parameters; }
|
||||
void set_parameters (const db::NetlistSpiceReader::parameters_type ¶meters) { m_parameters = parameters; }
|
||||
|
||||
private:
|
||||
std::vector<std::string> m_strings;
|
||||
std::map<std::string, double> m_parameters;
|
||||
db::NetlistSpiceReader::parameters_type m_parameters;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -2571,7 +2571,7 @@ public:
|
|||
return data;
|
||||
}
|
||||
|
||||
virtual void parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, std::map<std::string, double> &pv, const std::map<std::string, double> &variables)
|
||||
virtual void parse_element (const std::string &s, const std::string &element, std::string &model, double &value, std::vector<std::string> &nn, db::NetlistSpiceReader::parameters_type &pv, const db::NetlistSpiceReader::parameters_type &variables)
|
||||
{
|
||||
try {
|
||||
|
||||
|
|
@ -2605,12 +2605,12 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, double> ¶ms)
|
||||
virtual bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const db::NetlistSpiceReader::parameters_type ¶ms)
|
||||
{
|
||||
try {
|
||||
m_error.clear ();
|
||||
if (cb_element.can_issue ()) {
|
||||
return cb_element.issue<db::NetlistSpiceReaderDelegate, bool, db::Circuit *, const std::string &, const std::string &, const std::string &, double, const std::vector<db::Net *> &, const std::map<std::string, double> &> (&db::NetlistSpiceReaderDelegate::element, circuit, element, name, model, value, nets, params);
|
||||
return cb_element.issue<db::NetlistSpiceReaderDelegate, bool, db::Circuit *, const std::string &, const std::string &, const std::string &, double, const std::vector<db::Net *> &, const db::NetlistSpiceReader::parameters_type &> (&db::NetlistSpiceReaderDelegate::element, circuit, element, name, model, value, nets, params);
|
||||
} else {
|
||||
return db::NetlistSpiceReaderDelegate::element (circuit, element, name, model, value, nets, params);
|
||||
}
|
||||
|
|
@ -2624,9 +2624,9 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
const std::map<std::string, double> &variables () const
|
||||
const db::NetlistSpiceReader::parameters_type &variables () const
|
||||
{
|
||||
static std::map<std::string, double> empty;
|
||||
static db::NetlistSpiceReader::parameters_type empty;
|
||||
return mp_variables ? *mp_variables : empty;
|
||||
}
|
||||
|
||||
|
|
@ -2640,7 +2640,7 @@ public:
|
|||
|
||||
private:
|
||||
std::string m_error;
|
||||
const std::map<std::string, double> *mp_variables;
|
||||
const db::NetlistSpiceReader::parameters_type *mp_variables;
|
||||
};
|
||||
|
||||
static void start_fb (NetlistSpiceReaderDelegateImpl *delegate, db::Netlist *netlist)
|
||||
|
|
@ -2668,7 +2668,7 @@ static std::string translate_net_name_fb (NetlistSpiceReaderDelegateImpl *delega
|
|||
return delegate->db::NetlistSpiceReaderDelegate::translate_net_name (name);
|
||||
}
|
||||
|
||||
static bool element_fb (NetlistSpiceReaderDelegateImpl *delegate, db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, double> ¶ms)
|
||||
static bool element_fb (NetlistSpiceReaderDelegateImpl *delegate, db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const db::NetlistSpiceReader::parameters_type ¶ms)
|
||||
{
|
||||
return delegate->db::NetlistSpiceReaderDelegate::element (circuit, element, name, model, value, nets, params);
|
||||
}
|
||||
|
|
@ -2678,7 +2678,7 @@ static ParseElementData parse_element_fb (NetlistSpiceReaderDelegateImpl *delega
|
|||
return delegate->parse_element_helper (s, element);
|
||||
}
|
||||
|
||||
static tl::Variant value_from_string (NetlistSpiceReaderDelegateImpl * /*delegate*/, const std::string &s, const std::map<std::string, double> &variables)
|
||||
static tl::Variant value_from_string (NetlistSpiceReaderDelegateImpl * /*delegate*/, const std::string &s, const db::NetlistSpiceReader::parameters_type &variables)
|
||||
{
|
||||
tl::Variant res;
|
||||
double v = 0.0;
|
||||
|
|
@ -2688,7 +2688,7 @@ static tl::Variant value_from_string (NetlistSpiceReaderDelegateImpl * /*delegat
|
|||
return res;
|
||||
}
|
||||
|
||||
static ParseElementComponentsData parse_element_components (NetlistSpiceReaderDelegateImpl * /*delegate*/, const std::string &s, const std::map<std::string, double> &variables)
|
||||
static ParseElementComponentsData parse_element_components (NetlistSpiceReaderDelegateImpl * /*delegate*/, const std::string &s, const db::NetlistSpiceReader::parameters_type &variables)
|
||||
{
|
||||
ParseElementComponentsData data;
|
||||
db::NetlistSpiceReaderDelegate::parse_element_components (s, data.strings_nc (), data.parameters_nc (), variables);
|
||||
|
|
@ -2697,22 +2697,24 @@ static ParseElementComponentsData parse_element_components (NetlistSpiceReaderDe
|
|||
|
||||
Class<ParseElementComponentsData> db_ParseElementComponentsData ("db", "ParseElementComponentsData",
|
||||
gsi::method ("strings", &ParseElementComponentsData::strings,
|
||||
"@brief Gets the string parameters\n"
|
||||
"@brief Gets the (unnamed) string parameters\n"
|
||||
"These parameters are typically net names or model name."
|
||||
) +
|
||||
gsi::method ("strings=", &ParseElementComponentsData::set_strings, gsi::arg ("list"),
|
||||
"@brief Sets the string parameters\n"
|
||||
"@brief Sets the (unnamed) string parameters\n"
|
||||
) +
|
||||
gsi::method ("parameters", &ParseElementComponentsData::parameters,
|
||||
"@brief Gets the (named) numerical parameters\n"
|
||||
"@brief Gets the (named) parameters\n"
|
||||
"Named parameters are typically (but not neccessarily) numerical, like 'w=0.15u'."
|
||||
) +
|
||||
gsi::method ("parameters=", &ParseElementComponentsData::set_parameters, gsi::arg ("dict"),
|
||||
"@brief Sets the (named) numerical parameters\n"
|
||||
"@brief Sets the (named) parameters\n"
|
||||
),
|
||||
"@brief Supplies the return value for \\NetlistSpiceReaderDelegate#parse_element_components.\n"
|
||||
"This is a structure with two members: 'strings' for the string arguments and 'parameters' for the "
|
||||
"named numerical arguments.\n"
|
||||
"named arguments.\n"
|
||||
"\n"
|
||||
"This helper class has been introduced in version 0.27.1.\n"
|
||||
"This helper class has been introduced in version 0.27.1. Starting with version 0.28.7, named parameters can be string types too.\n"
|
||||
);
|
||||
|
||||
Class<ParseElementData> db_ParseElementData ("db", "ParseElementData",
|
||||
|
|
@ -2735,16 +2737,16 @@ Class<ParseElementData> db_ParseElementData ("db", "ParseElementData",
|
|||
"@brief Sets the net names\n"
|
||||
) +
|
||||
gsi::method ("parameters", &ParseElementData::parameters,
|
||||
"@brief Gets the (named) numerical parameters\n"
|
||||
"@brief Gets the (named) parameters\n"
|
||||
) +
|
||||
gsi::method ("parameters=", &ParseElementData::set_parameters, gsi::arg ("dict"),
|
||||
"@brief Sets the (named) numerical parameters\n"
|
||||
"@brief Sets the (named) parameters\n"
|
||||
),
|
||||
"@brief Supplies the return value for \\NetlistSpiceReaderDelegate#parse_element.\n"
|
||||
"This is a structure with four members: 'model_name' for the model name, 'value' for the default numerical value, 'net_names' for the net names and 'parameters' for the "
|
||||
"named numerical parameters.\n"
|
||||
"named parameters.\n"
|
||||
"\n"
|
||||
"This helper class has been introduced in version 0.27.1.\n"
|
||||
"This helper class has been introduced in version 0.27.1. Starting with version 0.28.7, named parameters can be string types too.\n"
|
||||
);
|
||||
|
||||
Class<NetlistSpiceReaderDelegateImpl> db_NetlistSpiceReaderDelegate ("db", "NetlistSpiceReaderDelegate",
|
||||
|
|
@ -2817,12 +2819,14 @@ Class<NetlistSpiceReaderDelegateImpl> db_NetlistSpiceReaderDelegate ("db", "Netl
|
|||
"some known elements using the Spice writer's parameter conventions.\n"
|
||||
"\n"
|
||||
"The method must return true, if the element was was understood and false otherwise.\n"
|
||||
"\n"
|
||||
"Starting with version 0.28.7, the parameter values can be strings too."
|
||||
) +
|
||||
gsi::method ("error", &NetlistSpiceReaderDelegateImpl::error, gsi::arg ("msg"),
|
||||
"@brief Issues an error with the given message.\n"
|
||||
"Use this method to generate an error."
|
||||
) +
|
||||
gsi::method_ext ("value_from_string", &value_from_string, gsi::arg ("s"), gsi::arg ("variables", std::map<std::string, double> (), "{}"),
|
||||
gsi::method_ext ("value_from_string", &value_from_string, gsi::arg ("s"), gsi::arg ("variables", db::NetlistSpiceReader::parameters_type (), "{}"),
|
||||
"@brief Translates a string into a value\n"
|
||||
"This function simplifies the implementation of SPICE readers by providing a translation of a unit-annotated string "
|
||||
"into double values. For example, '1k' is translated to 1000.0. In addition, simple formula evaluation is supported, e.g "
|
||||
|
|
@ -2832,7 +2836,7 @@ Class<NetlistSpiceReaderDelegateImpl> db_NetlistSpiceReaderDelegate ("db", "Netl
|
|||
"\n"
|
||||
"This method has been introduced in version 0.27.1. The variables argument has been added in version 0.28.7.\n"
|
||||
) +
|
||||
gsi::method_ext ("parse_element_components", &parse_element_components, gsi::arg ("s"), gsi::arg ("variables", std::map<std::string, double> (), "{}"),
|
||||
gsi::method_ext ("parse_element_components", &parse_element_components, gsi::arg ("s"), gsi::arg ("variables", db::NetlistSpiceReader::parameters_type (), "{}"),
|
||||
"@brief Parses a string into string and parameter components.\n"
|
||||
"This method is provided to simplify the implementation of 'parse_element'. It takes a string and splits it into "
|
||||
"string arguments and parameter values. For example, 'a b c=6' renders two string arguments in 'nn' and one parameter ('C'->6.0). "
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ public:
|
|||
return circuit_name == "HVNMOS" || circuit_name == "HVPMOS";
|
||||
}
|
||||
|
||||
bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, double> ¶ms)
|
||||
bool element (db::Circuit *circuit, const std::string &element, const std::string &name, const std::string &model, double value, const std::vector<db::Net *> &nets, const std::map<std::string, tl::Variant> ¶ms)
|
||||
{
|
||||
if (element == "X") {
|
||||
|
||||
|
|
@ -240,9 +240,9 @@ public:
|
|||
|
||||
const std::vector<db::DeviceParameterDefinition> &td = cls->parameter_definitions ();
|
||||
for (std::vector<db::DeviceParameterDefinition>::const_iterator i = td.begin (); i != td.end (); ++i) {
|
||||
std::map<std::string, double>::const_iterator pi = params.find (i->name ());
|
||||
auto pi = params.find (i->name ());
|
||||
if (pi != params.end ()) {
|
||||
device->set_parameter_value (i->id (), pi->second * 1.5);
|
||||
device->set_parameter_value (i->id (), pi->second.to_double () * 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue