00001 00010 #include "scalt0.hpp" 00011 00012 #include <iostream> 00013 00014 #include <ql/utilities/tracing.hpp> 00015 #include <boost/date_time/gregorian/formatters.hpp> 00016 00017 #include "scal0.hpp" 00018 00019 namespace eepgwde { namespace detail { namespace i0 { 00020 00022 template <typename U> 00023 typename enable_if<boost::is_arithmetic<U>, U>::type 00024 null1(dummy<0> = 0) { return std::numeric_limits<U>::min(); } 00025 00027 template <typename U> 00028 typename enable_if<boost::is_base_of<std::string, U>, U>::type 00029 null1(dummy<0> = 1) { return std::string(""); } 00030 00032 template <typename U> 00033 typename enable_if<boost::is_base_of<boost::gregorian::date, U>, U>::type 00034 null1(dummy<0> = 2) { 00035 return boost::gregorian::date(1901,1,1); 00036 } 00037 00039 template <typename U> 00040 typename enable_if_c<boost::is_arithmetic<typename U::value_type>::value && !boost::is_base_of<std::string, U>::value, U>::type 00041 null1(dummy<0> = 3) { 00042 return null1<typename U::value_type>(); 00043 } 00044 00046 template <typename U> 00047 typename enable_if<boost::is_base_of<boost::any, U>, U>::type 00048 null1(dummy<0> = 4) { 00049 return boost::any(); 00050 } 00051 00055 template <typename U> 00056 typename disable_if_c<boost::is_base_of<boost::any, U>::value || 00057 boost::is_arithmetic<U>::value || 00058 boost::is_arithmetic<typename U::value_type>::value || 00059 boost::is_base_of<std::string, U>::value || 00060 !(boost::has_trivial_default_constructor<U>::value) 00061 , U>::type 00062 null1(dummy<1> = 1) { 00063 return U(); 00064 } 00065 00067 template <typename U> 00068 std::string 00069 ys(typename enable_if<boost::is_arithmetic<U>, U>::type, 00070 const boost::any &o, dummy<1> = 1) 00071 throw (std::domain_error &) { 00072 U r(boost::any_cast<U>(o)); 00073 return boost::lexical_cast<std::string>(r); 00074 } 00075 00077 template <typename U> 00078 std::string 00079 ys(typename enable_if<boost::is_same<boost::gregorian::date, U>, U>::type, 00080 const boost::any &o, dummy<1> = 1) 00081 throw (std::domain_error &) { 00082 U r(boost::any_cast<U>(o)); 00083 return boost::gregorian::to_simple_string(r); 00084 } 00085 00087 template <typename U> 00088 U xs(typename disable_if_c< 00089 boost::is_base_of<boost::gregorian::date, U>::value || 00090 boost::is_base_of<boost::any, U>::value 00091 , U>::type, 00092 const std::string & s, dummy<1> = 2) 00093 throw (std::domain_error &) { 00094 return boost::lexical_cast<U>(s); 00095 } 00096 00098 template <typename U> 00099 U xs(typename enable_if<boost::is_same<boost::gregorian::date, U>, U>::type, 00100 const std::string & s, dummy<1> = 2) 00101 throw (std::domain_error &) { 00102 boost::gregorian::date dt = boost::gregorian::from_simple_string(s); 00103 return dt; 00104 } 00105 00107 template <typename U> 00108 U xs(typename enable_if<boost::is_same<usdate, U>, U>::type, 00109 const std::string & s, dummy<1> = 2) 00110 throw (std::domain_error &) { 00111 U dt = boost::gregorian::from_us_string(s); 00112 return dt; 00113 } 00114 00116 template <typename U> 00117 U xs(typename enable_if<boost::is_same<eudate, U>, U>::type, 00118 const std::string & s, dummy<1> = 2) 00119 throw (std::domain_error &) { 00120 U dt = boost::gregorian::from_uk_string(s); 00121 return dt; 00122 } 00123 00125 template <typename U> 00126 U xs(typename enable_if<boost::is_base_of<boost::any, U>, U>::type, 00127 const std::string & s, dummy<1> = 2) 00128 throw (std::domain_error &) { 00129 return boost::any(); 00130 } 00131 00132 }}} 00133 00134 #include "eleve/src/typing1.hpp" 00135 00136 BOOST_AUTO_TEST_SUITE (typing4) 00137 00138 using namespace eepgwde::detail; 00139 using namespace boost; 00140 00150 BOOST_AUTO_TEST_CASE(tas0) 00151 { 00152 BOOST_TEST_MESSAGE("eepgwde::detail::as0"); 00153 00154 using namespace eepgwde::detail; 00155 00156 { 00157 Rate0 d(2); 00158 boost::any o(d); 00159 std::string s1; 00160 try { 00161 s1 = any_cast<std::string>(o); 00162 } catch (...) { 00163 s1="failed"; 00164 } 00165 00166 BOOST_TEST_MESSAGE( d << " " << s1 ); 00167 } 00168 00169 { 00170 std::string s("1"); 00171 boost::any o(s); 00172 00173 std::string s1 = any_cast<std::string>(o); 00174 00175 unsigned long d1 = lexical_cast<unsigned long>(s1); 00176 Rate0::value_type d2 = lexical_cast<Rate0::value_type>(s1); 00177 Rate0 d3 = lexical_cast<Rate0>(s1); 00178 00179 BOOST_TEST_MESSAGE( d1 << " " << d2 << " " << d3 ); 00180 } 00181 00182 } 00183 00186 BOOST_AUTO_TEST_CASE(tas2) 00187 { 00188 BOOST_TEST_MESSAGE("eepgwde::detail::as2"); 00189 00190 using namespace eepgwde::detail; 00191 00192 { 00193 int s(1); 00194 boost::any o(s); 00195 00196 std::string si0 = i0::ys<int>((null0<int>())(), o, i0::dummy<1>(1) ); 00197 00198 BOOST_TEST_MESSAGE( si0 ); 00199 } 00200 } 00201 00204 BOOST_AUTO_TEST_CASE(tas21) 00205 { 00206 BOOST_TEST_MESSAGE("eepgwde::detail::as21"); 00207 00208 using namespace eepgwde::detail; 00209 00210 { 00211 string s("1"); 00212 boost::any o(s); 00213 00214 int i0 = i0::xs<int>((null0<int>())(), s, i0::dummy<1>(2) ); 00215 00216 BOOST_TEST_MESSAGE( s << " " << i0 ); 00217 } 00218 00219 { 00220 string s("2009-11-12"); 00221 boost::any o(s); 00222 00223 boost::gregorian::date 00224 i0 = i0::xs<boost::gregorian::date>((null0<boost::gregorian::date>())(), s, i0::dummy<1>(2) ); 00225 00226 BOOST_TEST_MESSAGE( s << " " << boost::gregorian::to_simple_string(i0) ); 00227 } 00228 00229 } 00230 00231 BOOST_AUTO_TEST_SUITE_END()