00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 #ifndef TYPING3_ 00019 #define TYPING3_ 00020 00021 #include "eleve/config.hpp" 00022 00023 #include <boost/utility/enable_if.hpp> 00024 #include <boost/type_traits.hpp> 00025 #include <boost/date_time/gregorian/formatters.hpp> 00026 00027 #include "eleve/src/typing0.hpp" 00028 00033 00034 namespace eepgwde { 00035 00041 00042 namespace detail { 00043 00050 namespace i0 { 00051 00052 using boost::enable_if; 00053 00056 00071 00075 00077 template <typename U> 00078 typename enable_if<boost::is_arithmetic<U>, U>::type 00079 null1(dummy<0> = 0) { return std::numeric_limits<U>::min(); } 00080 00082 template <typename U> 00083 typename enable_if<boost::is_base_of<std::string, U>, U>::type 00084 null1(dummy<0> = 1) { return std::string(""); } 00085 00087 template <typename U> 00088 typename enable_if<boost::is_base_of<boost::gregorian::date, U>, U>::type 00089 null1(dummy<0> = 2) { 00090 return boost::gregorian::date(1901,1,1); 00091 } 00092 00094 template <typename U> 00095 typename enable_if_c<boost::is_arithmetic<typename U::value_type>::value && !boost::is_base_of<std::string, U>::value, U>::type 00096 null1(dummy<0> = 3) { 00097 return null1<typename U::value_type>(); 00098 } 00099 00101 template <typename U> 00102 typename enable_if<boost::is_base_of<boost::any, U>, U>::type 00103 null1(dummy<0> = 4) { 00104 return boost::any(); 00105 } 00106 00110 template <typename U> 00111 typename disable_if_c<boost::is_base_of<boost::any, U>::value || 00112 boost::is_arithmetic<U>::value || 00113 boost::is_arithmetic<typename U::value_type>::value || 00114 boost::is_base_of<std::string, U>::value || 00115 !(boost::has_trivial_default_constructor<U>::value) 00116 , U>::type 00117 null1(dummy<1> = 1) { 00118 return U(); 00119 } 00122 } 00123 00124 namespace i0 { 00125 00136 00138 template <typename U> 00139 std::string 00140 ys(typename enable_if< boost::is_base_of<boost::any, U>, U>::type, 00141 const boost::any &o, dummy<0> = 0) 00142 throw (std::domain_error &) { 00143 return std::string(""); 00144 } 00145 00149 template <typename U> 00150 std::string 00151 ys(typename enable_if< boost::is_arithmetic<U>, U>::type, 00152 const boost::any &o, dummy<0> = 0) 00153 throw (std::domain_error &) { 00154 U r(boost::any_cast<U>(o)); 00155 return boost::lexical_cast<std::string>(r); 00156 } 00157 00161 template <typename U> 00162 std::string 00163 ys(typename enable_if<boost::is_arithmetic<typename U::value_type>,U>::type, 00164 const boost::any &o, dummy<0> = 0) 00165 throw (std::domain_error &) { 00166 U r(boost::any_cast<U>(o)); 00167 return boost::lexical_cast<std::string>(r); 00168 } 00169 00173 template <typename U> 00174 std::string 00175 ys(typename enable_if_c<boost::is_base_of<boost::gregorian::date, U>::value && 00176 !(boost::is_same<boost::gregorian::date, U>::value) 00177 , U>::type, 00178 const boost::any &o, dummy<0> = 0) 00179 throw (std::domain_error &) { 00180 U r(boost::any_cast<U>(o)); 00181 return boost::lexical_cast<std::string>(r); 00182 } 00183 00186 } 00187 00188 namespace i0 { 00189 00200 00201 template <typename U> 00202 typename enable_if<boost::is_arithmetic<typename U::scaling_type> 00203 , dummy<0> >::type 00204 scale0(U & u) { 00205 typename U::scaling_type a(u.scale()); 00206 u.d_ *= a; 00207 } 00208 00209 template <typename U> 00210 typename enable_if<boost::is_base_of<std::string, U> 00211 , dummy<0> >::type 00212 scale0(U & u) { 00213 } 00214 00215 template <typename U> 00216 typename enable_if_c< 00217 boost::is_arithmetic<typename U::value_type>::value && 00218 !(boost::is_arithmetic<typename U::scaling_type>::value) 00219 , dummy<0> >::type 00220 scale0(U & u) { 00221 } 00222 00223 template <typename U> 00224 typename enable_if<boost::is_arithmetic<U> 00225 , dummy<0> >::type 00226 scale0(U & u) { 00227 } 00228 00230 template <typename U> 00231 U xs(typename enable_if<boost::is_base_of<is_Numeric, U> 00232 , U>::type, 00233 const std::string & s, 00234 dummy<0> = 1) 00235 throw (std::domain_error &) { 00236 U r(boost::lexical_cast<U>(s)); 00237 scale0<U>(r); 00238 return r; 00239 } 00240 00242 template <typename U> 00243 U xs(typename enable_if<boost::is_arithmetic<U> 00244 , U>::type, 00245 const std::string & s, 00246 dummy<0> = 1) 00247 throw (std::domain_error &) { 00248 U r(boost::lexical_cast<U>(s)); 00249 return r; 00250 } 00251 00253 template <typename U> 00254 U xs(typename enable_if<boost::is_base_of<std::string, U> 00255 , U>::type, 00256 const std::string & s, 00257 dummy<0> = 1) 00258 throw (std::domain_error &) { 00259 U r(boost::lexical_cast<U>(s)); 00260 return r; 00261 } 00262 00264 template <typename U> 00265 U xs(typename enable_if<boost::is_same<boost::any, U>, U>::type, 00266 const std::string & s, dummy<0> = 1) 00267 throw (std::domain_error &) { 00268 return boost::any(); 00269 } 00270 00272 template <typename U> 00273 U xs(typename enable_if<boost::is_base_of<boost::gregorian::date, U>, U>::type, 00274 const std::string & s, dummy<0> = 1) 00275 throw (std::domain_error &) { 00276 U r(boost::lexical_cast<U>(s)); 00277 return r; 00278 } 00279 00282 00283 } 00284 00285 }} 00286 00287 #endif 00288 00297