1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2007-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_TYPE_TO_STRING_HPP_JOFA_080416
9 #define BOOST_ICL_TYPE_TO_STRING_HPP_JOFA_080416
15 #include <boost/type_traits/is_integral.hpp>
16 #include <boost/type_traits/is_float.hpp>
17 #include <boost/mpl/if.hpp>
19 namespace boost{ namespace icl
21 //--------------------------------------------------------------------------
25 /** Convert the type to it's typestring */
26 static std::string apply();
30 //--------------------------------------------------------------------------
31 template<>inline std::string type_to_string<bool>::apply() { return "bool"; }
32 template<>inline std::string type_to_string<char>::apply() { return "char"; }
33 template<>inline std::string type_to_string<short>::apply(){ return "short"; }
34 template<>inline std::string type_to_string<int>::apply() { return "int"; }
35 template<>inline std::string type_to_string<long>::apply() { return "long"; }
36 template<>inline std::string type_to_string<long long>::apply(){ return "Long"; }
38 template<>inline std::string type_to_string<unsigned char>::apply(){ return "char+"; }
39 template<>inline std::string type_to_string<unsigned short>::apply(){ return "short+"; }
40 template<>inline std::string type_to_string<unsigned int>::apply() { return "int+"; }
41 template<>inline std::string type_to_string<unsigned long>::apply() { return "long+"; }
42 template<>inline std::string type_to_string<unsigned long long>::apply(){ return "Long+"; }
44 template<>inline std::string type_to_string<float>::apply() { return "flt"; }
45 template<>inline std::string type_to_string<double>::apply() { return "dbl"; }
46 template<>inline std::string type_to_string<std::string>::apply() { return "string"; }
48 //-------------------------------------------------------------------------
49 template<template<class> class Templ>
50 struct unary_template_to_string
52 static std::string apply();
55 template <template<class>class Unary, class Type>
56 struct type_to_string<Unary<Type> >
58 static std::string to_string()
60 return unary_template_to_string<Unary>::apply()+"<"+type_to_string<Type>::apply()+">";
64 // ---------------------------------------------------------------------------
65 template<template<class,class>class Templ>
66 struct binary_template_to_string
68 static std::string apply();
71 template <template<class Type1, class Type2>class Binary, class Type1, class Type2>
72 struct type_to_string<Binary<Type1, Type2> >
74 static std::string apply()
76 return binary_template_to_string<Binary>::apply()+
77 "<"+type_to_string<Type1>::apply()+","+type_to_string<Type2>::apply()+">";
81 }} // namespace boost icl