netlist code maintenance. (nw)

- remove a lot of c library use and instead use c++
- improved pstring compatibility to std::string
- prepare removal of pstream
This commit is contained in:
couriersud 2019-09-17 21:05:01 +02:00
parent 4495c35113
commit 500ca5b8fc
31 changed files with 344 additions and 284 deletions

View File

@ -184,7 +184,7 @@ namespace devices
{ {
// FIXME: use pstonum_ne // FIXME: use pstonum_ne
//pati[i] = plib::pstonum<decltype(pati[i])>(pat[i]); //pati[i] = plib::pstonum<decltype(pati[i])>(pat[i]);
pati[i] = plib::pstonum<std::int64_t, true>(pat[i]); pati[i] = plib::pstonum<std::int64_t>(pat[i]);
total += pati[i]; total += pati[i];
} }
netlist_time ttotal = netlist_time::zero(); netlist_time ttotal = netlist_time::zero();

View File

@ -401,7 +401,7 @@ void truthtable_parser::parse(const std::vector<pstring> &truthtable)
else else
nl_assert_always(outs == "0", "Unknown value (not 0 or 1"); nl_assert_always(outs == "0", "Unknown value (not 0 or 1");
// FIXME: error handling // FIXME: error handling
netlist_time t = netlist_time::from_nsec(plib::pstonum<std::int64_t, true>(plib::trim(times[j]))); netlist_time t = netlist_time::from_nsec(plib::pstonum<std::int64_t>(plib::trim(times[j])));
uint_least8_t k=0; uint_least8_t k=0;
while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t) while (m_timing_nt[k] != netlist_time::zero() && m_timing_nt[k] != t)
k++; k++;

View File

@ -20,7 +20,7 @@
#include "nl_errstr.h" #include "nl_errstr.h"
#include <cmath> #include <cmath>
#include <cstring> //#include <cstring>
#include <limits> #include <limits>
namespace netlist namespace netlist

View File

@ -1139,7 +1139,7 @@ namespace netlist
protected: protected:
void changed() override void changed() override
{ {
stream()->read(reinterpret_cast<plib::pistream::value_type *>(&m_data[0]),1<<AW); stream()->read(reinterpret_cast<plib::pistream::char_type *>(&m_data[0]),1<<AW);
} }
private: private:
@ -1634,7 +1634,7 @@ namespace netlist
{ {
auto f = stream(); auto f = stream();
if (f != nullptr) if (f != nullptr)
f->read(reinterpret_cast<plib::pistream::value_type *>(&m_data[0]),1<<AW); f->read(reinterpret_cast<plib::pistream::char_type *>(&m_data[0]),1<<AW);
else else
device.state().log().warning(MW_ROM_NOT_FOUND(str())); device.state().log().warning(MW_ROM_NOT_FOUND(str()));
} }

View File

@ -1199,13 +1199,13 @@ bool source_t::parse(nlparse_t &setup, const pstring &name)
plib::unique_ptr<plib::pistream> source_string_t::stream(const pstring &name) plib::unique_ptr<plib::pistream> source_string_t::stream(const pstring &name)
{ {
plib::unused_var(name); plib::unused_var(name);
return plib::make_unique<plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str())); return plib::make_unique<plib::pistringstream>(m_str);
} }
plib::unique_ptr<plib::pistream> source_mem_t::stream(const pstring &name) plib::unique_ptr<plib::pistream> source_mem_t::stream(const pstring &name)
{ {
plib::unused_var(name); plib::unused_var(name);
return plib::make_unique<plib::pimemstream>(m_str.c_str(), std::strlen(m_str.c_str())); return plib::make_unique<plib::pistringstream>(m_str);
} }
plib::unique_ptr<plib::pistream> source_file_t::stream(const pstring &name) plib::unique_ptr<plib::pistream> source_file_t::stream(const pstring &name)

View File

@ -22,7 +22,7 @@
#include "plib/ptime.h" #include "plib/ptime.h"
#include "plib/putil.h" #include "plib/putil.h"
#include <cstdint> //#include <cstdint>
#include <unordered_map> #include <unordered_map>
namespace netlist namespace netlist

View File

@ -21,7 +21,6 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cmath> #include <cmath>
#include <cstdlib>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>

View File

@ -12,8 +12,8 @@
#include "pstring.h" #include "pstring.h"
#include "ptypes.h" #include "ptypes.h"
#include <cstddef> #include <cstddef> // for std::max_align_t (usually long long)
#include <cstdlib> //#include <cstdlib>
#include <memory> #include <memory>
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>

View File

