From 0d136e2703f69bc21822c98bb9a3055de3c50ef1 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 30 Dec 2011 05:13:27 +0100 Subject: [PATCH] define explicit specialisations for primitive types --- src/lib/format-string.cpp | 20 ++++++++++++++++++ src/lib/format-string.hpp | 15 +++++++++++--- src/lib/meta/util.hpp | 2 +- tests/lib/format-string-test.cpp | 35 ++++++++++++++++---------------- 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/lib/format-string.cpp b/src/lib/format-string.cpp index 4db936d6e..d0804c77f 100644 --- a/src/lib/format-string.cpp +++ b/src/lib/format-string.cpp @@ -103,18 +103,38 @@ namespace util { pushParameter(string("(null)")); } + template<> + void + _Fmt::pushParameter (const char * const cString) + { + pushParameter (cString); + } + + /* ===== explicitly supported =================== */ template void _Fmt::pushParameter(string const&); + template void _Fmt::pushParameter(char const&); + template void _Fmt::pushParameter(uchar const&); template void _Fmt::pushParameter(int const&); template void _Fmt::pushParameter(uint const&); + template void _Fmt::pushParameter(short const&); + template void _Fmt::pushParameter(ushort const&); + template void _Fmt::pushParameter(int64_t const&); + template void _Fmt::pushParameter(uint64_t const&); template void _Fmt::pushParameter(float const&); template void _Fmt::pushParameter(double const&); + template void _Fmt::pushParameter(void * const&); template void _Fmt::pushParameter(const string * const); + template void _Fmt::pushParameter(const uchar * const); template void _Fmt::pushParameter(const int * const); template void _Fmt::pushParameter(const uint * const); + template void _Fmt::pushParameter(const short * const); + template void _Fmt::pushParameter(const ushort * const); + template void _Fmt::pushParameter(const int64_t * const); + template void _Fmt::pushParameter(const uint64_t * const); template void _Fmt::pushParameter(const float * const); template void _Fmt::pushParameter(const double * const); diff --git a/src/lib/format-string.hpp b/src/lib/format-string.hpp index b1a8ce44b..d7eb1fde2 100644 --- a/src/lib/format-string.hpp +++ b/src/lib/format-string.hpp @@ -71,10 +71,11 @@ namespace std { // forward declaration to avoid including namespace util { + typedef unsigned char uchar; + using boost::enable_if; using std::string; - - + @@ -173,17 +174,25 @@ namespace util { /* the following definitions enable some basic types * to be forwarded to boost::format literally */ template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; template<> struct _shall_forward { enum{ value = true }; }; template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward{ enum{ value = true }; }; template<> struct _shall_forward { enum{ value = true }; }; template<> struct _shall_forward { enum{ value = true }; }; + template<> struct _shall_forward { enum{ value = true }; }; template struct _shall_convert_toString { enum{ value = ! _shall_forward::value - && lib::meta::_can_convertToString::value + && lib::meta::can_convertToString::value + && !lib::meta::is_sameType::value }; }; diff --git a/src/lib/meta/util.hpp b/src/lib/meta/util.hpp index f305c46bb..91724943f 100644 --- a/src/lib/meta/util.hpp +++ b/src/lib/meta/util.hpp @@ -75,7 +75,7 @@ namespace meta { * @see string-util.hpp more elaborate solution including lexical_cast */ template - struct _can_convertToString + struct can_convertToString { static T & probe(); diff --git a/tests/lib/format-string-test.cpp b/tests/lib/format-string-test.cpp index e87fe8739..acc39eb7e 100644 --- a/tests/lib/format-string-test.cpp +++ b/tests/lib/format-string-test.cpp @@ -89,8 +89,9 @@ namespace test { _Fmt formatter (formatString); uint val = rand() % 100; + void *pt = &val; - formatter % &val; + formatter % &pt; formatter % val; cout << formatter << endl; @@ -102,7 +103,7 @@ namespace test { { int i(-12); CHECK (_Fmt("%d") % i == "-12" ); - CHECK (_Fmt("%6d") % i == "- 12" ); + CHECK (_Fmt("%6d") % i == " -12" ); CHECK (_Fmt("%-6d") % i == "-12 " ); CHECK (_Fmt("%+-6d") % -i == "+12 " ); CHECK (_Fmt("%+06d") % -i == "+00012" ); @@ -242,8 +243,8 @@ namespace test { verify_errorHandling () { cout << _Fmt("__nix_") % 1 % 2 << endl; - cout << _Fmt("__%d__") << endl; - cout << _Fmt("__%d__") % 1 << endl; + cout << _Fmt("__%d__") << endl; + cout << _Fmt("__%d__") % 1 << endl; cout << _Fmt("__%d__") % 1 % 2 << endl; cout << _Fmt("__%d__") % "dirt" << endl; @@ -255,19 +256,19 @@ namespace test { void verify_pointerHandling () { - int i(-12); int * pi = & i; - uint u(12); uint * pu = & u; - short sh(-123); short * psh = & sh; - ushort ush(123); ushort *push = &ush; - long l(-123); long * pl = & l; - ulong ul(123); ulong * pul = & ul; - int64_t ll(5e+9); int64_t * pll = & ll; - uint64_t ull(ll); uint64_t *pull = &ull; - float f(12.34); float * pf = & f; - double d(-12.34); double * pd = & d; - char c(0x40); char * pc = & c; - unsigned char uc(0xff); unsigned char * puc = & uc; - string str("Lumiera"); string *pstr = &str; + int i(-12); int * pi = & i; + uint u(12); uint * pu = & u; + short sh(-123); short * psh = & sh; + ushort ush(123); ushort * push = &ush; + long l(-123); long * pl = & l; + ulong ul(123); ulong * pul = & ul; + int64_t ll(5e+9); int64_t * pll = & ll; + uint64_t ull(ll); uint64_t * pull = &ull; + float f(12.34); float * pf = & f; + double d(-12.34); double * pd = & d; + char c(0x40); char * pc = & c; + uchar uc(0xff); uchar * puc = & uc; + string str("Lumiera"); string * pstr = &str; CHECK (_Fmt("%d") % i == _Fmt("%d") % pi); CHECK (_Fmt("%d") % u == _Fmt("%d") % pu);