mirror of
https://github.com/holub/mame
synced 2025-04-20 07:22:04 +03:00
netlist code maintenance (nw)
- prepare move to c++ streams and later std::string - fix more lint and clang pedantic warnings/errors - fix some bugs
This commit is contained in:
parent
aead1f98f4
commit
8734df72ea
@ -316,7 +316,7 @@ plib::unique_ptr<plib::pistream> netlist_source_memregion_t::stream(const pstrin
|
||||
if (m_dev.has_running_machine())
|
||||
{
|
||||
memory_region *mem = m_dev.memregion(m_name.c_str());
|
||||
return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
|
||||
return plib::make_unique<plib::pistringstream>(pstring(reinterpret_cast<char *>(mem->base()), mem->bytes()));
|
||||
}
|
||||
else
|
||||
throw memregion_not_set("memregion unavailable for {1} in source {2}", name, m_name);
|
||||
@ -354,7 +354,7 @@ plib::unique_ptr<plib::pistream> netlist_data_memregions_t::stream(const pstring
|
||||
{
|
||||
memory_region *mem = m_dev.memregion(name.c_str());
|
||||
if (mem != nullptr)
|
||||
return plib::make_unique<plib::pimemstream>(mem->base(), mem->bytes());
|
||||
return plib::make_unique<plib::pistringstream>(pstring(reinterpret_cast<char *>(mem->base()), mem->bytes()));
|
||||
else
|
||||
return plib::unique_ptr<plib::pistream>(nullptr);
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ TIDY_FLAGSX += -modernize-pass-by-value,-cppcoreguidelines-pro-type-static-cast-
|
||||
TIDY_FLAGSX += -cppcoreguidelines-avoid-magic-numbers,
|
||||
TIDY_FLAGSX += -cppcoreguidelines-macro-usage,
|
||||
TIDY_FLAGSX += -cppcoreguidelines-non-private-member-variables-in-classes,-misc-non-private-member-variables-in-classes,
|
||||
TIDY_FLAGSX += -bugprone-macro-parentheses,-misc-macro-parentheses
|
||||
TIDY_FLAGSX += -bugprone-macro-parentheses,-misc-macro-parentheses,
|
||||
TIDY_FLAGSX += -modernize-use-trailing-return-type
|
||||
|
||||
space :=
|
||||
space +=
|
||||
@ -234,7 +235,7 @@ gcc9:
|
||||
$(MAKE) CC=g++-9 LD=g++-9 CEXTRAFLAGS="-march=native -msse4.2 -Wall -Wpedantic -Wsign-compare -Wextra "
|
||||
|
||||
clang:
|
||||
$(MAKE) CC=clang++-9 LD=clang++-9 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-padded -Wno-weak-vtables -Wno-unused-template -Wno-missing-variable-declarations -Wno-float-equal -Wconversion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-exit-time-destructors"
|
||||
$(MAKE) CC=clang++-10 LD=clang++-10 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-padded -Wno-weak-vtables -Wno-unused-template -Wno-missing-variable-declarations -Wno-float-equal -Wconversion -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-exit-time-destructors"
|
||||
|
||||
clang-5:
|
||||
$(MAKE) CC=clang++-5.0 LD=clang++-5.0 CEXTRAFLAGS="-march=native -Weverything -Werror -Wno-inconsistent-missing-destructor-override -Wno-unreachable-code -Wno-padded -Wno-weak-vtables -Wno-missing-variable-declarations -Wconversion -Wno-c++98-compat -Wno-float-equal -Wno-global-constructors -Wno-c++98-compat-pedantic -Wno-format-nonliteral -Wno-weak-template-vtables -Wno-exit-time-destructors"
|
||||
|
@ -256,22 +256,23 @@ void netlist_state_t::rebuild_lists()
|
||||
|
||||
void netlist_state_t::compile_defines(std::vector<std::pair<pstring, pstring>> &defs)
|
||||
{
|
||||
#define ENTRY(x) { #x, PSTRINGIFY(x) }
|
||||
defs.push_back(ENTRY(PHAS_RDTSCP));
|
||||
defs.push_back(ENTRY(PUSE_ACCURATE_STATS));
|
||||
defs.push_back(ENTRY(PHAS_INT128));
|
||||
defs.push_back(ENTRY(USE_ALIGNED_OPTIMIZATIONS));
|
||||
defs.push_back(ENTRY(NVCCBUILD));
|
||||
defs.push_back(ENTRY(USE_MEMPOOL));
|
||||
defs.push_back(ENTRY(USE_QUEUE_STATS));
|
||||
defs.push_back(ENTRY(USE_COPY_INSTEAD_OF_REFERENCE));
|
||||
defs.push_back(ENTRY(USE_TRUTHTABLE_7448));
|
||||
defs.push_back(ENTRY(NL_DEBUG));
|
||||
defs.push_back(ENTRY(HAS_OPENMP));
|
||||
defs.push_back(ENTRY(USE_OPENMP));
|
||||
//#define ENTRY(x) { #x, PSTRINGIFY(x) }
|
||||
#define ENTRY(x) std::pair<pstring, pstring>(#x, PSTRINGIFY(x))
|
||||
defs.emplace_back(ENTRY(PHAS_RDTSCP));
|
||||
defs.emplace_back(ENTRY(PUSE_ACCURATE_STATS));
|
||||
defs.emplace_back(ENTRY(PHAS_INT128));
|
||||
defs.emplace_back(ENTRY(USE_ALIGNED_OPTIMIZATIONS));
|
||||
defs.emplace_back(ENTRY(NVCCBUILD));
|
||||
defs.emplace_back(ENTRY(USE_MEMPOOL));
|
||||
defs.emplace_back(ENTRY(USE_QUEUE_STATS));
|
||||
defs.emplace_back(ENTRY(USE_COPY_INSTEAD_OF_REFERENCE));
|
||||
defs.emplace_back(ENTRY(USE_TRUTHTABLE_7448));
|
||||
defs.emplace_back(ENTRY(NL_DEBUG));
|
||||
defs.emplace_back(ENTRY(HAS_OPENMP));
|
||||
defs.emplace_back(ENTRY(USE_OPENMP));
|
||||
|
||||
defs.push_back(ENTRY(PPMF_TYPE));
|
||||
defs.push_back(ENTRY(PHAS_PMF_INTERNAL));
|
||||
defs.emplace_back(ENTRY(PPMF_TYPE));
|
||||
defs.emplace_back(ENTRY(PHAS_PMF_INTERNAL));
|
||||
|
||||
#undef ENTRY
|
||||
}
|
||||
|
@ -208,12 +208,15 @@ namespace netlist
|
||||
|
||||
bool nlparse_t::parse_stream(plib::unique_ptr<plib::pistream> &&istrm, const pstring &name)
|
||||
{
|
||||
return parser_t(std::move(plib::ppreprocessor(&m_defines).process(std::move(istrm))), *this).parse(name);
|
||||
plib::ppreprocessor y(&m_defines);
|
||||
plib::ppreprocessor &x(y.process(std::move(istrm)));
|
||||
return parser_t(std::move(x), *this).parse(name);
|
||||
//return parser_t(std::move(plib::ppreprocessor(&m_defines).process(std::move(istrm))), *this).parse(name);
|
||||
}
|
||||
|
||||
void nlparse_t::add_define(const pstring &defstr)
|
||||
{
|
||||
auto p = defstr.find("=");
|
||||
auto p = defstr.find('=');
|
||||
if (p != pstring::npos)
|
||||
add_define(plib::left(defstr, p), defstr.substr(p+1));
|
||||
else
|
||||
@ -351,7 +354,7 @@ std::vector<pstring> setup_t::get_terminals_for_device_name(const pstring &devna
|
||||
if (plib::startsWith(t.second->name(), devname))
|
||||
{
|
||||
pstring tn(t.second->name().substr(devname.length()+1));
|
||||
if (tn.find(".") == pstring::npos)
|
||||
if (tn.find('.') == pstring::npos)
|
||||
terms.push_back(tn);
|
||||
}
|
||||
}
|
||||
@ -362,7 +365,7 @@ std::vector<pstring> setup_t::get_terminals_for_device_name(const pstring &devna
|
||||
{
|
||||
pstring tn(t.first.substr(devname.length()+1));
|
||||
//printf("\t%s %s %s\n", t.first.c_str(), t.second.c_str(), tn.c_str());
|
||||
if (tn.find(".") == pstring::npos)
|
||||
if (tn.find('.') == pstring::npos)
|
||||
{
|
||||
terms.push_back(tn);
|
||||
pstring resolved = resolve_alias(t.first);
|
||||
@ -842,7 +845,7 @@ const log_type &setup_t::log() const
|
||||
|
||||
void models_t::register_model(const pstring &model_in)
|
||||
{
|
||||
auto pos = model_in.find(" ");
|
||||
auto pos = model_in.find(' ');
|
||||
if (pos == pstring::npos)
|
||||
throw nl_exception(MF_UNABLE_TO_PARSE_MODEL_1(model_in));
|
||||
pstring model = plib::ucase(plib::trim(plib::left(model_in, pos)));
|
||||
@ -859,7 +862,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
|
||||
while (true)
|
||||
{
|
||||
pos = model.find("(");
|
||||
pos = model.find('(');
|
||||
if (pos != pstring::npos) break;
|
||||
|
||||
key = plib::ucase(model);
|
||||
@ -890,7 +893,7 @@ void models_t::model_parse(const pstring &model_in, model_map_t &map)
|
||||
std::vector<pstring> pairs(plib::psplit(remainder," ", true));
|
||||
for (pstring &pe : pairs)
|
||||
{
|
||||
auto pose = pe.find("=");
|
||||
auto pose = pe.find('=');
|
||||
if (pose == pstring::npos)
|
||||
throw nl_exception(MF_MODEL_ERROR_ON_PAIR_1(model));
|
||||
map[plib::ucase(plib::left(pe, pose))] = pe.substr(pose + 1);
|
||||
@ -901,7 +904,7 @@ pstring models_t::model_string(model_map_t &map)
|
||||
{
|
||||
pstring ret = map["COREMODEL"] + "(";
|
||||
for (auto & i : map)
|
||||
ret = ret + i.first + "=" + i.second + " ";
|
||||
ret += (i.first + '=' + i.second + ' ');
|
||||
|
||||
return ret + ")";
|
||||
}
|
||||
@ -956,7 +959,7 @@ nl_double models_t::value(const pstring &model, const pstring &entity)
|
||||
// FIXME: check for errors
|
||||
//printf("%s %s %e %e\n", entity.c_str(), tmp.c_str(), plib::pstonum<nl_double>(tmp), factor);
|
||||
bool err(false);
|
||||
nl_double val = plib::pstonum_ne<nl_double, true>(tmp, err);
|
||||
auto val = plib::pstonum_ne<nl_double, true>(tmp, err);
|
||||
if (err)
|
||||
throw nl_exception(MF_MODEL_NUMBER_CONVERSION_ERROR(entity, tmp, "double", model));
|
||||
return val * factor;
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
|
||||
namespace plib {
|
||||
|
||||
@ -42,7 +42,7 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
pfmt::rtype pfmt::setfmt(std::stringstream &strm, char32_t cfmt_spec)
|
||||
{
|
||||
pstring fmt;
|
||||
pstring search("{");
|
||||
@ -50,11 +50,11 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
rtype r;
|
||||
|
||||
r.sl = search.size();
|
||||
r.p = m_str.find(search + ":");
|
||||
r.p = m_str.find(search + ':');
|
||||
r.sl++; // ":"
|
||||
if (r.p == pstring::npos) // no further specifiers
|
||||
{
|
||||
r.p = m_str.find(search + "}");
|
||||
r.p = m_str.find(search + '}');
|
||||
if (r.p == pstring::npos) // not found try default
|
||||
{
|
||||
r.sl = 2;
|
||||
@ -69,7 +69,7 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
r.p = m_str.find("{:");
|
||||
if (r.p != pstring:: npos)
|
||||
{
|
||||
auto p1 = m_str.find("}", r.p);
|
||||
auto p1 = m_str.find('}', r.p);
|
||||
if (p1 != pstring::npos)
|
||||
{
|
||||
r.sl = p1 - r.p + 1;
|
||||
@ -81,7 +81,7 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
else
|
||||
{
|
||||
// found absolute positional place holder
|
||||
auto p1 = m_str.find("}", r.p);
|
||||
auto p1 = m_str.find('}', r.p);
|
||||
if (p1 != pstring::npos)
|
||||
{
|
||||
r.sl = p1 - r.p + 1;
|
||||
@ -92,11 +92,11 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
if (r.p != pstring::npos)
|
||||
{
|
||||
// a.b format here ...
|
||||
if (fmt != "" && pstring("duxofge").find(cfmt_spec) != pstring::npos)
|
||||
if (fmt != "" && pstring("duxofge").find(static_cast<pstring::value_type>(cfmt_spec)) != pstring::npos)
|
||||
{
|
||||
r.pend = fmt.at(fmt.size() - 1);
|
||||
if (pstring("duxofge").find(r.pend) == pstring::npos)
|
||||
r.pend = static_cast<pstring::value_type>(cfmt_spec);
|
||||
r.pend = static_cast<char32_t>(fmt.at(fmt.size() - 1));
|
||||
if (pstring("duxofge").find(static_cast<pstring::value_type>(r.pend)) == pstring::npos)
|
||||
r.pend = cfmt_spec;
|
||||
else
|
||||
fmt = plib::left(fmt, fmt.size() - 1);
|
||||
}
|
||||
@ -104,16 +104,19 @@ pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
|
||||
// FIXME: Error
|
||||
r.pend = cfmt_spec;
|
||||
|
||||
int pdot(fmt.find('.'));
|
||||
auto pdot(fmt.find('.'));
|
||||
|
||||
if (pdot==0)
|
||||
strm << std::setprecision(pstonum<int>(fmt.substr(1)));
|
||||
else if (r.p != pstring::npos)
|
||||
else if (pdot != pstring::npos)
|
||||
{
|
||||
strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))) << std::setw(pstonum<int>(left(fmt,pdot)));
|
||||
//strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))) << std::setw(pstonum<int>(left(fmt,pdot)));
|
||||
strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1)));
|
||||
r.width = pstonum<pstring::size_type>(left(fmt,pdot));
|
||||
}
|
||||
else if (fmt != "")
|
||||
strm << std::setw(pstonum<int>(fmt));
|
||||
//strm << std::setw(pstonum<int>(fmt));
|
||||
r.width = pstonum<pstring::size_type>(fmt);
|
||||
|
||||
switch (r.pend)
|
||||
{
|
||||
|
@ -148,7 +148,7 @@ public:
|
||||
: m_str(fmt), m_locale(std::locale::classic()), m_arg(0)
|
||||
{
|
||||
}
|
||||
explicit pfmt(std::locale loc, const pstring &fmt)
|
||||
explicit pfmt(const std::locale &loc, const pstring &fmt)
|
||||
: m_str(fmt), m_locale(loc), m_arg(0)
|
||||
{
|
||||
}
|
||||
@ -212,21 +212,28 @@ public:
|
||||
return format_element('o', x);
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &ostrm, const pfmt &fmt)
|
||||
{
|
||||
ostrm << fmt.m_str;
|
||||
return ostrm;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
struct rtype
|
||||
{
|
||||
rtype() : ret(0), p(0), sl(0), pend(0) {}
|
||||
rtype() : ret(0), p(0), sl(0), pend(0), width(0) {}
|
||||
int ret;
|
||||
pstring::size_type p;
|
||||
pstring::size_type sl;
|
||||
pstring::value_type pend;
|
||||
char32_t pend;
|
||||
pstring::size_type width;
|
||||
|
||||
};
|
||||
rtype setfmt(std::stringstream &strm, unsigned cfmt_spec);
|
||||
rtype setfmt(std::stringstream &strm, char32_t cfmt_spec);
|
||||
|
||||
template <typename T>
|
||||
pfmt &format_element(const unsigned cfmt_spec, T &&val)
|
||||
pfmt &format_element(const char32_t cfmt_spec, T &&val)
|
||||
{
|
||||
rtype ret;
|
||||
|
||||
@ -239,7 +246,12 @@ protected:
|
||||
if (ret.ret>=0)
|
||||
{
|
||||
strm << std::forward<T>(val);
|
||||
m_str = m_str.substr(0, ret.p) + pstring(strm.str()) + m_str.substr(ret.p + ret.sl);
|
||||
const pstring ps(strm.str());
|
||||
pstring pad("");
|
||||
if (ret.width > ps.length())
|
||||
pad = pstring(ret.width - ps.length(), ' ');
|
||||
|
||||
m_str = m_str.substr(0, ret.p) + pad + ps + m_str.substr(ret.p + ret.sl);
|
||||
}
|
||||
} while (ret.ret == 1);
|
||||
|
||||
|
@ -63,7 +63,7 @@ void pfunction::compile_postfix(const std::vector<pstring> &inputs,
|
||||
if (inputs[i] == cmd)
|
||||
{
|
||||
rc.m_cmd = PUSH_INPUT;
|
||||
rc.m_param = i;
|
||||
rc.m_param = static_cast<double>(i);
|
||||
stk += 1;
|
||||
break;
|
||||
}
|
||||
|
@ -35,10 +35,15 @@ namespace plib {
|
||||
|
||||
app::app()
|
||||
: options()
|
||||
#if !USE_CSTREAM
|
||||
, pout_strm()
|
||||
, perr_strm()
|
||||
, pout(&pout_strm)
|
||||
, perr(&perr_strm)
|
||||
#else
|
||||
, pout(&std::cout)
|
||||
, perr(&std::cerr)
|
||||
#endif
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -44,10 +44,10 @@ namespace plib {
|
||||
|
||||
virtual pstring usage() = 0;
|
||||
virtual int execute() = 0;
|
||||
|
||||
#if !USE_CSTREAM
|
||||
plib::pstdout pout_strm;
|
||||
plib::pstderr perr_strm;
|
||||
|
||||
#endif
|
||||
plib::putf8_fmt_writer pout;
|
||||
plib::putf8_fmt_writer perr;
|
||||
|
||||
|
@ -10,8 +10,9 @@
|
||||
#define POMP_H_
|
||||
|
||||
#include "pconfig.h"
|
||||
#include "ptypes.h"
|
||||
|
||||
//#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#if HAS_OPENMP
|
||||
#include "omp.h"
|
||||
|
@ -118,7 +118,7 @@ namespace plib {
|
||||
if (has_equal_arg)
|
||||
{
|
||||
for (std::size_t j = 1; j < v.size() - 1; j++)
|
||||
opt_arg = opt_arg + v[j] + "=";
|
||||
opt_arg += (v[j] + "=");
|
||||
opt_arg += v[v.size()-1];
|
||||
}
|
||||
}
|
||||
|
@ -264,7 +264,11 @@ void ptokenizer::error(const pstring &errs)
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
ppreprocessor::ppreprocessor(defines_map_type *defines)
|
||||
#if !USE_CSTREAM
|
||||
: pistream()
|
||||
#else
|
||||
: pistream(new st(this))
|
||||
#endif
|
||||
, m_ifflag(0)
|
||||
, m_level(0)
|
||||
, m_lineno(0)
|
||||
@ -296,9 +300,10 @@ void ppreprocessor::error(const pstring &err)
|
||||
throw pexception("PREPRO ERROR: " + err);
|
||||
}
|
||||
|
||||
#if !USE_CSTREAM
|
||||
pstream::size_type ppreprocessor::vread(char_type *buf, const pstream::size_type n)
|
||||
{
|
||||
size_type bytes = std::min(m_buf.size() - m_pos, n);
|
||||
size_type bytes = std::min(m_buf.size() - m_pos, static_cast<std::size_t>(n));
|
||||
|
||||
if (bytes==0)
|
||||
return 0;
|
||||
@ -307,6 +312,7 @@ pstream::size_type ppreprocessor::vread(char_type *buf, const pstream::size_type
|
||||
m_pos += bytes;
|
||||
return bytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define CHECKTOK2(p_op, p_prio) \
|
||||
else if (tok == # p_op) \
|
||||
|
@ -22,7 +22,12 @@ class ptokenizer
|
||||
public:
|
||||
template <typename T>
|
||||
ptokenizer(T &&strm) // NOLINT(misc-forwarding-reference-overload, bugprone-forwarding-reference-overload)
|
||||
: m_strm(std::forward<T>(strm)), m_lineno(0), m_cur_line(""), m_px(m_cur_line.begin()), m_unget(0), m_string('"')
|
||||
: m_strm(std::forward<T>(strm))
|
||||
, m_lineno(0)
|
||||
, m_cur_line("")
|
||||
, m_px(m_cur_line.begin())
|
||||
, m_unget(0)
|
||||
, m_string('"')
|
||||
{
|
||||
}
|
||||
|
||||
@ -153,7 +158,11 @@ private:
|
||||
};
|
||||
|
||||
|
||||
#if !USE_CSTREAM
|
||||
class ppreprocessor : public pistream
|
||||
#else
|
||||
class ppreprocessor : public /*std::streambuf,*/ pistream
|
||||
#endif
|
||||
{
|
||||
public:
|
||||
|
||||
@ -169,8 +178,14 @@ public:
|
||||
using defines_map_type = std::unordered_map<pstring, define_t>;
|
||||
|
||||
explicit ppreprocessor(defines_map_type *defines = nullptr);
|
||||
#if !USE_CSTREAM
|
||||
~ppreprocessor() override = default;
|
||||
|
||||
#else
|
||||
~ppreprocessor() override
|
||||
{
|
||||
delete rdbuf();
|
||||
}
|
||||
#endif
|
||||
template <typename T>
|
||||
ppreprocessor & process(T &&istrm)
|
||||
{
|
||||
@ -190,7 +205,13 @@ public:
|
||||
|
||||
|
||||
ppreprocessor(ppreprocessor &&s) noexcept
|
||||
: m_defines(std::move(s.m_defines))
|
||||
//: pistream(s.rdbuf())
|
||||
#if !USE_CSTREAM
|
||||
: pistream()
|
||||
#else
|
||||
: pistream(new st(this))
|
||||
#endif
|
||||
, m_defines(std::move(s.m_defines))
|
||||
, m_expr_sep(std::move(s.m_expr_sep))
|
||||
, m_ifflag(s.m_ifflag)
|
||||
, m_level(s.m_level)
|
||||
@ -204,14 +225,46 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
size_type vread(char_type *buf, const size_type n) override;
|
||||
#if !USE_CSTREAM
|
||||
size_type vread(char_type *buf, const pos_type n) override;
|
||||
void vseek(const pos_type n) override
|
||||
{
|
||||
plib::unused_var(n);
|
||||
/* FIXME throw exception - should be done in base unless implemented */
|
||||
}
|
||||
pos_type vtell() const override { return m_pos; }
|
||||
#else
|
||||
class st : public std::streambuf
|
||||
{
|
||||
public:
|
||||
st(ppreprocessor *strm) : m_strm(strm) { setg(nullptr, nullptr, nullptr); }
|
||||
st(st &&rhs) noexcept : m_strm(rhs.m_strm) {}
|
||||
int_type underflow() override
|
||||
{
|
||||
//printf("here\n");
|
||||
if (this->gptr() == this->egptr())
|
||||
{
|
||||
/* clang reports sign error - weird */
|
||||
std::size_t bytes = pstring_mem_t_size(m_strm->m_buf) - static_cast<std::size_t>(m_strm->m_pos);
|
||||
|
||||
if (bytes > m_buf.size())
|
||||
bytes = m_buf.size();
|
||||
std::copy(m_strm->m_buf.c_str() + m_strm->m_pos, m_strm->m_buf.c_str() + m_strm->m_pos + bytes, m_buf.data());
|
||||
//printf("%ld\n", (long int)bytes);
|
||||
this->setg(m_buf.data(), m_buf.data(), m_buf.data() + bytes);
|
||||
|
||||
m_strm->m_pos += static_cast</*pos_type*/long>(bytes);
|
||||
}
|
||||
return this->gptr() == this->egptr()
|
||||
? std::char_traits<char>::eof()
|
||||
: std::char_traits<char>::to_int_type(*this->gptr());
|
||||
}
|
||||
private:
|
||||
ppreprocessor *m_strm;
|
||||
std::array<char_type, 1024> m_buf;
|
||||
};
|
||||
//friend class st;
|
||||
#endif
|
||||
int expr(const std::vector<pstring> &sexpr, std::size_t &start, int prio);
|
||||
define_t *get_define(const pstring &name);
|
||||
pstring replace_macros(const pstring &line);
|
||||
@ -224,6 +277,7 @@ private:
|
||||
PROCESS,
|
||||
LINE_CONTINUATION
|
||||
};
|
||||
|
||||
pstring process_line(pstring line);
|
||||
pstring process_comments(pstring line);
|
||||
|
||||
@ -234,7 +288,7 @@ private:
|
||||
int m_level;
|
||||
int m_lineno;
|
||||
pstring_t<pu8_traits> m_buf;
|
||||
pos_type m_pos;
|
||||
pistream::pos_type m_pos;
|
||||
state_e m_state;
|
||||
pstring m_line;
|
||||
bool m_comment;
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "pconfig.h"
|
||||
|
||||
//#include <cstdint>
|
||||
#include <cstdint> // uintptr_t
|
||||
#include <utility>
|
||||
|
||||
/*
|
||||
|
@ -33,6 +33,8 @@ namespace plib {
|
||||
// Input file stream
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if !USE_CSTREAM
|
||||
|
||||
pifilestream::pifilestream(const pstring &fname)
|
||||
: pistream(0)
|
||||
, m_file(fopen(fname.c_str(), "rb"))
|
||||
@ -119,6 +121,7 @@ pstdin::pstdin()
|
||||
{
|
||||
/* nothing to do */
|
||||
}
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Output file stream
|
||||
@ -223,13 +226,11 @@ pstream::pos_type pomemstream::vtell() const
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// pstderr: write to stderr
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if 1
|
||||
pstderr::pstderr()
|
||||
#ifdef _WIN32
|
||||
: pofilestream(fdopen(_dup(fileno(stderr)), "wb"), "<stderr>", true)
|
||||
@ -252,6 +253,9 @@ pstdout::pstdout()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !USE_CSTREAM
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Memory stream
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -299,7 +303,7 @@ pimemstream::pos_type pimemstream::vtell() const
|
||||
{
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool putf8_reader::readline(pstring &line)
|
||||
{
|
||||
|
@ -19,20 +19,27 @@
|
||||
#include <array>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
#include <ios>
|
||||
|
||||
#if USE_CSTREAM
|
||||
#include <fstream>
|
||||
//#include <strstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#endif
|
||||
|
||||
namespace plib {
|
||||
|
||||
#if USE_CSTREAM
|
||||
typedef std::ostream postream;
|
||||
typedef std::ofstream pofilestream;
|
||||
typedef std::ostringstream postringstream;
|
||||
typedef std::ostringstream pomemstream;
|
||||
using postream = std::ostream;
|
||||
using pofilestream = std::ofstream;
|
||||
using postringstream = std::ostringstream;
|
||||
using pomemstream = std::ostringstream;
|
||||
|
||||
using pistream = std::istream;
|
||||
using pifilestream = std::ifstream;
|
||||
using pistringstream = std::istringstream;
|
||||
using pimemstream = std::istringstream;
|
||||
|
||||
#endif
|
||||
|
||||
@ -44,8 +51,8 @@ class pstream
|
||||
{
|
||||
public:
|
||||
|
||||
using pos_type = std::size_t;
|
||||
using size_type = std::size_t;
|
||||
using pos_type = std::streamsize;
|
||||
using size_type = std::streamsize;
|
||||
|
||||
static constexpr pos_type SEEK_EOF = static_cast<pos_type>(-1);
|
||||
|
||||
@ -95,6 +102,8 @@ private:
|
||||
unsigned m_flags;
|
||||
};
|
||||
|
||||
#if !USE_CSTREAM
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// pistream: input stream
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -133,7 +142,6 @@ using pistream = pistream_base<char>;
|
||||
// postream: output stream
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
#if !USE_CSTREAM
|
||||
template <typename T>
|
||||
class postream_base : public pstream
|
||||
{
|
||||
@ -195,7 +203,7 @@ public:
|
||||
~pomemstream() override = default;
|
||||
|
||||
const char *memory() const { return m_mem.data(); }
|
||||
pos_type size() const { return m_mem.size(); }
|
||||
pos_type size() const { return static_cast<pos_type>(m_mem.size()); }
|
||||
|
||||
protected:
|
||||
/* write n bytes to stream */
|
||||
@ -230,10 +238,10 @@ protected:
|
||||
void vwrite(const char_type *buf, const pos_type n) override
|
||||
{
|
||||
//m_buf += pstring(reinterpret_cast<const pstring::mem_t *>(buf), n);
|
||||
m_buf += pstring(buf, n);
|
||||
m_buf += pstring(buf, static_cast<pstring::size_type>(n));
|
||||
}
|
||||
void vseek(const pos_type n) override { unused_var(n); }
|
||||
pos_type vtell() const override { return m_buf.size(); }
|
||||
pos_type vtell() const override { return static_cast<pos_type>(m_buf.size()); }
|
||||
|
||||
private:
|
||||
pstring m_buf;
|
||||
@ -282,7 +290,6 @@ private:
|
||||
// -----------------------------------------------------------------------------
|
||||
// pstderr: write to stderr
|
||||
// -----------------------------------------------------------------------------
|
||||
#endif
|
||||
|
||||
class pstderr : public pofilestream
|
||||
{
|
||||
@ -310,6 +317,7 @@ public:
|
||||
~pstdout() noexcept override = default;
|
||||
};
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// pifilestream: file input stream
|
||||
// -----------------------------------------------------------------------------
|
||||
@ -423,12 +431,12 @@ public:
|
||||
: pimemstream()
|
||||
, m_str(str)
|
||||
{
|
||||
set_mem(m_str.c_str(), pstring_mem_t_size(m_str));
|
||||
set_mem(m_str.c_str(), static_cast<pos_type>(pstring_mem_t_size(m_str)));
|
||||
}
|
||||
pistringstream(pistringstream &&src) noexcept
|
||||
: pimemstream(std::move(src)), m_str(src.m_str)
|
||||
{
|
||||
set_mem(m_str.c_str(), pstring_mem_t_size(m_str));
|
||||
set_mem(m_str.c_str(), static_cast<pos_type>(pstring_mem_t_size(m_str)));
|
||||
}
|
||||
COPYASSIGN(pistringstream, delete)
|
||||
pistringstream &operator=(pistringstream &&src) = delete;
|
||||
@ -439,6 +447,7 @@ private:
|
||||
/* only needed for a reference till destruction */
|
||||
const pstring m_str;
|
||||
};
|
||||
#endif
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// putf8reader_t: reader on top of istream
|
||||
@ -473,6 +482,8 @@ public:
|
||||
bool eof() const { return m_strm->eof(); }
|
||||
bool readline(pstring &line);
|
||||
|
||||
|
||||
#if !USE_CSTREAM
|
||||
bool readbyte1(pistream::char_type &b)
|
||||
{
|
||||
return (m_strm->read(&b, 1) == 1);
|
||||
@ -490,7 +501,32 @@ public:
|
||||
c = putf8string::traits_type::code(reinterpret_cast<putf8string::traits_type::mem_t *>(&b));
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool readbyte1(pistream::char_type &b)
|
||||
{
|
||||
if (m_strm->eof())
|
||||
return false;
|
||||
m_strm->read(&b, 1);
|
||||
return true;
|
||||
}
|
||||
bool readcode(putf8string::traits_type::code_t &c)
|
||||
{
|
||||
std::array<pistream::char_type, 4> b{0};
|
||||
if (m_strm->eof())
|
||||
return false;
|
||||
m_strm->read(&b[0], 1);
|
||||
const std::size_t l = putf8string::traits_type::codelen(reinterpret_cast<putf8string::traits_type::mem_t *>(&b));
|
||||
for (std::size_t i = 1; i < l; i++)
|
||||
{
|
||||
if (m_strm->eof())
|
||||
return false;
|
||||
m_strm->read(&b[i], 1);
|
||||
}
|
||||
c = putf8string::traits_type::code(reinterpret_cast<putf8string::traits_type::mem_t *>(&b));
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif
|
||||
private:
|
||||
plib::unique_ptr<pistream> m_strm;
|
||||
putf8string m_linebuf;
|
||||
@ -535,7 +571,7 @@ public:
|
||||
{
|
||||
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
|
||||
const putf8string conv_utf8(text);
|
||||
m_strm->write(conv_utf8.c_str(), plib::strlen(conv_utf8.c_str()));
|
||||
m_strm->write(conv_utf8.c_str(), static_cast<std::streamsize>(plib::strlen(conv_utf8.c_str())));
|
||||
}
|
||||
|
||||
void write(const pstring::value_type c) const
|
||||
@ -592,7 +628,7 @@ public:
|
||||
void write(const pstring &s)
|
||||
{
|
||||
const auto sm = reinterpret_cast<const postream::char_type *>(s.c_str());
|
||||
const std::size_t sl(pstring_mem_t_size(s));
|
||||
const std::streamsize sl(static_cast<std::streamsize>(pstring_mem_t_size(s)));
|
||||
write(sl);
|
||||
m_strm.write(sm, sl);
|
||||
}
|
||||
@ -600,9 +636,9 @@ public:
|
||||
template <typename T>
|
||||
void write(const std::vector<T> &val)
|
||||
{
|
||||
std::size_t sz = val.size();
|
||||
const std::streamsize sz(static_cast<std::streamsize>(val.size()));
|
||||
write(sz);
|
||||
m_strm.write(reinterpret_cast<const postream::char_type *>(val.data()), sizeof(T) * sz);
|
||||
m_strm.write(reinterpret_cast<const postream::char_type *>(val.data()), sz * static_cast<std::streamsize>(sizeof(T)));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -631,7 +667,7 @@ public:
|
||||
std::size_t sz = 0;
|
||||
read(sz);
|
||||
std::vector<plib::string_info<pstring>::mem_t> buf(sz+1);
|
||||
m_strm.read(buf.data(), sz);
|
||||
m_strm.read(buf.data(), static_cast<std::streamsize>(sz));
|
||||
buf[sz] = 0;
|
||||
s = pstring(buf.data());
|
||||
}
|
||||
@ -642,7 +678,7 @@ public:
|
||||
std::size_t sz = 0;
|
||||
read(sz);
|
||||
val.resize(sz);
|
||||
m_strm.read(reinterpret_cast<pistream::char_type *>(val.data()), sizeof(T) * sz);
|
||||
m_strm.read(reinterpret_cast<pistream::char_type *>(val.data()), static_cast<std::streamsize>(sizeof(T) * sz));
|
||||
}
|
||||
|
||||
private:
|
||||
@ -651,10 +687,20 @@ private:
|
||||
|
||||
inline void copystream(postream &dest, pistream &src)
|
||||
{
|
||||
// FIXME: optimize
|
||||
#if !USE_CSTREAM
|
||||
std::array<postream::char_type, 1024> buf; // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
pstream::pos_type r;
|
||||
while ((r=src.read(buf.data(), 1024)) > 0)
|
||||
dest.write(buf.data(), r);
|
||||
#else
|
||||
std::array<postream::char_type, 1024> buf; // NOLINT(cppcoreguidelines-pro-type-member-init)
|
||||
while (!src.eof())
|
||||
{
|
||||
src.read(buf.data(), 1);
|
||||
dest.write(buf.data(), 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct perrlogger
|
||||
@ -667,8 +713,12 @@ struct perrlogger
|
||||
private:
|
||||
static putf8_fmt_writer &h()
|
||||
{
|
||||
#if !USE_CSTREAM
|
||||
static plib::pstderr perr_strm;
|
||||
static plib::putf8_fmt_writer perr(&perr_strm);
|
||||
#else
|
||||
static plib::putf8_fmt_writer perr(&std::cerr);
|
||||
#endif
|
||||
return perr;
|
||||
}
|
||||
};
|
||||
|
@ -186,6 +186,7 @@ public:
|
||||
pstring_t& operator+=(const code_t c) { traits_type::encode(c, m_str); return *this; }
|
||||
friend pstring_t operator+(const pstring_t &lhs, const pstring_t &rhs) { return pstring_t(lhs) += rhs; }
|
||||
friend pstring_t operator+(const pstring_t &lhs, const code_t rhs) { return pstring_t(lhs) += rhs; }
|
||||
friend pstring_t operator+(const code_t lhs, const pstring_t &rhs) { return pstring_t(1, lhs) += rhs; }
|
||||
|
||||
// comparison operators
|
||||
bool operator==(const pstring_t &string) const { return (compare(string) == 0); }
|
||||
@ -196,6 +197,12 @@ public:
|
||||
bool operator>(const pstring_t &string) const { return (compare(string) > 0); }
|
||||
bool operator>=(const pstring_t &string) const { return (compare(string) >= 0); }
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &ostrm, const pstring_t &str)
|
||||
{
|
||||
ostrm << str.m_str;
|
||||
return ostrm;
|
||||
}
|
||||
|
||||
const_reference at(const size_type pos) const { return *reinterpret_cast<const ref_value_type *>(F::nthcode(m_str.c_str(),pos)); }
|
||||
|
||||
static constexpr const size_type npos = static_cast<size_type>(-1);
|
||||
@ -475,11 +482,12 @@ extern template struct pstring_t<putf16_traits>;
|
||||
extern template struct pstring_t<pwchar_traits>;
|
||||
|
||||
#if (PSTRING_USE_STD_STRING)
|
||||
typedef std::string pstring;
|
||||
using pstring = std::string;
|
||||
static inline pstring::size_type pstring_mem_t_size(const pstring &s) { return s.size(); }
|
||||
#else
|
||||
using pstring = pstring_t<putf8_traits>;
|
||||
static inline pstring::size_type pstring_mem_t_size(const pstring &s) { return s.mem_t_size(); }
|
||||
template <typename T>
|
||||
static inline pstring::size_type pstring_mem_t_size(const pstring_t<T> &s) { return s.mem_t_size(); }
|
||||
#endif
|
||||
using putf8string = pstring_t<putf8_traits>;
|
||||
using pu16string = pstring_t<putf16_traits>;
|
||||
@ -618,7 +626,7 @@ namespace plib
|
||||
const T *p = str;
|
||||
while (*p)
|
||||
p++;
|
||||
return p - str;
|
||||
return static_cast<std::size_t>(p - str);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
@ -25,7 +25,7 @@ namespace plib
|
||||
#ifdef _WIN32
|
||||
ret = ret + '\\' + elem;
|
||||
#else
|
||||
ret = ret + '/' + elem;
|
||||
ret += ('/' + elem);
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
@ -137,7 +137,7 @@ namespace plib
|
||||
int penum_base::from_string_int(const char *str, const char *x)
|
||||
{
|
||||
int cnt = 0;
|
||||
for (auto s : psplit(str, ",", false))
|
||||
for (auto &s : psplit(str, ",", false))
|
||||
{
|
||||
if (s == x)
|
||||
return cnt;
|
||||
|
@ -12,9 +12,10 @@
|
||||
#include "pstring.h"
|
||||
#include <algorithm>
|
||||
#include <initializer_list>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <locale>
|
||||
#include <iostream>
|
||||
|
||||
#define PSTRINGIFY_HELP(y) # y
|
||||
#define PSTRINGIFY(x) PSTRINGIFY_HELP(x)
|
||||
@ -131,16 +132,16 @@ namespace plib
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
template <typename T, typename S>
|
||||
T pstonum_locale(std::locale loc, const S &arg, std::size_t *idx)
|
||||
T pstonum_locale(const std::locale &loc, const S &arg, std::size_t *idx)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss.imbue(loc);
|
||||
ss << arg;
|
||||
long int len(ss.tellp());
|
||||
auto x(constants<long double>::zero());
|
||||
auto len(ss.tellp());
|
||||
T x(constants<T>::zero());
|
||||
if (ss >> x)
|
||||
{
|
||||
long int pos(ss.tellg());
|
||||
auto pos(ss.tellg());
|
||||
if (pos == -1)
|
||||
pos = len;
|
||||
*idx = static_cast<std::size_t>(pos);
|
||||
@ -155,7 +156,7 @@ namespace plib
|
||||
struct pstonum_helper;
|
||||
|
||||
template<typename T>
|
||||
struct pstonum_helper<T, typename std::enable_if<std::is_integral<T>::value>::type>
|
||||
struct pstonum_helper<T, typename std::enable_if<std::is_integral<T>::value && std::is_signed<T>::value>::type>
|
||||
{
|
||||
template <typename S>
|
||||
long long operator()(std::locale loc, const S &arg, std::size_t *idx)
|
||||
@ -165,6 +166,17 @@ namespace plib
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pstonum_helper<T, typename std::enable_if<std::is_integral<T>::value && !std::is_signed<T>::value>::type>
|
||||
{
|
||||
template <typename S>
|
||||
unsigned long long operator()(std::locale loc, const S &arg, std::size_t *idx)
|
||||
{
|
||||
//return std::stoll(arg, idx);
|
||||
return pstonum_locale<unsigned long long>(loc, arg, idx);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
struct pstonum_helper<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
|
||||
{
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "pconfig.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <type_traits>
|
||||
|
||||
|
@ -16,6 +16,8 @@
|
||||
#include "netlist/tools/nl_convert.h"
|
||||
|
||||
#include <cstdio> // scanf
|
||||
#include <iomanip> // scanf
|
||||
#include <iostream> // scanf
|
||||
|
||||
#define NLTOOL_VERSION 20190420
|
||||
|
||||
@ -486,14 +488,13 @@ void tool_app_t::static_compile()
|
||||
|
||||
// no reset needed ...
|
||||
|
||||
plib::putf8_writer w(&pout_strm);
|
||||
std::map<pstring, pstring> mp;
|
||||
|
||||
nt.solver()->create_solver_code(mp);
|
||||
|
||||
for (auto &e : mp)
|
||||
{
|
||||
w.write(e.second);
|
||||
pout.write(e.second);
|
||||
}
|
||||
|
||||
nt.stop();
|
||||
@ -730,15 +731,19 @@ void tool_app_t::convert()
|
||||
plib::postringstream ostrm;
|
||||
if (opt_file() == "-")
|
||||
{
|
||||
#if !USE_CSTREAM
|
||||
plib::pstdin f;
|
||||
plib::copystream(ostrm, f);
|
||||
#else
|
||||
plib::copystream(ostrm, std::cin);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
plib::pifilestream f(opt_file());
|
||||
plib::copystream(ostrm, f);
|
||||
}
|
||||
contents = ostrm.str();
|
||||
contents = pstring(ostrm.str());
|
||||
|
||||
pstring result;
|
||||
if (opt_type.as_string() == "spice")
|
||||
@ -859,7 +864,19 @@ int tool_app_t::execute()
|
||||
perr("plib exception caught: {}\n", e.text());
|
||||
return 2;
|
||||
}
|
||||
#if 1
|
||||
std::cout.imbue(std::locale("de_DE.utf8"));
|
||||
std::cout.imbue(std::locale("C.UTF-8"));
|
||||
std::cout << std::fixed << 20.003 << "\n";
|
||||
std::cout << std::setw(20) << std::left << "01234567890" << "|" << "\n";
|
||||
std::cout << std::setw(20) << "Общая ком" << "|" << "\n";
|
||||
std::cout << "Общая ком" << pstring(20 - pstring("Общая ком").length(), ' ') << "|" << "\n";
|
||||
std::cout << plib::pfmt("{:20}")("Общая ком") << "|" << "\n";
|
||||
|
||||
//char x = 'a';
|
||||
auto b= U'щ';
|
||||
std::cout << "b: <" << b << ">";
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,12 @@ class wav_t
|
||||
{
|
||||
public:
|
||||
// XXNOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
|
||||
wav_t(plib::postream &strm, std::size_t sr, std::size_t channels)
|
||||
wav_t(plib::postream &strm, bool is_seekable, std::size_t sr, std::size_t channels)
|
||||
: m_f(strm)
|
||||
, m_stream_is_seekable(is_seekable)
|
||||
/* force "play" to play and warn about eof instead of being silent */
|
||||
, m_fmt(static_cast<std::uint16_t>(channels), static_cast<std::uint32_t>(sr))
|
||||
, m_data(m_f.seekable() ? 0 : 0xffffffff)
|
||||
, m_data(is_seekable ? 0 : 0xffffffff)
|
||||
{
|
||||
|
||||
write(m_fh);
|
||||
@ -40,7 +41,7 @@ public:
|
||||
|
||||
~wav_t()
|
||||
{
|
||||
if (m_f.seekable())
|
||||
if (m_stream_is_seekable)
|
||||
{
|
||||
m_fh.filelen = m_data.len + sizeof(m_data) + sizeof(m_fh) + sizeof(m_fmt) - 8;
|
||||
m_f.seekp(0);
|
||||
@ -107,6 +108,7 @@ private:
|
||||
};
|
||||
|
||||
plib::postream &m_f;
|
||||
bool m_stream_is_seekable;
|
||||
|
||||
riff_chunk_t m_fh;
|
||||
riff_format_t m_fmt;
|
||||
@ -238,7 +240,7 @@ private:
|
||||
class wavwriter
|
||||
{
|
||||
public:
|
||||
wavwriter(plib::postream &fo, std::size_t channels, std::size_t sample_rate, double ampa)
|
||||
wavwriter(plib::postream &fo, bool is_seekable, std::size_t channels, std::size_t sample_rate, double ampa)
|
||||
: mean(channels, 0.0)
|
||||
, means(channels, 0.0)
|
||||
, maxsam(channels, -1e9)
|
||||
@ -248,7 +250,7 @@ public:
|
||||
, m_last_time(0)
|
||||
, m_fo(fo)
|
||||
, m_amp(ampa)
|
||||
, m_wo(m_fo, sample_rate, channels)
|
||||
, m_wo(m_fo, is_seekable, sample_rate, channels)
|
||||
{ }
|
||||
|
||||
void process(std::size_t chan, double time, double outsam)
|
||||
@ -355,7 +357,7 @@ public:
|
||||
private:
|
||||
void write(const pstring &line)
|
||||
{
|
||||
m_fo.write(line.c_str(), plib::strlen(line.c_str()));
|
||||
m_fo.write(line.c_str(), static_cast<std::streamsize>(plib::strlen(line.c_str())));
|
||||
}
|
||||
|
||||
std::size_t m_channels;
|
||||
@ -418,8 +420,9 @@ private:
|
||||
plib::option_bool opt_help;
|
||||
plib::option_example opt_ex1;
|
||||
plib::option_example opt_ex2;
|
||||
#if !USE_CSTREAM
|
||||
plib::pstdin pin_strm;
|
||||
|
||||
#endif
|
||||
std::vector<plib::unique_ptr<plib::pistream>> m_instrms;
|
||||
plib::postream *m_outstrm;
|
||||
};
|
||||
@ -429,7 +432,7 @@ void nlwav_app::convert_wav()
|
||||
|
||||
double dt = 1.0 / static_cast<double>(opt_rate());
|
||||
|
||||
plib::unique_ptr<wavwriter> wo = plib::make_unique<wavwriter>(*m_outstrm, m_instrms.size(), opt_rate(), opt_amp());
|
||||
plib::unique_ptr<wavwriter> wo = plib::make_unique<wavwriter>(*m_outstrm, opt_out() != "-", m_instrms.size(), opt_rate(), opt_amp());
|
||||
plib::unique_ptr<aggregator> ago = plib::make_unique<aggregator>(m_instrms.size(), dt, aggregator::callback_type(&wavwriter::process, wo.get()));
|
||||
aggregator::callback_type agcb = log_processor::callback_type(&aggregator::process, ago.get());
|
||||
|
||||
@ -499,13 +502,22 @@ int nlwav_app::execute()
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if !USE_CSTREAM
|
||||
m_outstrm = (opt_out() == "-" ? &pout_strm : plib::pnew<plib::pofilestream>(opt_out()));
|
||||
#else
|
||||
m_outstrm = (opt_out() == "-" ? &std::cout : plib::pnew<plib::pofilestream>(opt_out()));
|
||||
#endif
|
||||
|
||||
for (auto &oi: opt_args())
|
||||
{
|
||||
#if !USE_CSTREAM
|
||||
plib::unique_ptr<plib::pistream> fin = (oi == "-" ?
|
||||
plib::make_unique<plib::pstdin>()
|
||||
: plib::make_unique<plib::pifilestream>(oi));
|
||||
#else
|
||||
//FIXME:
|
||||
plib::unique_ptr<plib::pistream> fin = plib::make_unique<plib::pifilestream>(oi);
|
||||
#endif
|
||||
m_instrms.push_back(std::move(fin));
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,26 @@ nl_convert_base_t::nl_convert_base_t()
|
||||
: out(&m_buf)
|
||||
, m_numberchars("0123456789-+e.")
|
||||
{
|
||||
m_units = {
|
||||
{"T", "", 1.0e12 },
|
||||
{"G", "", 1.0e9 },
|
||||
{"MEG", "RES_M({1})", 1.0e6 },
|
||||
{"k", "RES_K({1})", 1.0e3 }, /* eagle */
|
||||
{"K", "RES_K({1})", 1.0e3 },
|
||||
{"", "{1}", 1.0e0 },
|
||||
{"M", "CAP_M({1})", 1.0e-3 },
|
||||
{"u", "CAP_U({1})", 1.0e-6 }, /* eagle */
|
||||
{"U", "CAP_U({1})", 1.0e-6 },
|
||||
{"μ", "CAP_U({1})", 1.0e-6 },
|
||||
{"µ", "CAP_U({1})", 1.0e-6 },
|
||||
{"N", "CAP_N({1})", 1.0e-9 },
|
||||
{"pF", "CAP_P({1})", 1.0e-12},
|
||||
{"P", "CAP_P({1})", 1.0e-12},
|
||||
{"F", "{1}e-15", 1.0e-15},
|
||||
|
||||
{"MIL", "{1}", 25.4e-6}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
nl_convert_base_t::~nl_convert_base_t()
|
||||
@ -182,25 +202,20 @@ void nl_convert_base_t::dump_nl()
|
||||
|
||||
const pstring nl_convert_base_t::get_nl_val(const double val)
|
||||
{
|
||||
for (auto &e : m_units)
|
||||
{
|
||||
int i = 0;
|
||||
while (pstring(m_units[i].m_unit) != "-" )
|
||||
{
|
||||
if (m_units[i].m_mult <= std::abs(val))
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
return plib::pfmt(pstring(m_units[i].m_func))(val / m_units[i].m_mult);
|
||||
if (e.m_mult <= std::abs(val))
|
||||
return plib::pfmt(e.m_func)(val / e.m_mult);
|
||||
}
|
||||
return plib::pfmt("{1}")(val);
|
||||
}
|
||||
|
||||
double nl_convert_base_t::get_sp_unit(const pstring &unit)
|
||||
{
|
||||
int i = 0;
|
||||
while (pstring(m_units[i].m_unit) != "-")
|
||||
for (auto &e : m_units)
|
||||
{
|
||||
if (pstring(m_units[i].m_unit) == unit)
|
||||
return m_units[i].m_mult;
|
||||
i++;
|
||||
if (e.m_unit == unit)
|
||||
return e.m_mult;
|
||||
}
|
||||
plib::perrlogger("Unit {} unknown\n", unit);
|
||||
return 0.0;
|
||||
@ -217,7 +232,8 @@ double nl_convert_base_t::get_sp_val(const pstring &sin)
|
||||
return ret;
|
||||
}
|
||||
|
||||
nl_convert_base_t::unit_t nl_convert_base_t::m_units[] = {
|
||||
#if 0
|
||||
std::vector<nl_convert_base_t::unit_t> nl_convert_base_t::m_units = {
|
||||
{"T", "", 1.0e12 },
|
||||
{"G", "", 1.0e9 },
|
||||
{"MEG", "RES_M({1})", 1.0e6 },
|
||||
@ -234,11 +250,9 @@ nl_convert_base_t::unit_t nl_convert_base_t::m_units[] = {
|
||||
{"P", "CAP_P({1})", 1.0e-12},
|
||||
{"F", "{1}e-15", 1.0e-15},
|
||||
|
||||
{"MIL", "{1}", 25.4e-6},
|
||||
|
||||
{"-", "{1}", 1.0 }
|
||||
{"MIL", "{1}", 25.4e-6}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void nl_convert_spice_t::convert(const pstring &contents)
|
||||
{
|
||||
@ -257,7 +271,7 @@ void nl_convert_spice_t::convert(const pstring &contents)
|
||||
// Basic preprocessing
|
||||
pstring inl = plib::ucase(plib::trim(i));
|
||||
if (plib::startsWith(inl, "+"))
|
||||
line = line + inl.substr(1);
|
||||
line += inl.substr(1);
|
||||
else
|
||||
{
|
||||
process_line(line);
|
||||
|
@ -117,8 +117,8 @@ private:
|
||||
};
|
||||
|
||||
struct unit_t {
|
||||
const char *m_unit;
|
||||
const char *m_func;
|
||||
pstring m_unit;
|
||||
pstring m_func;
|
||||
double m_mult;
|
||||
};
|
||||
|
||||
@ -146,7 +146,7 @@ private:
|
||||
std::vector<pstring> m_ext_alias;
|
||||
std::unordered_map<pstring, plib::unique_ptr<pin_alias_t>> m_pins;
|
||||
|
||||
static unit_t m_units[];
|
||||
std::vector<unit_t> m_units;
|
||||
pstring m_numberchars;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user