diff options
Diffstat (limited to 'src/lib/netlist/plib/pfmtlog.h')
-rw-r--r-- | src/lib/netlist/plib/pfmtlog.h | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/src/lib/netlist/plib/pfmtlog.h b/src/lib/netlist/plib/pfmtlog.h index 44397da115a..0e8b7f46946 100644 --- a/src/lib/netlist/plib/pfmtlog.h +++ b/src/lib/netlist/plib/pfmtlog.h @@ -7,104 +7,100 @@ #ifndef PFMT_H_ #define PFMT_H_ -//#include <cstdarg> -//#include <cstddef> +#include <limits> #include "pconfig.h" #include "pstring.h" #include "ptypes.h" namespace plib { + template <typename T> -struct ptype_treats +struct ptype_traits_base { + static T cast(T x) { return x; } + static const bool is_signed = std::numeric_limits<T>::is_signed; }; -template<> -struct ptype_treats<bool> +template <> +struct ptype_traits_base<bool> { static unsigned int cast(bool x) { return static_cast<unsigned int>(x); } - static const bool is_signed = false; + static const bool is_signed = std::numeric_limits<bool>::is_signed; +}; + +template <typename T> +struct ptype_traits; + +template<> +struct ptype_traits<bool> : ptype_traits_base<bool> +{ static const char *size_specifier() { return ""; } }; template<> -struct ptype_treats<char> +struct ptype_traits<char> : ptype_traits_base<char> { - static short cast(char x) { return x; } - static const bool is_signed = true; static const char *size_specifier() { return "h"; } }; template<> -struct ptype_treats<short> +struct ptype_traits<short> : ptype_traits_base<short> { - static short cast(short x) { return x; } - static const bool is_signed = true; static const char *size_specifier() { return "h"; } }; template<> -struct ptype_treats<int> +struct ptype_traits<int> : ptype_traits_base<int> { - static int cast(int x) { return x; } - static const bool is_signed = true; static const char *size_specifier() { return ""; } }; template<> -struct ptype_treats<long> +struct ptype_traits<long> : ptype_traits_base<long> { - static long cast(long x) { return x; } - static const bool is_signed = true; static const char *size_specifier() { return "l"; } }; template<> -struct ptype_treats<long long> +struct ptype_traits<long long> : ptype_traits_base<long long> { - static long long cast(long long x) { return x; } - static const bool is_signed = true; static const char *size_specifier() { return "ll"; } }; template<> -struct ptype_treats<unsigned char> +struct ptype_traits<signed char> : ptype_traits_base<signed char> +{ + static const char *size_specifier() { return "h"; } +}; + +template<> +struct ptype_traits<unsigned char> : ptype_traits_base<unsigned char> { - static unsigned short cast(unsigned char x) { return x; } - static const bool is_signed = false; static const char *size_specifier() { return "h"; } }; template<> -struct ptype_treats<unsigned short> +struct ptype_traits<unsigned short> : ptype_traits_base<unsigned short> { - static unsigned short cast(unsigned short x) { return x; } - static const bool is_signed = false; static const char *size_specifier() { return "h"; } }; template<> -struct ptype_treats<unsigned int> +struct ptype_traits<unsigned int> : ptype_traits_base<unsigned int> { - static unsigned int cast(unsigned int x) { return x; } - static const bool is_signed = false; static const char *size_specifier() { return ""; } }; template<> -struct ptype_treats<unsigned long> +struct ptype_traits<unsigned long> : ptype_traits_base<unsigned long> { - static unsigned long cast(unsigned long x) { return x; } - static const bool is_signed = false; static const char *size_specifier() { return "l"; } }; template<> -struct ptype_treats<unsigned long long> +struct ptype_traits<unsigned long long> : ptype_traits_base<unsigned long long> { - static unsigned long long cast(unsigned long long x) { return x; } - static const bool is_signed = false; static const char *size_specifier() { return "ll"; } }; @@ -127,29 +123,28 @@ public: P &operator ()(char *x, const char *f = "") { format_element(f, "", "s", x); return static_cast<P &>(*this); } P &operator ()(const void *x, const char *f = "") { format_element(f, "", "p", x); return static_cast<P &>(*this); } P &operator ()(const pstring &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast<P &>(*this); } - P &operator ()(const pstring_t<putf8_traits> &x, const char *f = "") { format_element(f, "", "s", x.cstr() ); return static_cast<P &>(*this); } template<typename T> P &operator ()(const T x, const char *f = "") { - if (ptype_treats<T>::is_signed) - format_element(f, ptype_treats<T>::size_specifier(), "d", ptype_treats<T>::cast(x)); + if (ptype_traits<T>::is_signed) + format_element(f, ptype_traits<T>::size_specifier(), "d", ptype_traits<T>::cast(x)); else - format_element(f, ptype_treats<T>::size_specifier(), "u", ptype_treats<T>::cast(x)); + format_element(f, ptype_traits<T>::size_specifier(), "u", ptype_traits<T>::cast(x)); return static_cast<P &>(*this); } template<typename T> P &x(const T x, const char *f = "") { - format_element(f, ptype_treats<T>::size_specifier(), "x", x); + format_element(f, ptype_traits<T>::size_specifier(), "x", x); return static_cast<P &>(*this); } template<typename T> P &o(const T x, const char *f = "") { - format_element(f, ptype_treats<T>::size_specifier(), "o", x); + format_element(f, ptype_traits<T>::size_specifier(), "o", x); return static_cast<P &>(*this); } |