define explicit specialisations for primitive types

This commit is contained in:
Fischlurch 2011-12-30 05:13:27 +01:00
parent e054c272b6
commit 0d136e2703
4 changed files with 51 additions and 21 deletions

View file

@ -103,18 +103,38 @@ namespace util {
pushParameter(string("(null)")); pushParameter(string("(null)"));
} }
template<>
void
_Fmt::pushParameter (const char * const cString)
{
pushParameter (cString);
}
/* ===== explicitly supported =================== */ /* ===== explicitly supported =================== */
template void _Fmt::pushParameter(string const&); 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(int const&);
template void _Fmt::pushParameter(uint 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(float const&);
template void _Fmt::pushParameter(double 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 string * const);
template void _Fmt::pushParameter(const uchar * const);
template void _Fmt::pushParameter(const int * const); template void _Fmt::pushParameter(const int * const);
template void _Fmt::pushParameter(const uint * 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 float * const);
template void _Fmt::pushParameter(const double * const); template void _Fmt::pushParameter(const double * const);

View file

@ -71,6 +71,8 @@ namespace std { // forward declaration to avoid including <iostream>
namespace util { namespace util {
typedef unsigned char uchar;
using boost::enable_if; using boost::enable_if;
using std::string; using std::string;
@ -78,7 +80,6 @@ namespace util {
/** /**
* @todo write type comment * @todo write type comment
*/ */
@ -173,17 +174,25 @@ namespace util {
/* the following definitions enable some basic types /* the following definitions enable some basic types
* to be forwarded to boost::format literally */ * to be forwarded to boost::format literally */
template<> struct _shall_forward<string> { enum{ value = true }; }; template<> struct _shall_forward<string> { enum{ value = true }; };
template<> struct _shall_forward<char> { enum{ value = true }; };
template<> struct _shall_forward<uchar> { enum{ value = true }; };
template<> struct _shall_forward<int> { enum{ value = true }; }; template<> struct _shall_forward<int> { enum{ value = true }; };
template<> struct _shall_forward<uint> { enum{ value = true }; }; template<> struct _shall_forward<uint> { enum{ value = true }; };
template<> struct _shall_forward<short> { enum{ value = true }; };
template<> struct _shall_forward<ushort> { enum{ value = true }; };
template<> struct _shall_forward<int64_t> { enum{ value = true }; };
template<> struct _shall_forward<uint64_t>{ enum{ value = true }; };
template<> struct _shall_forward<float> { enum{ value = true }; }; template<> struct _shall_forward<float> { enum{ value = true }; };
template<> struct _shall_forward<double> { enum{ value = true }; }; template<> struct _shall_forward<double> { enum{ value = true }; };
template<> struct _shall_forward<void*> { enum{ value = true }; };
template<typename X> template<typename X>
struct _shall_convert_toString struct _shall_convert_toString
{ {
enum{ value = ! _shall_forward<X>::value enum{ value = ! _shall_forward<X>::value
&& lib::meta::_can_convertToString<X>::value && lib::meta::can_convertToString<X>::value
&& !lib::meta::is_sameType<X,char*>::value
}; };
}; };

View file

@ -75,7 +75,7 @@ namespace meta {
* @see string-util.hpp more elaborate solution including lexical_cast * @see string-util.hpp more elaborate solution including lexical_cast
*/ */
template<typename T> template<typename T>
struct _can_convertToString struct can_convertToString
{ {
static T & probe(); static T & probe();

View file

@ -89,8 +89,9 @@ namespace test {
_Fmt formatter (formatString); _Fmt formatter (formatString);
uint val = rand() % 100; uint val = rand() % 100;
void *pt = &val;
formatter % &val; formatter % &pt;
formatter % val; formatter % val;
cout << formatter << endl; cout << formatter << endl;
@ -266,7 +267,7 @@ namespace test {
float f(12.34); float * pf = & f; float f(12.34); float * pf = & f;
double d(-12.34); double * pd = & d; double d(-12.34); double * pd = & d;
char c(0x40); char * pc = & c; char c(0x40); char * pc = & c;
unsigned char uc(0xff); unsigned char * puc = & uc; uchar uc(0xff); uchar * puc = & uc;
string str("Lumiera"); string * pstr = &str; string str("Lumiera"); string * pstr = &str;
CHECK (_Fmt("%d") % i == _Fmt("%d") % pi); CHECK (_Fmt("%d") % i == _Fmt("%d") % pi);