Do not derive other classes from std::vector. More cleanup. (nw)

This commit is contained in:
couriersud 2017-01-26 21:22:59 +01:00
parent 5c88873a87
commit 6d2354264a
16 changed files with 64 additions and 74 deletions

View File

@ -11,7 +11,6 @@
#define NLD_OPAMPS_H_
#include "nl_base.h"
#include "nl_setup.h"
#include "nld_twoterm.h"
#include "nld_fourterm.h"

View File

@ -186,14 +186,14 @@ void truthtable_desc_t::setup(const std::vector<pstring> &truthtable, uint_least
while (!ttline.equals(""))
{
plib::pstring_vector_t io(ttline,"|");
std::vector<pstring> io(plib::psplit(ttline,"|"));
// checks
nl_assert_always(io.size() == 3, "io.count mismatch");
plib::pstring_vector_t inout(io[0], ",");
std::vector<pstring> inout(plib::psplit(io[0], ","));
nl_assert_always(inout.size() == m_num_bits, "number of bits not matching");
plib::pstring_vector_t out(io[1], ",");
std::vector<pstring> out(plib::psplit(io[1], ","));
nl_assert_always(out.size() == m_NO, "output count not matching");
plib::pstring_vector_t times(io[2], ",");
std::vector<pstring> times(plib::psplit(io[2], ","));
nl_assert_always(times.size() == m_NO, "timing count not matching");
uint_least64_t val = 0;

View File

@ -11,8 +11,6 @@
#define NLD_TRUTHTABLE_H_
#include "nl_setup.h"
#include "nl_factory.h"
#include "plib/plists.h"
#include "plib/putil.h"
#define NETLIB_TRUTHTABLE(cname, nIN, nOUT) \
@ -191,12 +189,12 @@ namespace netlist
pstring header = m_desc[0];
plib::pstring_vector_t io(header,"|");
std::vector<pstring> io(plib::psplit(header,"|"));
// checks
nl_assert_always(io.size() == 2, "too many '|'");
plib::pstring_vector_t inout(io[0], ",");
std::vector<pstring> inout(plib::psplit(io[0], ","));
nl_assert_always(inout.size() == m_num_bits, "bitcount wrong");
plib::pstring_vector_t out(io[1], ",");
std::vector<pstring> out(plib::psplit(io[1], ","));
nl_assert_always(out.size() == m_NO, "output count wrong");
for (std::size_t i=0; i < m_NI; i++)

View File

@ -8,7 +8,7 @@
#ifndef NLID_CMOS_H_
#define NLID_CMOS_H_
#include "nl_base.h"
#include "nl_setup.h"
namespace netlist
{

View File

@ -12,8 +12,6 @@
#define NLID_PROXY_H_
#include "nl_setup.h"
#include "nl_base.h"
#include "nl_factory.h"
#include "analog/nld_twoterm.h"
namespace netlist

View File

@ -11,14 +11,8 @@
#ifndef NLID_SYSTEM_H_
#define NLID_SYSTEM_H_
#include "analog/nld_twoterm.h"
#include "nl_base.h"
#include "nl_time.h"
#include "nl_setup.h"
#include "plib/palloc.h"
#include "plib/pfmtlog.h"
#include "plib/pfunction.h"
#include "plib/pstring.h"
#include "analog/nld_twoterm.h"
#include "plib/putil.h"
namespace netlist
@ -129,7 +123,7 @@ namespace netlist
connect(m_feedback, m_Q);
{
netlist_time base = netlist_time::from_double(1.0 / (m_freq()*2.0));
plib::pstring_vector_t pat(m_pattern(),",");
std::vector<pstring> pat(plib::psplit(m_pattern(),","));
m_off = netlist_time::from_double(m_offset());
unsigned long pati[256];

View File

@ -293,7 +293,7 @@ void parser_t::net_c()
void parser_t::dippins()
{
plib::pstring_vector_t pins;
std::vector<pstring> pins;
pins.push_back(get_identifier());
require_token(m_tok_comma);
@ -350,7 +350,7 @@ void parser_t::netdev_hint()
void parser_t::device(const pstring &dev_type)
{
factory::element_t *f = m_setup.factory().factory_by_name(dev_type);
auto paramlist = plib::pstring_vector_t(f->param_desc(), ",");
auto paramlist = plib::psplit(f->param_desc(), ",");
pstring devname = get_identifier();

View File

@ -121,7 +121,7 @@ void setup_t::register_alias(const pstring &alias, const pstring &out)
void setup_t::register_dippins_arr(const pstring &terms)
{
plib::pstring_vector_t list(terms,", ");
std::vector<pstring> list(plib::psplit(terms,", "));
if (list.size() == 0 || (list.size() % 2) == 1)
log().fatal(MF_1_DIP_PINS_MUST_BE_AN_EQUAL_NUMBER_OF_PINS_1,
build_fqn(""));
@ -202,7 +202,7 @@ void setup_t::register_term(detail::core_terminal_t &term)
void setup_t::register_link_arr(const pstring &terms)
{
plib::pstring_vector_t list(terms,", ");
std::vector<pstring> list(plib::psplit(terms,", "));
if (list.size() < 2)
log().fatal(MF_2_NET_C_NEEDS_AT_LEAST_2_TERMINAL);
for (std::size_t i = 1; i < list.size(); i++)
@ -769,7 +769,7 @@ void setup_t::start_devices()
if (env != "")
{
log().debug("Creating dynamic logs ...");
plib::pstring_vector_t loglist(env, ":");
std::vector<pstring> loglist(plib::psplit(env, ":"));
for (pstring ll : loglist)
{
pstring name = "log_" + ll;
@ -840,7 +840,7 @@ void setup_t::model_parse(const pstring &model_in, model_map_t &map)
// FIMXE: Not optimal
remainder = remainder.left(remainder.begin() + (remainder.len() - 1));
plib::pstring_vector_t pairs(remainder," ", true);
std::vector<pstring> pairs(plib::psplit(remainder," ", true));
for (pstring &pe : pairs)
{
auto pose = pe.find("=");

View File

@ -24,7 +24,7 @@ void pfunction::compile(const std::vector<pstring> &inputs, const pstring expr)
void pfunction::compile_postfix(const std::vector<pstring> &inputs, const pstring expr)
{
plib::pstring_vector_t cmds(expr, " ");
std::vector<pstring> cmds(plib::psplit(expr, " "));
compile_postfix(inputs, cmds, expr);
}
@ -110,9 +110,9 @@ void pfunction::compile_infix(const std::vector<pstring> &inputs, const pstring
{
// Shunting-yard infix parsing
std::vector<pstring> sep = {"(", ")", ",", "*", "/", "+", "-", "^"};
plib::pstring_vector_t sexpr(expr.replace(" ",""), sep);
std::vector<pstring> sexpr(plib::psplit(expr.replace(" ",""), sep));
std::stack<pstring> opstk;
plib::pstring_vector_t postfix;
std::vector<pstring> postfix;
//printf("dbg: %s\n", expr.c_str());
for (unsigned i = 0; i < sexpr.size(); i++)

View File

@ -39,13 +39,13 @@ namespace plib {
{
}
int option_str::parse(pstring argument)
int option_str::parse(const pstring &argument)
{
m_val = argument;
return 0;
}
int option_str_limit::parse(pstring argument)
int option_str_limit::parse(const pstring &argument)
{
if (plib::container::contains(m_limit, argument))
{
@ -56,20 +56,20 @@ namespace plib {
return 1;
}
int option_bool::parse(pstring argument)
int option_bool::parse(const pstring &argument)
{
m_val = true;
return 0;
}
int option_double::parse(pstring argument)
int option_double::parse(const pstring &argument)
{
bool err = false;
m_val = argument.as_double(&err);
return (err ? 1 : 0);
}
int option_vec::parse(pstring argument)
int option_vec::parse(const pstring &argument)
{
bool err = false;
m_val.push_back(argument);
@ -113,7 +113,7 @@ namespace plib {
if (arg.startsWith("--"))
{
auto v = pstring_vector_t(arg.substr(2),"=");
auto v = psplit(arg.substr(2),"=");
opt = getopt_long(v[0]);
has_equal_arg = (v.size() > 1);
if (has_equal_arg)
@ -166,13 +166,13 @@ namespace plib {
pstring options::split_paragraphs(pstring text, unsigned width, unsigned indent,
unsigned firstline_indent)
{
auto paragraphs = pstring_vector_t(text,"\n");
auto paragraphs = psplit(text,"\n");
pstring ret("");
for (auto &p : paragraphs)
{
pstring line = pstring("").rpad(" ", firstline_indent);
for (auto &s : pstring_vector_t(p, " "))
for (auto &s : psplit(p, " "))
{
if (line.len() + s.len() > width)
{

View File

@ -65,7 +65,7 @@ public:
/* no_argument options will be called with "" argument */
virtual int parse(pstring argument) = 0;
virtual int parse(const pstring &argument) = 0;
pstring short_opt() { return m_short; }
pstring long_opt() { return m_long; }
@ -83,7 +83,7 @@ public:
: option(parent, ashort, along, help, true), m_val(defval)
{}
virtual int parse(pstring argument) override;
virtual int parse(const pstring &argument) override;
pstring operator ()() { return m_val; }
private:
@ -94,17 +94,19 @@ class option_str_limit : public option
{
public:
option_str_limit(options &parent, pstring ashort, pstring along, pstring defval, pstring limit, pstring help)
: option(parent, ashort, along, help, true), m_val(defval), m_limit(limit, ":")
{}
: option(parent, ashort, along, help, true), m_val(defval)
{
m_limit = plib::psplit(limit, ":");
}
virtual int parse(pstring argument) override;
virtual int parse(const pstring &argument) override;
pstring operator ()() { return m_val; }
const plib::pstring_vector_t &limit() { return m_limit; }
const std::vector<pstring> &limit() { return m_limit; }
private:
pstring m_val;
plib::pstring_vector_t m_limit;
std::vector<pstring> m_limit;
};
class option_bool : public option
@ -114,7 +116,7 @@ public:
: option(parent, ashort, along, help, false), m_val(false)
{}
virtual int parse(pstring argument) override;
virtual int parse(const pstring &argument) override;
bool operator ()() { return m_val; }
private:
@ -128,7 +130,7 @@ public:
: option(parent, ashort, along, help, true), m_val(defval)
{}
virtual int parse(pstring argument) override;
virtual int parse(const pstring &argument) override;
double operator ()() { return m_val; }
private:
@ -142,7 +144,7 @@ public:
: option(parent, ashort, along, help, true)
{}
virtual int parse(pstring argument) override;
virtual int parse(const pstring &argument) override;
std::vector<pstring> operator ()() { return m_val; }
private:

View File

@ -384,7 +384,7 @@ ppreprocessor::define_t *ppreprocessor::get_define(const pstring &name)
pstring ppreprocessor::replace_macros(const pstring &line)
{
pstring_vector_t elems(line, m_expr_sep);
std::vector<pstring> elems(psplit(line, m_expr_sep));
pstringbuffer ret = "";
for (auto & elem : elems)
{
@ -397,7 +397,7 @@ pstring ppreprocessor::replace_macros(const pstring &line)
return ret;
}
static pstring catremainder(const pstring_vector_t &elems, std::size_t start, pstring sep)
static pstring catremainder(const std::vector<pstring> &elems, std::size_t start, pstring sep)
{
pstringbuffer ret = "";
for (auto & elem : elems)
@ -416,13 +416,13 @@ pstring ppreprocessor::process_line(const pstring &line)
// FIXME ... revise and extend macro handling
if (lt.startsWith("#"))
{
pstring_vector_t lti(lt, " ", true);
std::vector<pstring> lti(psplit(lt, " ", true));
if (lti[0].equals("#if"))
{
m_level++;
std::size_t start = 0;
lt = replace_macros(lt);
pstring_vector_t t(lt.substr(3).replace(" ",""), m_expr_sep);
std::vector<pstring> t(psplit(lt.substr(3).replace(" ",""), m_expr_sep));
int val = static_cast<int>(expr(t, start, 0));
if (val == 0)
m_ifflag |= (1 << m_level);

View File

@ -40,9 +40,10 @@ namespace plib
}
}
pstring_vector_t::pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty)
: std::vector<pstring>()
std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty)
{
std::vector<pstring> ret;
pstring::iterator p = str.begin();
pstring::iterator pn = str.find(onstr, p);
@ -50,7 +51,7 @@ namespace plib
{
pstring t = str.substr(p, pn);
if (!ignore_empty || t.len() != 0)
this->push_back(t);
ret.push_back(t);
p = pn + onstr.len();
pn = str.find(onstr, p);
}
@ -58,14 +59,15 @@ namespace plib
{
pstring t = str.substr(p, str.end());
if (!ignore_empty || t.len() != 0)
this->push_back(t);
ret.push_back(t);
}
return ret;
}
pstring_vector_t::pstring_vector_t(const pstring &str, const std::vector<pstring> &onstrl)
: std::vector<pstring>()
std::vector<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl)
{
pstring col = "";
std::vector<pstring> ret;
unsigned i = 0;
while (i<str.blen())
@ -82,10 +84,10 @@ namespace plib
if (p != static_cast<std::size_t>(-1))
{
if (col != "")
this->push_back(col);
ret.push_back(col);
col = "";
this->push_back(onstrl[p]);
ret.push_back(onstrl[p]);
i += onstrl[p].blen();
}
else
@ -96,7 +98,9 @@ namespace plib
}
}
if (col != "")
this->push_back(col);
ret.push_back(col);
return ret;
}

View File

@ -66,13 +66,8 @@ namespace plib
// string list
// ----------------------------------------------------------------------------------------
class pstring_vector_t : public std::vector<pstring>
{
public:
pstring_vector_t() : std::vector<pstring>() { }
pstring_vector_t(const pstring &str, const pstring &onstr, bool ignore_empty = false);
pstring_vector_t(const pstring &str, const std::vector<pstring> &onstrl);
};
std::vector<pstring> psplit(const pstring &str, const pstring &onstr, bool ignore_empty = false);
std::vector<pstring> psplit(const pstring &str, const std::vector<pstring> &onstrl);
}

View File

@ -375,7 +375,7 @@ static void create_header(tool_options_t &opts)
pout("{1}\n", pstring("// Source: ").cat(e->sourcefile().replace("../","")));
pout("{1}\n", pstring("// ").rpad("-", 72));
}
auto v = plib::pstring_vector_t(e->param_desc(), ",");
auto v = plib::psplit(e->param_desc(), ",");
pstring vs;
for (auto s : v)
vs += ", p" + s.replace("+","").replace(".","_");
@ -464,7 +464,7 @@ static void listdevices(tool_options_t &opts)
}
out += "," + f->param_desc();
for (auto p : plib::pstring_vector_t(f->param_desc(),",") )
for (auto p : plib::psplit(f->param_desc(),",") )
{
if (p.startsWith("+"))
{

View File

@ -48,7 +48,7 @@ static lib_map_t read_lib_map(const pstring lm)
pstring line;
while (reader.readline(line))
{
plib::pstring_vector_t split(line, ",");
std::vector<pstring> split(plib::psplit(line, ","));
m[split[0].trim()] = { split[1].trim(), split[2].trim() };
}
return m;
@ -242,7 +242,7 @@ nl_convert_base_t::unit_t nl_convert_base_t::m_units[] = {
void nl_convert_spice_t::convert(const pstring &contents)
{
plib::pstring_vector_t spnl(contents, "\n");
std::vector<pstring> spnl(plib::psplit(contents, "\n"));
// Add gnd net
@ -274,7 +274,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
{
if (line != "")
{
plib::pstring_vector_t tt(line, " ", true);
std::vector<pstring> tt(plib::psplit(line, " ", true));
double val = 0.0;
switch (tt[0].code_at(0))
{
@ -313,7 +313,7 @@ void nl_convert_spice_t::process_line(const pstring &line)
model = tt[5];
else
model = tt[4];
plib::pstring_vector_t m(model,"{");
std::vector<pstring> m(plib::psplit(model,"{"));
if (m.size() == 2)
{
if (m[1].len() != 4)