summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/netlist/plib/pfmtlog.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/netlist/plib/pfmtlog.h')
-rw-r--r--src/lib/netlist/plib/pfmtlog.h53
1 files changed, 38 insertions, 15 deletions
diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h
index df0463cbb61..489e16aea8e 100644
--- a/src/lib/netlist/plib/pfmtlog.h
+++ b/src/lib/netlist/plib/pfmtlog.h
@@ -31,6 +31,10 @@ struct ptype_traits_base
static constexpr const T cast(const T &x) { return x; }
static constexpr const bool is_signed = std::numeric_limits<T>::is_signed;
static char32_t fmt_spec() { return 'u'; }
+ static inline void streamify(std::ostream &s, const T &v)
+ {
+ s << v;
+ }
};
#if (PUSE_FLOAT128)
@@ -41,17 +45,13 @@ struct ptype_traits_base<__float128>
static constexpr const long double cast(const __float128 &x) { return static_cast<long double>(x); }
static constexpr const bool is_signed = true;
static char32_t fmt_spec() { return 'f'; }
+ static inline void streamify(std::ostream &s, const __float128 &v)
+ {
+ s << static_cast<long double>(v);
+ }
};
#endif
-template <>
-struct ptype_traits_base<bool>
-{
- 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 char32_t fmt_spec() { return 'u'; }
-};
-
template <typename T>
struct ptype_traits;
@@ -160,12 +160,25 @@ struct ptype_traits<char *> : ptype_traits_base<char *>
};
template<>
-struct ptype_traits<std::string> : ptype_traits_base<char *>
+struct ptype_traits<const char *> : ptype_traits_base<const char *>
{
- static const char *cast(const std::string &x) { return x.c_str(); }
+ static const char *cast(const char *x) { return x; }
static char32_t fmt_spec() { return 's'; }
};
+template<>
+struct ptype_traits<std::string> : ptype_traits_base<std::string>
+{
+ static char32_t fmt_spec() { return 's'; }
+};
+
+template<>
+struct ptype_traits<const void *> : ptype_traits_base<const void *>
+{
+ static const void *cast(const void *x) { return x; }
+ static char32_t fmt_spec() { return 'p'; }
+};
+
class pfmt
{
public:
@@ -193,7 +206,7 @@ public:
e(const T &x) {return format_element('e', x); }
#if PUSE_FLOAT128
- // FIXME: not what we want
+ // FIXME: should use quadmath_snprintf
pfmt & e(const __float128 &x) {return format_element('e', static_cast<long double>(x)); }
#endif
@@ -207,13 +220,13 @@ public:
template<typename T>
pfmt &operator ()(const T &x)
{
- return format_element(ptype_traits<T>::fmt_spec(), ptype_traits<T>::cast(x));
+ return format_element(x);
}
template<typename T>
pfmt &operator ()(const T *x)
{
- return format_element(ptype_traits<T *>::fmt_spec(), ptype_traits<T *>::cast(x));
+ return format_element(x);
}
pfmt &operator ()()
@@ -262,8 +275,16 @@ protected:
rtype setfmt(std::stringstream &strm, char32_t cfmt_spec);
template <typename T>
- pfmt &format_element(const char32_t cfmt_spec, T &&val)
+ pfmt &format_element(T &&v)
{
+ return format_element(ptype_traits<typename std::decay<T>::type>::fmt_spec(), std::forward<T>(v));
+ }
+
+ template <typename T>
+ pfmt &format_element(const char32_t cfmt_spec, T &&v)
+ {
+ //auto val = ptype_traits<typename std::decay<T>::type>::cast(std::forward<T>(v));
+
rtype ret;
m_arg++;
@@ -274,7 +295,9 @@ protected:
ret = setfmt(strm, cfmt_spec);
if (ret.ret>=0)
{
- strm << std::forward<T>(val);
+ //strm << val;
+ ptype_traits<typename std::decay<T>::type>::streamify(strm, std::forward<T>(v));
+
const pstring ps(strm.str());
pstring pad("");
auto aw(static_cast<std::size_t>(std::abs(ret.width)));