00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PALUDIS_GUARD_PALUDIS_STRINGIFY_HH
00021 #define PALUDIS_GUARD_PALUDIS_STRINGIFY_HH 1
00022
00023 #include <paludis/util/attributes.hh>
00024 #include <paludis/util/validated-fwd.hh>
00025 #include <tr1/memory>
00026 #include <sstream>
00027 #include <string>
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 namespace paludis
00040 {
00041
00042
00043
00044
00045
00046 namespace stringify_internals
00047 {
00048
00049
00050
00051
00052
00053 template <typename T_>
00054 struct CheckType
00055 {
00056
00057 enum { value = 0 } Value;
00058 };
00059
00060
00061
00062
00063
00064
00065
00066 template <typename T_>
00067 struct CheckType<T_ *>
00068 {
00069 };
00070
00071
00072
00073
00074
00075
00076
00077 template <typename T_>
00078 struct CheckType<std::tr1::shared_ptr<T_> >
00079 {
00080 };
00081
00082
00083
00084
00085
00086
00087
00088 template <>
00089 struct CheckType<char *>
00090 {
00091
00092 enum { value = 0 } Value;
00093 };
00094 }
00095
00096 template <typename T_> inline std::string stringify(const T_ & item);
00097
00098 namespace stringify_internals
00099 {
00100
00101
00102
00103
00104
00105
00106
00107 template <typename T_>
00108 std::string
00109 real_stringify(const T_ & item)
00110 {
00111
00112 int check_for_stringifying_silly_things
00113 PALUDIS_ATTRIBUTE((unused)) = CheckType<T_>::value;
00114
00115 std::ostringstream s;
00116 s << item;
00117 return s.str();
00118 }
00119
00120 inline std::string
00121 real_stringify(const std::string & item)
00122 {
00123 return item;
00124 }
00125
00126 inline std::string
00127 real_stringify(const char & item)
00128 {
00129 return std::string(1, item);
00130 }
00131
00132 inline std::string
00133 real_stringify(const unsigned char & item)
00134 {
00135 return std::string(1, item);
00136 }
00137
00138 inline std::string
00139 real_stringify(const bool & item)
00140 {
00141 return item ? "true" : "false";
00142 }
00143
00144 inline std::string
00145 real_stringify(const char * const item)
00146 {
00147 return std::string(item);
00148 }
00149
00150 template <typename D_, typename V_, bool c_, typename C_>
00151 inline std::string
00152 real_stringify(const Validated<D_, V_, c_, C_> & v)
00153 {
00154 return stringify(v.data());
00155 }
00156 }
00157
00158
00159
00160
00161
00162
00163
00164 template <typename T_>
00165 inline std::string
00166 stringify(const T_ & item)
00167 {
00168 return stringify_internals::real_stringify(item);
00169 }
00170 }
00171
00172 #endif