@ -3,8 +3,6 @@
#include "pchrono.h" #include "pchrono.h"
#include <chrono>
namespace plib { namespace plib {
namespace chrono { namespace chrono {
#if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6)) #if defined(__x86_64__) && !defined(_clang__) && !defined(_MSC_VER) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 6))

View File

@ -12,7 +12,7 @@
#include "ptypes.h" #include "ptypes.h"
#include <chrono> #include <chrono>
#include <cstdint> //#include <cstdint>
namespace plib { namespace plib {
namespace chrono { namespace chrono {

View File

@ -10,100 +10,133 @@
#include <algorithm> #include <algorithm>
#include <array> #include <array>
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream> #include <iostream>
#include <clocale> #include <iomanip>
#include <cmath>
namespace plib { namespace plib {
pfmt &pfmt::format_element(const char *l, const unsigned cfmt_spec, ...) #if 0
struct ptemporary_locale
{ {
va_list ap; ptemporary_locale(std::locale tlocale)
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) : new_locale(tlocale), old_clocale(std::setlocale(LC_ALL, nullptr))
std::array<char, 2048> buf = {0}; {
std::size_t sl; if (old_locale != tlocale)
bool found_abs = false; std::locale::global(tlocale);
pstring old_locale(std::setlocale(LC_ALL, nullptr)); if (old_clocale != tlocale.name().c_str())
std::setlocale(LC_ALL, tlocale.name().c_str());
}
if (old_locale != "C") ~ptemporary_locale()
std::setlocale(LC_ALL, "C"); {
if (old_clocale != new_locale.name().c_str())
std::setlocale(LC_ALL, old_clocale.c_str());
if (old_locale != new_locale)
std::locale::global(old_locale);
}
private:
std::locale new_locale;
std::locale old_locale;
pstring old_clocale;
};
#endif
m_arg++; pfmt::rtype pfmt::setfmt(std::stringstream &strm, unsigned cfmt_spec)
{
pstring fmt;
pstring search("{");
search += plib::to_string(m_arg);
rtype r;
do { r.sl = search.size();
pstring fmt("%"); r.p = m_str.find(search + ":");
va_start(ap, cfmt_spec); r.sl++; // ":"
found_abs = false; if (r.p == pstring::npos) // no further specifiers
buf[0] = 0; {
pstring search("{"); r.p = m_str.find(search + "}");
search += plib::to_string(m_arg); if (r.p == pstring::npos) // not found try default
sl = search.size();
auto p = m_str.find(search + ":");
sl++; // ":"
if (p == pstring::npos) // no further specifiers
{ {
p = m_str.find(search + "}"); r.sl = 2;
if (p == pstring::npos) // not found try default r.p = m_str.find("{}");
}
else
// found absolute positional place holder
r.ret = 1;
if (r.p == pstring::npos)
{
r.sl=2;
r.p = m_str.find("{:");
if (r.p != pstring:: npos)
{ {
sl = 2; auto p1 = m_str.find("}", r.p);
p = m_str.find("{}"); if (p1 != pstring::npos)
}
else
// found absolute positional place holder
found_abs = true;
if (p == pstring::npos)
{
sl=2;
p = m_str.find("{:");
if (p != pstring:: npos)
{ {
auto p1 = m_str.find("}", p); r.sl = p1 - r.p + 1;
if (p1 != pstring::npos) fmt += m_str.substr(r.p+2, p1 - r.p - 2);
{
sl = p1 - p + 1;
fmt += m_str.substr(p+1, p1 - p - 1);
}
} }
} }
} }
else }
else
{
// found absolute positional place holder
auto p1 = m_str.find("}", r.p);
if (p1 != pstring::npos)
{ {
// found absolute positional place holder r.sl = p1 - r.p + 1;
auto p1 = m_str.find("}", p); fmt += ((m_arg>=10) ? m_str.substr(r.p+4, p1 - r.p - 4) : m_str.substr(r.p+3, p1 - r.p - 3));
if (p1 != pstring::npos) r.ret = 1;
{
sl = p1 - p + 1;
fmt += ((m_arg>=10) ? m_str.substr(p+4, p1 - p - 4) : m_str.substr(p+3, p1 - p - 3));
found_abs = true;
}
} }
pstring::value_type pend = fmt.at(fmt.size() - 1); }
if (pstring("duxo").find(cfmt_spec) != pstring::npos) if (r.p != pstring::npos)
{
// a.b format here ...
if (fmt != "" && pstring("duxofge").find(cfmt_spec) != pstring::npos)
{ {
if (pstring("duxo").find(pend) == pstring::npos) r.pend = fmt.at(fmt.size() - 1);
fmt += (pstring(l) + static_cast<pstring::value_type>(cfmt_spec)); if (pstring("duxofge").find(r.pend) == pstring::npos)
r.pend = static_cast<pstring::value_type>(cfmt_spec);
else else
fmt = plib::left(fmt, fmt.size() - 1) + pstring(l) + plib::right(fmt, 1); fmt = plib::left(fmt, fmt.size() - 1);
}
else if (pstring("fge").find(cfmt_spec) != pstring::npos)
{
if (pstring("fge").find(pend) == pstring::npos)
fmt += cfmt_spec;
} }
else else
fmt += cfmt_spec; // FIXME: Error
std::vsnprintf(buf.data(), buf.size(), fmt.c_str(), ap); r.pend = cfmt_spec;
if (p != pstring::npos)
m_str = m_str.substr(0, p) + pstring(buf.data()) + m_str.substr(p + sl); int pdot(fmt.find('.'));
va_end(ap);
} while (found_abs); if (pdot==0)
if (old_locale != "C") strm << std::setprecision(pstonum<int>(fmt.substr(1)));
std::setlocale(LC_ALL, old_locale.c_str()); else if (r.p != pstring::npos)
return *this; {
strm << std::setprecision(pstonum<int>(fmt.substr(pdot + 1))) << std::setw(pstonum<int>(left(fmt,pdot)));
}
else if (fmt != "")
strm << std::setw(pstonum<int>(fmt));
switch (r.pend)
{
case 'x':
strm << std::hex;
break;
case 'o':
strm << std::oct;
break;
case 'f':
strm << std::fixed;
break;
case 'e':
strm << std::scientific;
break;
default:
break;
}
}
else
r.ret = -1;
return r;
} }
} // namespace plib } // namespace plib

View File

@ -12,6 +12,8 @@
#include "putil.h" #include "putil.h"
#include <limits> #include <limits>
#include <locale>
#include <sstream>
namespace plib { namespace plib {
@ -28,7 +30,6 @@ struct ptype_traits_base
{ {
static const T cast(const T &x) { return x; } static const T cast(const T &x) { return x; }
static const bool is_signed = std::numeric_limits<T>::is_signed; static const bool is_signed = std::numeric_limits<T>::is_signed;
static const char *size_spec() { return ""; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
@ -37,7 +38,6 @@ struct ptype_traits_base<bool>
{ {
static unsigned int cast(const bool &x) { return static_cast<unsigned int>(x); } static unsigned int cast(const bool &x) { return static_cast<unsigned int>(x); }
static const bool is_signed = std::numeric_limits<bool>::is_signed; static const bool is_signed = std::numeric_limits<bool>::is_signed;
static const char *size_spec() { return ""; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
@ -52,14 +52,12 @@ struct ptype_traits<bool> : ptype_traits_base<bool>
template<> template<>
struct ptype_traits<char> : ptype_traits_base<char> struct ptype_traits<char> : ptype_traits_base<char>
{ {
static const char *size_spec() { return "h"; }
static char32_t fmt_spec() { return is_signed ? 'd' : 'u'; } static char32_t fmt_spec() { return is_signed ? 'd' : 'u'; }
}; };
template<> template<>
struct ptype_traits<short> : ptype_traits_base<short> struct ptype_traits<short> : ptype_traits_base<short>
{ {
static const char *size_spec() { return "h"; }
static char32_t fmt_spec() { return 'd'; } static char32_t fmt_spec() { return 'd'; }
}; };
@ -72,35 +70,30 @@ struct ptype_traits<int> : ptype_traits_base<int>
template<> template<>
struct ptype_traits<long> : ptype_traits_base<long> struct ptype_traits<long> : ptype_traits_base<long>
{ {
static const char *size_spec() { return "l"; }
static char32_t fmt_spec() { return 'd'; } static char32_t fmt_spec() { return 'd'; }
}; };
template<> template<>
struct ptype_traits<long long> : ptype_traits_base<long long> struct ptype_traits<long long> : ptype_traits_base<long long>
{ {
static const char *size_spec() { return "ll"; }
static char32_t fmt_spec() { return 'd'; } static char32_t fmt_spec() { return 'd'; }
}; };
template<> template<>
struct ptype_traits<signed char> : ptype_traits_base<signed char> struct ptype_traits<signed char> : ptype_traits_base<signed char>
{ {
static const char *size_spec() { return "h"; }
static char32_t fmt_spec() { return 'd'; } static char32_t fmt_spec() { return 'd'; }
}; };
template<> template<>
struct ptype_traits<unsigned char> : ptype_traits_base<unsigned char> struct ptype_traits<unsigned char> : ptype_traits_base<unsigned char>
{ {
static const char *size_spec() { return "h"; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
template<> template<>
struct ptype_traits<unsigned short> : ptype_traits_base<unsigned short> struct ptype_traits<unsigned short> : ptype_traits_base<unsigned short>
{ {
static const char *size_spec() { return "h"; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
@ -113,14 +106,12 @@ struct ptype_traits<unsigned int> : ptype_traits_base<unsigned int>
template<> template<>
struct ptype_traits<unsigned long> : ptype_traits_base<unsigned long> struct ptype_traits<unsigned long> : ptype_traits_base<unsigned long>
{ {
static const char *size_spec() { return "l"; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
template<> template<>
struct ptype_traits<unsigned long long> : ptype_traits_base<unsigned long long> struct ptype_traits<unsigned long long> : ptype_traits_base<unsigned long long>
{ {
static const char *size_spec() { return "ll"; }
static char32_t fmt_spec() { return 'u'; } static char32_t fmt_spec() { return 'u'; }
}; };
@ -154,41 +145,45 @@ class pfmt
{ {
public: public:
explicit pfmt(const pstring &fmt) explicit pfmt(const pstring &fmt)
: m_str(fmt), m_arg(0) : m_str(fmt), m_locale(std::locale::classic()), m_arg(0)
{ {
} }
explicit pfmt(std::locale loc, const pstring &fmt)
: m_str(fmt), m_locale(loc), m_arg(0)
{
}
COPYASSIGNMOVE(pfmt, default) COPYASSIGNMOVE(pfmt, default)
~pfmt() noexcept = default; ~pfmt() noexcept = default;
operator pstring() const { return m_str; } operator pstring() const { return m_str; }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & e(const double &x) {return format_element("", 'e', x); }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
pfmt & g(const double &x) {return format_element("", 'g', x); }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) template <typename T>
pfmt & e(const float &x) {return format_element("", 'e', static_cast<double>(x)); } typename std::enable_if<std::is_floating_point<T>::value, pfmt &>::type
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) f(const T &x) {return format_element('f', x); }
pfmt & g(const float &x) {return format_element("", 'g', static_cast<double>(x)); }
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) template <typename T>
pfmt &operator ()(const void *x) {return format_element("", 'p', x); } typename std::enable_if<std::is_floating_point<T>::value, pfmt &>::type
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) e(const T &x) {return format_element('e', x); }
pfmt &operator ()(const pstring &x) {return format_element("", 's', x.c_str() ); }
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value, pfmt &>::type
g(const T &x) {return format_element('g', x); }
pfmt &operator ()(const void *x) {return format_element('p', x); }
pfmt &operator ()(const pstring &x) {return format_element('s', x.c_str() ); }
template<typename T> template<typename T>
pfmt &operator ()(const T &x) pfmt &operator ()(const T &x)
{ {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits<T>::fmt_spec(), ptype_traits<T>::cast(x));
return format_element(ptype_traits<T>::size_spec(), ptype_traits<T>::fmt_spec(), ptype_traits<T>::cast(x));
} }
template<typename T> template<typename T>
pfmt &operator ()(const T *x) pfmt &operator ()(const T *x)
{ {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element(ptype_traits<T *>::fmt_spec(), ptype_traits<T *>::cast(x));
return format_element(ptype_traits<T *>::size_spec(), ptype_traits<T *>::fmt_spec(), ptype_traits<T *>::cast(x));
} }
pfmt &operator ()() pfmt &operator ()()
@ -204,26 +199,58 @@ public:
} }
template<typename T> template<typename T>
pfmt &x(const T &x) typename std::enable_if<std::is_integral<T>::value, pfmt &>::type
x(const T &x)
{ {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element('x', x);
return format_element(ptype_traits<T>::size_spec(), 'x', x);
} }
template<typename T> template<typename T>
pfmt &o(const T &x) typename std::enable_if<std::is_integral<T>::value, pfmt &>::type
o(const T &x)
{ {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) return format_element('o', x);
return format_element(ptype_traits<T>::size_spec(), 'o', x);
} }
protected: protected:
pfmt &format_element(const char *l, const unsigned fmt_spec, ...); struct rtype
{
rtype() : ret(0), p(0), sl(0), pend(0) {}
int ret;
pstring::size_type p;
pstring::size_type sl;
pstring::value_type pend;
};
rtype setfmt(std::stringstream &strm, unsigned cfmt_spec);
template <typename T>
pfmt &format_element(const unsigned cfmt_spec, T &&val)
{
rtype ret;
m_arg++;
do {
std::stringstream strm;
strm.imbue(m_locale);
ret = setfmt(strm, cfmt_spec);
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);
}
} while (ret.ret == 1);
return *this;
}
private: private:
pstring m_str; pstring m_str;
std::locale m_locale;
unsigned m_arg; unsigned m_arg;
}; };

View File

@ -16,10 +16,10 @@
#include "pstring.h" #include "pstring.h"
#include "putil.h" #include "putil.h"
#include <cwchar>
#include <memory> #include <memory>
#ifdef _WIN32 #ifdef _WIN32
#include <cwchar>
#define PMAIN(appclass) \ #define PMAIN(appclass) \
extern "C" int wmain(int argc, wchar_t *argv[]) { return plib::app::mainrun<appclass, wchar_t>(argc, argv); } extern "C" int wmain(int argc, wchar_t *argv[]) { return plib::app::mainrun<appclass, wchar_t>(argc, argv); }
#else #else

View File

@ -14,7 +14,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <cstdlib> //#include <cstdlib>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>

View File

@ -15,7 +15,7 @@
#include "putil.h" #include "putil.h"
#include <algorithm> #include <algorithm>
#include <cstddef> //#include <cstddef>
#include <memory> #include <memory>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>

View File

@ -11,7 +11,7 @@
#include "pconfig.h" #include "pconfig.h"
#include <cstddef> //#include <cstddef>
#if HAS_OPENMP #if HAS_OPENMP
#include "omp.h" #include "omp.h"

View File

@ -9,7 +9,7 @@
#include "palloc.h" #include "palloc.h"
#include "putil.h" #include "putil.h"
#include <cstdarg> //#include <cstdarg>
namespace plib { namespace plib {
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
@ -296,14 +296,14 @@ void ppreprocessor::error(const pstring &err)
throw pexception("PREPRO ERROR: " + err); throw pexception("PREPRO ERROR: " + err);
} }
pstream::size_type ppreprocessor::vread(value_type *buf, const pstream::size_type n) 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, n);
if (bytes==0) if (bytes==0)
return 0; return 0;
std::memcpy(buf, m_buf.c_str() + m_pos, bytes); std::copy(m_buf.c_str() + m_pos, m_buf.c_str() + m_pos + bytes, buf);
m_pos += bytes; m_pos += bytes;
return bytes; return bytes;
} }
@ -357,7 +357,7 @@ int ppreprocessor::expr(const std::vector<pstring> &sexpr, std::size_t &start, i
else else
{ {
// FIXME: error handling // FIXME: error handling
val = plib::pstonum<decltype(val), true>(tok); val = plib::pstonum<decltype(val)>(tok);
start++; start++;
} }
} }

View File

@ -12,7 +12,7 @@
#include "pstream.h" #include "pstream.h"
#include "pstring.h" #include "pstring.h"
#include <cstdint> //#include <cstdint>
#include <unordered_map> #include <unordered_map>
@ -204,7 +204,7 @@ public:
protected: protected:
size_type vread(value_type *buf, const size_type n) override; size_type vread(char_type *buf, const size_type n) override;
void vseek(const pos_type n) override void vseek(const pos_type n) override
{ {
plib::unused_var(n); plib::unused_var(n);

View File

@ -10,7 +10,7 @@
#include "pconfig.h" #include "pconfig.h"
#include <cstdint> //#include <cstdint>
#include <utility> #include <utility>
/* /*

View File

@ -10,7 +10,7 @@
#include <algorithm> #include <algorithm>
#include <cstdio> #include <cstdio>
#include <cstdlib> //#include <cstdlib>
// VS2015 prefers _dup // VS2015 prefers _dup
#ifdef _WIN32 #ifdef _WIN32
@ -71,7 +71,7 @@ pifilestream::~pifilestream()
} }
} }
pifilestream::pos_type pifilestream::vread(value_type *buf, const pos_type n) pifilestream::pos_type pifilestream::vread(char_type *buf, const pos_type n)
{ {
pos_type r = fread(buf, 1, n, static_cast<FILE *>(m_file)); pos_type r = fread(buf, 1, n, static_cast<FILE *>(m_file));
if (r < n) if (r < n)
@ -124,6 +124,8 @@ pstdin::pstdin()
// Output file stream // Output file stream
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if !USE_CSTREAM
pofilestream::pofilestream(const pstring &fname) pofilestream::pofilestream(const pstring &fname)
: postream(0), m_file(fopen(fname.c_str(), "wb")), m_pos(0), m_actually_close(true), m_filename(fname) : postream(0), m_file(fopen(fname.c_str(), "wb")), m_pos(0), m_actually_close(true), m_filename(fname)
{ {
@ -156,7 +158,7 @@ pofilestream::~pofilestream()
} }
} }
void pofilestream::vwrite(const value_type *buf, const pos_type n) void pofilestream::vwrite(const char_type *buf, const pos_type n)
{ {
std::size_t r = fwrite(buf, 1, n, static_cast<FILE *>(m_file)); std::size_t r = fwrite(buf, 1, n, static_cast<FILE *>(m_file));
if (r < n) if (r < n)
@ -190,10 +192,44 @@ pstream::pos_type pofilestream::vtell() const
return static_cast<pos_type>(ret); return static_cast<pos_type>(ret);
} }
// -----------------------------------------------------------------------------
// Output memory stream
// -----------------------------------------------------------------------------
pomemstream::pomemstream()
: postream(FLAG_SEEKABLE), m_pos(0), m_mem(1024)
{
m_mem.clear();
}
void pomemstream::vwrite(const char_type *buf, const pos_type n)
{
if (m_pos + n >= m_mem.size())
m_mem.resize(m_pos + n);
std::copy(buf, buf + n, &m_mem[0] + m_pos);
m_pos += n;
}
void pomemstream::vseek(const pos_type n)
{
m_pos = n;
if (m_pos>=m_mem.size())
m_mem.resize(m_pos);
}
pstream::pos_type pomemstream::vtell() const
{
return m_pos;
}
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// pstderr: write to stderr // pstderr: write to stderr
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if 1
pstderr::pstderr() pstderr::pstderr()
#ifdef _WIN32 #ifdef _WIN32
: pofilestream(fdopen(_dup(fileno(stderr)), "wb"), "<stderr>", true) : pofilestream(fdopen(_dup(fileno(stderr)), "wb"), "<stderr>", true)
@ -215,7 +251,7 @@ pstdout::pstdout()
#endif #endif
{ {
} }
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Memory stream // Memory stream
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -229,13 +265,14 @@ pimemstream::pimemstream()
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(0), m_mem(static_cast<const char *>(nullptr)) : pistream(FLAG_SEEKABLE), m_pos(0), m_len(0), m_mem(static_cast<const char *>(nullptr))
{ {
} }
#if 0
pimemstream::pimemstream(const pomemstream &ostrm) pimemstream::pimemstream(const pomemstream &ostrm)
: pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<const char *>(ostrm.memory())) : pistream(FLAG_SEEKABLE), m_pos(0), m_len(ostrm.size()), m_mem(reinterpret_cast<const char *>(ostrm.memory()))
{ {
} }
#endif
pimemstream::pos_type pimemstream::vread(value_type *buf, const pos_type n) pimemstream::pos_type pimemstream::vread(char_type *buf, const pos_type n)
{ {
pos_type ret = (m_pos + n <= m_len) ? n : m_len - m_pos; pos_type ret = (m_pos + n <= m_len) ? n : m_len - m_pos;
@ -263,36 +300,6 @@ pimemstream::pos_type pimemstream::vtell() const
return m_pos; return m_pos;
} }
// -----------------------------------------------------------------------------
// Output memory stream
// -----------------------------------------------------------------------------
pomemstream::pomemstream()
: postream(FLAG_SEEKABLE), m_pos(0), m_mem(1024)
{
m_mem.clear();
}
void pomemstream::vwrite(const value_type *buf, const pos_type n)
{
if (m_pos + n >= m_mem.size())
m_mem.resize(m_pos + n);
std::copy(buf, buf + n, &m_mem[0] + m_pos);
m_pos += n;
}
void pomemstream::vseek(const pos_type n)
{
m_pos = n;
if (m_pos>=m_mem.size())
m_mem.resize(m_pos);
}
pstream::pos_type pomemstream::vtell() const
{
return m_pos;
}
bool putf8_reader::readline(pstring &line) bool putf8_reader::readline(pstring &line)
{ {
@ -308,7 +315,7 @@ bool putf8_reader::readline(pstring &line)
if (c == 10) if (c == 10)
break; break;
else if (c != 13) /* ignore CR */ else if (c != 13) /* ignore CR */
m_linebuf += putf8string(c); m_linebuf += putf8string(1, c);
if (!this->readcode(c)) if (!this->readcode(c))
break; break;
} }

View File

@ -104,7 +104,7 @@ class pistream_base : public pstream
{ {
public: public:
using value_type = T; using char_type = T;
~pistream_base() noexcept override = default; ~pistream_base() noexcept override = default;
@ -139,7 +139,7 @@ class postream_base : public pstream
{ {
public: public:
using value_type = T; using char_type = T;
postream_base() = default; postream_base() = default;
~postream_base() noexcept override = default; ~postream_base() noexcept override = default;
@ -152,6 +152,14 @@ public:
vwrite(buf, n); vwrite(buf, n);
} }
void write_c_str(const T *buf)
{
size_type n(0);
while (buf[n])
n++;
vwrite(buf, n);
}
protected: protected:
explicit postream_base(unsigned flags) : pstream(flags) {} explicit postream_base(unsigned flags) : pstream(flags) {}
postream_base(postream_base &&src) noexcept : pstream(std::move(src)) {} postream_base(postream_base &&src) noexcept : pstream(std::move(src)) {}
@ -191,7 +199,7 @@ public:
protected: protected:
/* write n bytes to stream */ /* write n bytes to stream */
void vwrite(const value_type *buf, const pos_type) override; void vwrite(const char_type *buf, const pos_type) override;
void vseek(const pos_type n) override; void vseek(const pos_type n) override;
pos_type vtell() const override; pos_type vtell() const override;
@ -219,9 +227,10 @@ public:
protected: protected:
/* write n bytes to stream */ /* write n bytes to stream */
void vwrite(const value_type *buf, const pos_type n) override 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(reinterpret_cast<const pstring::mem_t *>(buf), n);
m_buf += pstring(buf, n);
} }
void vseek(const pos_type n) override { unused_var(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 m_buf.size(); }
@ -257,7 +266,7 @@ public:
protected: protected:
pofilestream(void *file, const pstring &name, const bool do_close); pofilestream(void *file, const pstring &name, const bool do_close);
/* write n bytes to stream */ /* write n bytes to stream */
void vwrite(const value_type *buf, const pos_type n) override; void vwrite(const char_type *buf, const pos_type n) override;
void vseek(const pos_type n) override; void vseek(const pos_type n) override;
pos_type vtell() const override; pos_type vtell() const override;
@ -329,7 +338,7 @@ protected:
pifilestream(void *file, const pstring &name, const bool do_close); pifilestream(void *file, const pstring &name, const bool do_close);
/* read up to n bytes from stream */ /* read up to n bytes from stream */
pos_type vread(value_type *buf, const pos_type n) override; pos_type vread(char_type *buf, const pos_type n) override;
void vseek(const pos_type n) override; void vseek(const pos_type n) override;
pos_type vtell() const override; pos_type vtell() const override;
@ -379,7 +388,7 @@ public:
COPYASSIGN(pimemstream, delete) COPYASSIGN(pimemstream, delete)
pimemstream &operator=(pimemstream &&src) = delete; pimemstream &operator=(pimemstream &&src) = delete;
explicit pimemstream(const pomemstream &ostrm); //explicit pimemstream(const pomemstream &ostrm);
~pimemstream() override = default; ~pimemstream() override = default;
@ -393,7 +402,7 @@ protected:
} }
/* read up to n bytes from stream */ /* read up to n bytes from stream */
pos_type vread(value_type *buf, const pos_type n) override; pos_type vread(char_type *buf, const pos_type n) override;
void vseek(const pos_type n) override; void vseek(const pos_type n) override;
pos_type vtell() const override; pos_type vtell() const override;
@ -414,12 +423,12 @@ public:
: pimemstream() : pimemstream()
, m_str(str) , m_str(str)
{ {
set_mem(m_str.c_str(), std::strlen(m_str.c_str())); set_mem(m_str.c_str(), pstring_mem_t_size(m_str));
} }
pistringstream(pistringstream &&src) noexcept pistringstream(pistringstream &&src) noexcept
: pimemstream(std::move(src)), m_str(src.m_str) : pimemstream(std::move(src)), m_str(src.m_str)
{ {
set_mem(m_str.c_str(), std::strlen(m_str.c_str())); set_mem(m_str.c_str(), pstring_mem_t_size(m_str));
} }
COPYASSIGN(pistringstream, delete) COPYASSIGN(pistringstream, delete)
pistringstream &operator=(pistringstream &&src) = delete; pistringstream &operator=(pistringstream &&src) = delete;
@ -464,14 +473,14 @@ public:
bool eof() const { return m_strm->eof(); } bool eof() const { return m_strm->eof(); }
bool readline(pstring &line); bool readline(pstring &line);
bool readbyte1(pistream::value_type &b) bool readbyte1(pistream::char_type &b)
{ {
return (m_strm->read(&b, 1) == 1); return (m_strm->read(&b, 1) == 1);
} }
bool readcode(putf8string::traits_type::code_t &c) bool readcode(putf8string::traits_type::code_t &c)
{ {
std::array<pistream::value_type, 4> b{0}; std::array<pistream::char_type, 4> b{0};
if (m_strm->read(&b[0], 1) != 1) if (m_strm->read(&b[0], 1) != 1)
return false; return false;
const std::size_t l = putf8string::traits_type::codelen(reinterpret_cast<putf8string::traits_type::mem_t *>(&b)); const std::size_t l = putf8string::traits_type::codelen(reinterpret_cast<putf8string::traits_type::mem_t *>(&b));
@ -526,7 +535,7 @@ public:
{ {
// NOLINTNEXTLINE(performance-unnecessary-copy-initialization) // NOLINTNEXTLINE(performance-unnecessary-copy-initialization)
const putf8string conv_utf8(text); const putf8string conv_utf8(text);
m_strm->write(reinterpret_cast<const pistream::value_type *>(conv_utf8.c_str()), conv_utf8.mem_t_size()); m_strm->write(conv_utf8.c_str(), plib::strlen(conv_utf8.c_str()));
} }
void write(const pstring::value_type c) const void write(const pstring::value_type c) const
@ -577,13 +586,13 @@ public:
template <typename T> template <typename T>
void write(const T &val) void write(const T &val)
{ {
m_strm.write(reinterpret_cast<const postream::value_type *>(&val), sizeof(T)); m_strm.write(reinterpret_cast<const postream::char_type *>(&val), sizeof(T));
} }
void write(const pstring &s) void write(const pstring &s)
{ {
const auto sm = reinterpret_cast<const postream::value_type *>(s.c_str()); const auto sm = reinterpret_cast<const postream::char_type *>(s.c_str());
const std::size_t sl = std::strlen(s.c_str()); const std::size_t sl(pstring_mem_t_size(s));
write(sl); write(sl);
m_strm.write(sm, sl); m_strm.write(sm, sl);
} }
@ -593,7 +602,7 @@ public:
{ {
std::size_t sz = val.size(); std::size_t sz = val.size();
write(sz); write(sz);
m_strm.write(reinterpret_cast<const postream::value_type *>(val.data()), sizeof(T) * sz); m_strm.write(reinterpret_cast<const postream::char_type *>(val.data()), sizeof(T) * sz);
} }
private: private:
@ -614,7 +623,7 @@ public:
template <typename T> template <typename T>
void read(T &val) void read(T &val)
{ {
m_strm.read(reinterpret_cast<pistream::value_type *>(&val), sizeof(T)); m_strm.read(reinterpret_cast<pistream::char_type *>(&val), sizeof(T));
} }
void read( pstring &s) void read( pstring &s)
@ -633,7 +642,7 @@ public:
std::size_t sz = 0; std::size_t sz = 0;
read(sz); read(sz);
val.resize(sz); val.resize(sz);
m_strm.read(reinterpret_cast<pistream::value_type *>(val.data()), sizeof(T) * sz); m_strm.read(reinterpret_cast<pistream::char_type *>(val.data()), sizeof(T) * sz);
} }
private: private:
@ -642,7 +651,7 @@ private:
inline void copystream(postream &dest, pistream &src) inline void copystream(postream &dest, pistream &src)
{ {
std::array<postream::value_type, 1024> buf; // NOLINT(cppcoreguidelines-pro-type-member-init) std::array<postream::char_type, 1024> buf; // NOLINT(cppcoreguidelines-pro-type-member-init)
pstream::pos_type r; pstream::pos_type r;
while ((r=src.read(buf.data(), 1024)) > 0) while ((r=src.read(buf.data(), 1024)) > 0)
dest.write(buf.data(), r); dest.write(buf.data(), r);

View File

@ -9,7 +9,6 @@
#include "ptypes.h" #include "ptypes.h"
#include <cstring>
#include <exception> #include <exception>
#include <iterator> #include <iterator>
#include <limits> #include <limits>
@ -126,9 +125,10 @@ public:
pstring_t &operator=(const pstring_t &string) = default; pstring_t &operator=(const pstring_t &string) = default;
pstring_t &operator=(pstring_t &&string) noexcept = default; pstring_t &operator=(pstring_t &&string) noexcept = default;
explicit pstring_t(code_t code) explicit pstring_t(size_type n, code_t code)
{ {
*this += code; while (n--)
*this += code;
} }
template <typename T, template <typename T,
@ -198,14 +198,13 @@ public:
const_reference at(const size_type pos) const { return *reinterpret_cast<const ref_value_type *>(F::nthcode(m_str.c_str(),pos)); } 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);
/* the following are extensions to <string> */ /* the following are extensions to <string> */
// FIXME: remove those
size_type mem_t_size() const { return m_str.size(); } size_type mem_t_size() const { return m_str.size(); }
const string_type &cpp_string() const { return m_str; }
static constexpr const size_type npos = static_cast<size_type>(-1);
private: private:
string_type m_str; string_type m_str;
}; };
@ -477,8 +476,10 @@ extern template struct pstring_t<pwchar_traits>;
#if (PSTRING_USE_STD_STRING) #if (PSTRING_USE_STD_STRING)
typedef std::string pstring; typedef std::string pstring;
static inline pstring::size_type pstring_mem_t_size(const pstring &s) { return s.size(); }
#else #else
using pstring = pstring_t<putf8_traits>; using pstring = pstring_t<putf8_traits>;
static inline pstring::size_type pstring_mem_t_size(const pstring &s) { return s.mem_t_size(); }
#endif #endif
using putf8string = pstring_t<putf8_traits>; using putf8string = pstring_t<putf8_traits>;
using pu16string = pstring_t<putf16_traits>; using pu16string = pstring_t<putf16_traits>;
@ -602,13 +603,22 @@ namespace plib
template<typename T> template<typename T>
bool startsWith(const T &str, const char *arg) bool startsWith(const T &str, const char *arg)
{ {
return (left(str, std::strlen(arg)) == arg); return startsWith(str, static_cast<pstring>(arg));
} }
template<typename T> template<typename T>
bool endsWith(const T &str, const char *arg) bool endsWith(const T &str, const char *arg)
{ {
return (right(str, std::strlen(arg)) == arg); return endsWith(str, static_cast<pstring>(arg));
}
template<typename T>
std::size_t strlen(const T *str)
{
const T *p = str;
while (*p)
p++;
return p - str;
} }
template<typename T> template<typename T>
@ -670,7 +680,7 @@ namespace std
{ {
using argument_type = pstring_t<T>; using argument_type = pstring_t<T>;
using result_type = std::size_t; using result_type = std::size_t;
result_type operator()(argument_type const& s) const result_type operator()(const argument_type & s) const
{ {
const typename argument_type::mem_t *string = s.c_str(); const typename argument_type::mem_t *string = s.c_str();
result_type result = 5381; result_type result = 5381;

View File

@ -11,7 +11,7 @@
#include "ptypes.h" #include "ptypes.h"
#include <cmath> // std::floor #include <cmath> // std::floor
#include <cstdint> //#include <cstdint>
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
// netlist_time // netlist_time

View File

@ -6,8 +6,8 @@
#include "ptypes.h" #include "ptypes.h"
#include <algorithm> #include <algorithm>
#include <cstdlib> //#include <cstdlib>
#include <cstring> //#include <cstring>
#include <initializer_list> #include <initializer_list>
namespace plib namespace plib
@ -137,30 +137,15 @@ namespace plib
int penum_base::from_string_int(const char *str, const char *x) int penum_base::from_string_int(const char *str, const char *x)
{ {
int cnt = 0; int cnt = 0;
const char *cur = str; for (auto s : psplit(str, ",", false))
std::size_t lx = strlen(x);
while (*str)
{ {
if (*str == ',') if (s == x)
{
std::ptrdiff_t l = str-cur;
if (static_cast<std::size_t>(l) == lx)
if (strncmp(cur, x, lx) == 0)
return cnt;
}
else if (*str == ' ')
{
cur = str + 1;
cnt++;
}
str++;
}
std::ptrdiff_t l = str-cur;
if (static_cast<std::size_t>(l) == lx)
if (strncmp(cur, x, lx) == 0)
return cnt; return cnt;
cnt++;
}
return -1; return -1;
} }
std::string penum_base::nthstr(int n, const char *str) std::string penum_base::nthstr(int n, const char *str)
{ {
return psplit(str, ",", false)[static_cast<std::size_t>(n)]; return psplit(str, ",", false)[static_cast<std::size_t>(n)];

View File

@ -14,6 +14,7 @@
#include <initializer_list> #include <initializer_list>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <locale>
#define PSTRINGIFY_HELP(y) # y #define PSTRINGIFY_HELP(y) # y
#define PSTRINGIFY(x) PSTRINGIFY_HELP(x) #define PSTRINGIFY(x) PSTRINGIFY_HELP(x)
@ -129,66 +130,57 @@ namespace plib
// number conversions // number conversions
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
template <typename T, bool CLOCALE, typename E = void> template <typename T, typename S>
T pstonum_locale(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());
if (ss >> x)
{
long int pos(ss.tellg());
if (pos == -1)
pos = len;
*idx = static_cast<std::size_t>(pos);
}
else
*idx = constants<std::size_t>::zero();
//printf("%s, %f, %lu %ld\n", arg, (double)x, *idx, (long int) ss.tellg());
return x;
}
template <typename T, typename E = void>
struct pstonum_helper; struct pstonum_helper;
template<typename T, bool CLOCALE> template<typename T>
struct pstonum_helper<T, CLOCALE, typename std::enable_if<std::is_integral<T>::value struct pstonum_helper<T, typename std::enable_if<std::is_integral<T>::value>::type>
&& std::is_signed<T>::value>::type>
{ {
template <typename S> template <typename S>
long long operator()(const S &arg, std::size_t *idx) long long operator()(std::locale loc, const S &arg, std::size_t *idx)
{ {
return std::stoll(arg, idx); //return std::stoll(arg, idx);
return pstonum_locale<long long>(loc, arg, idx);
} }
}; };
template<typename T, bool CLOCALE> template<typename T>
struct pstonum_helper<T, CLOCALE, typename std::enable_if<std::is_integral<T>::value struct pstonum_helper<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
&& !std::is_signed<T>::value>::type>
{ {
template <typename S> template <typename S>
unsigned long long operator()(const S &arg, std::size_t *idx) long double operator()(std::locale loc, const S &arg, std::size_t *idx)
{ {
return std::stoull(arg, idx); return pstonum_locale<long double>(loc, arg, idx);
} }
}; };
template<typename T, bool CLOCALE> template<typename T, typename S>
struct pstonum_helper<T, CLOCALE, typename std::enable_if<std::is_floating_point<T>::value>::type> T pstonum(const S &arg, std::locale loc = std::locale::classic())
{
template <typename S>
long double operator()(const S &arg, std::size_t *idx)
{
if (CLOCALE)
{
std::stringstream ss;
ss.imbue(std::locale::classic());
ss << arg;
long int len(ss.tellp());
auto x(constants<long double>::zero());
long int pos(0);
if (ss >> x)
{
pos = static_cast<long int>(ss.tellg());
if (pos == -1)
pos = len;
}
*idx = static_cast<std::size_t>(pos);
//printf("%s, %f, %lu %ld\n", arg, (double)x, *idx, (long int) ss.tellg());
return x;
}
else
return std::stold(arg, idx);
}
};
template<typename T, bool CLOCALE, typename S>
T pstonum(const S &arg)
{ {
decltype(arg.c_str()) cstr = arg.c_str(); decltype(arg.c_str()) cstr = arg.c_str();
std::size_t idx(0); std::size_t idx(0);
auto ret = pstonum_helper<T, CLOCALE>()(cstr, &idx); auto ret = pstonum_helper<T>()(loc, cstr, &idx);
using ret_type = decltype(ret); using ret_type = decltype(ret);
if (ret >= static_cast<ret_type>(std::numeric_limits<T>::lowest()) if (ret >= static_cast<ret_type>(std::numeric_limits<T>::lowest())
&& ret <= static_cast<ret_type>(std::numeric_limits<T>::max())) && ret <= static_cast<ret_type>(std::numeric_limits<T>::max()))
@ -205,12 +197,12 @@ namespace plib
} }
template<typename R, bool CLOCALE, typename T> template<typename R, bool CLOCALE, typename T>
R pstonum_ne(const T &str, bool &err) noexcept R pstonum_ne(const T &str, bool &err, std::locale loc = std::locale::classic()) noexcept
{ {
try try
{ {
err = false; err = false;
return pstonum<R, CLOCALE>(str); return pstonum<R>(str, loc);
} }
catch (...) catch (...)
{ {

View File

@ -15,7 +15,7 @@
#include "netlist/solver/nld_solver.h" #include "netlist/solver/nld_solver.h"
#include "netlist/tools/nl_convert.h" #include "netlist/tools/nl_convert.h"
#include <cstring> #include <cstdio> // scanf
#define NLTOOL_VERSION 20190420 #define NLTOOL_VERSION 20190420
@ -292,7 +292,7 @@ struct input_t
std::array<char, 400> buf; // NOLINT(cppcoreguidelines-pro-type-member-init) std::array<char, 400> buf; // NOLINT(cppcoreguidelines-pro-type-member-init)
double t; double t;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
int e = sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &m_value); int e = std::sscanf(line.c_str(), "%lf,%[^,],%lf", &t, buf.data(), &m_value);
if (e != 3) if (e != 3)
throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line)); throw netlist::nl_exception(plib::pfmt("error {1} scanning line {2}\n")(e)(line));
m_time = netlist::netlist_time::from_double(t); m_time = netlist::netlist_time::from_double(t);
@ -794,6 +794,8 @@ int tool_app_t::execute()
if (opt_help()) if (opt_help())
{ {
pout(plib::pfmt("{:10.3}\n").f(20.0));
//pout(plib::pfmt("{10.3}\n").f(20));
pout(usage()); pout(usage());
return 0; return 0;
} }

View File

@ -7,7 +7,7 @@
#include "plib/ppmf.h" #include "plib/ppmf.h"
#include "plib/pstream.h" #include "plib/pstream.h"
#include <cstring> #include <cstdio>
/* From: https://ffmpeg.org/pipermail/ffmpeg-devel/2007-October/038122.html /* From: https://ffmpeg.org/pipermail/ffmpeg-devel/2007-October/038122.html
* The most compatible way to make a wav header for unknown length is to put * The most compatible way to make a wav header for unknown length is to put
@ -58,7 +58,7 @@ public:
template <typename T> template <typename T>
void write(const T &val) void write(const T &val)
{ {
m_f.write(reinterpret_cast<const plib::postream::value_type *>(&val), sizeof(T)); m_f.write(reinterpret_cast<const plib::postream::char_type *>(&val), sizeof(T));
} }
void write_sample(int *sample) void write_sample(int *sample)
@ -146,7 +146,7 @@ public:
{ {
// sscanf is very fast ... // sscanf is very fast ...
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg)
sscanf(line.c_str(), "%lf %lf", &m_e[i].t, &m_e[i].v); std::sscanf(line.c_str(), "%lf %lf", &m_e[i].t, &m_e[i].v);
m_e[i].need_more = false; m_e[i].need_more = false;
} }
} }
@ -304,7 +304,7 @@ public:
, m_format(format) , m_format(format)
{ {
for (pstring::value_type c = 64; c < 64+26; c++) for (pstring::value_type c = 64; c < 64+26; c++)
m_ids.emplace_back(pstring(c)); m_ids.emplace_back(pstring(1, c));
write("$date Sat Jan 19 14:14:17 2019\n"); write("$date Sat Jan 19 14:14:17 2019\n");
write("$end\n"); write("$end\n");
write("$version Netlist nlwav 0.1\n"); write("$version Netlist nlwav 0.1\n");
@ -355,9 +355,7 @@ public:
private: private:
void write(const pstring &line) void write(const pstring &line)
{ {
auto p = static_cast<const char *>(line.c_str()); m_fo.write(line.c_str(), plib::strlen(line.c_str()));
std::size_t len = std::strlen(p);
m_fo.write(p, len);
} }
std::size_t m_channels; std::size_t m_channels;

View File

@ -265,7 +265,7 @@ namespace devices
plib::postringstream t; plib::postringstream t;
plib::putf8_fmt_writer w(&t); plib::putf8_fmt_writer w(&t);
csc_private(w); csc_private(w);
std::hash<pstring> h; std::hash<typename std::remove_const<std::remove_reference<decltype(t.str())>::type>::type> h;
return plib::pfmt("nl_gcr_{1:x}_{2}")(h( t.str() ))(mat.nz_num); return plib::pfmt("nl_gcr_{1:x}_{2}")(h( t.str() ))(mat.nz_num);
} }

View File

@ -386,7 +386,7 @@ namespace devices
ms->setup(grp); ms->setup(grp);
log().verbose("Solver {1}", ms->name()); log().verbose("Solver {1}", ms->name());
log().verbose(" ==> {2} nets", grp.size()); log().verbose(" ==> {1} nets", grp.size());
log().verbose(" has {1} elements", ms->has_dynamic_devices() ? "dynamic" : "no dynamic"); log().verbose(" has {1} elements", ms->has_dynamic_devices() ? "dynamic" : "no dynamic");
log().verbose(" has {1} elements", ms->has_timestep_devices() ? "timestep" : "no timestep"); log().verbose(" has {1} elements", ms->has_timestep_devices() ? "timestep" : "no timestep");
for (auto &n : grp) for (auto &n : grp)

View File

@ -213,7 +213,7 @@ double nl_convert_base_t::get_sp_val(const pstring &sin)
++p; ++p;
pstring val = plib::left(sin, p); pstring val = plib::left(sin, p);
pstring unit = sin.substr(p); pstring unit = sin.substr(p);
double ret = get_sp_unit(unit) * plib::pstonum<double, true>(val); double ret = get_sp_unit(unit) * plib::pstonum<double>(val);
return ret; return ret;
} }
@ -532,7 +532,7 @@ void nl_convert_eagle_t::convert(const pstring &contents)
else if (plib::ucase(sval) == "LOW") else if (plib::ucase(sval) == "LOW")
add_device("TTL_INPUT", name, 0); add_device("TTL_INPUT", name, 0);
else else
add_device("ANALOG_INPUT", name, plib::pstonum<double, true>(sval)); add_device("ANALOG_INPUT", name, plib::pstonum<double>(sval));
add_pin_alias(name, "1", "Q"); add_pin_alias(name, "1", "Q");
break; break;
case 'D': case 'D':

View File

@ -29,7 +29,7 @@ public:
virtual ~nl_convert_base_t(); virtual ~nl_convert_base_t();
const pstring &result() { return m_buf.str(); } pstring result() { return pstring(m_buf.str()); }
virtual void convert(const pstring &contents) = 0; virtual void convert(const pstring &contents) = 0;