00001 00002 00003 00004 00005 00006 #ifndef TYPING0_ 00007 #define TYPING0_ 00008 00009 #include "eleve/config.hpp" 00010 00011 #include <list> 00012 #include <vector> 00013 #include <typeinfo> 00014 #include <iostream> 00015 #include <algorithm> 00016 #include <iomanip> 00017 00018 #include <boost/noncopyable.hpp> 00019 #include <boost/bind.hpp> 00020 #include <boost/lexical_cast.hpp> 00021 #include <boost/any.hpp> 00022 #include <boost/numeric/conversion/converter.hpp> 00023 #include <boost/type_traits.hpp> 00024 #include <boost/utility/enable_if.hpp> 00025 #include <boost/lexical_cast.hpp> 00026 00027 #include <boost/date_time/gregorian/gregorian_types.hpp> 00028 #include <boost/date_time/gregorian/formatters.hpp> 00029 #include <boost/date_time/gregorian/parsers.hpp> 00030 00031 #include "eleve/src/runtime2.hpp" 00032 00034 namespace boost { 00035 00037 namespace gregorian { 00038 00040 template<class charT> 00041 inline std::basic_string<charT> to_uk_string_type(const date& d) 00042 { 00043 date::ymd_type ymd = d.year_month_day(); 00044 std::basic_ostringstream<charT> ss; 00045 ss << std::setw(2) << std::setfill(ss.widen('0')) 00046 << ymd.day 00047 << "-"; 00048 ss << std::setw(2) << std::setfill(ss.widen('0')) 00049 << ymd.month.as_number() 00050 << "-"; 00051 ss << ymd.year ; 00052 00053 return ss.str(); 00054 } 00055 00056 inline std::string to_uk_string(const date& d) { 00057 return to_uk_string_type<char>(d); 00058 } 00059 00061 template<class charT> 00062 inline std::basic_string<charT> to_us_string_type(const date& d) 00063 { 00064 date::ymd_type ymd = d.year_month_day(); 00065 std::basic_ostringstream<charT> ss; 00066 ss << std::setw(2) << std::setfill(ss.widen('0')) 00067 << ymd.month.as_number() 00068 << "-"; 00069 ss << std::setw(2) << std::setfill(ss.widen('0')) 00070 << ymd.day 00071 << "-"; 00072 ss << ymd.year ; 00073 00074 return ss.str(); 00075 } 00076 inline std::string to_us_string(const date& d) { 00077 return to_us_string_type<char>(d); 00078 } 00079 00080 }} 00081 00082 namespace eepgwde { namespace detail { 00083 00107 00115 template <typename T, typename Enable = void> 00116 struct Numeric { }; 00117 00118 struct is_Numeric {}; 00119 00120 template <class T> 00121 struct Numeric<T, typename enable_if<is_arithmetic<T> >::type> : 00122 public is_Numeric { 00123 typedef T value_type; 00124 T d_; 00125 00126 Numeric() : d_(0) {} 00127 Numeric(const T & d) : d_(d) {} 00128 Numeric(const Numeric & d) : d_(d.d_) {} 00129 00130 const Numeric operator() () const { 00131 return Numeric(d_); 00132 } 00133 00134 operator double () const { 00135 typedef typename boost::promote<T>::type promoted; 00136 return boost::numeric::converter<double,promoted>::convert(d_); 00137 } 00138 00139 operator std::string () const { 00140 return boost::lexical_cast<std::string>(d_); 00141 } 00142 00144 template <typename U> 00145 friend std::ostream& operator<< (std::ostream& o, 00146 const Numeric<U> & ); 00148 template <typename U> 00149 friend std::istream& operator>> (std::istream& i, 00150 Numeric<U> & ); 00151 }; 00152 00153 template <typename T> 00154 std::ostream& operator<< (std::ostream& o, const Numeric<T> & t) { 00155 return o << t.d_; 00156 } 00157 00158 template <typename T> 00159 std::istream& operator>> (std::istream& i, Numeric<T> & t) { 00160 return i >> t.d_; 00161 } 00162 00170 struct usdate : public boost::gregorian::date { 00171 usdate() : boost::gregorian::date() {} 00172 usdate(const boost::gregorian::date & d) : boost::gregorian::date(d) { 00173 } 00174 }; 00175 00176 std::ostream& operator<< (std::ostream& o, const usdate & t); 00177 std::istream& operator>> (std::istream& i, usdate & t); 00178 00186 struct posixdate : public boost::gregorian::date { 00187 posixdate() : boost::gregorian::date() {} 00188 posixdate(const boost::gregorian::date & d) : boost::gregorian::date(d) { 00189 } 00190 }; 00191 00192 std::ostream& operator<< (std::ostream& o, const posixdate & t); 00193 std::istream& operator>> (std::istream& i, posixdate & t); 00194 00202 struct eudate : public boost::gregorian::date { 00203 eudate() : boost::gregorian::date() {} 00204 eudate(const boost::gregorian::date & d) : boost::gregorian::date(d) { 00205 } 00206 }; 00207 00208 std::ostream& operator<< (std::ostream& o, const eudate & t); 00209 std::istream& operator>> (std::istream& i, eudate & t); 00210 00211 template <typename T, int P, int Q> 00212 struct scaling { 00213 typedef T scaling_type; 00214 T scale() const { 00215 return static_cast<T>(static_cast<T>(P) / static_cast<T>(Q)); 00216 } 00217 }; 00218 00226 struct rate : public Numeric<double>, public scaling<double, 1, 100> { 00227 rate() : Numeric<double>(0) {} 00228 rate(const double & d) : Numeric<double>(d) {} 00229 rate(const Numeric<double> & d) : Numeric<double>(d.d_) {} 00230 }; 00231 00239 struct bps : public Numeric<double>, public scaling<double, 1, 100*100> { 00240 bps() : Numeric<double>(0) {} 00241 bps(const double & d) : Numeric<double>(d) {} 00242 bps(const Numeric<double> & d) : Numeric<double>(d.d_) {} 00243 }; 00244 00246 00247 }} 00248 00249 namespace eepgwde { namespace detail { 00250 00265 00273 template <typename B, typename T> 00274 struct pointerize0 : public std::unary_function<T, B> { 00275 B operator()(T & t) { 00276 return &t; 00277 } 00278 }; 00279 00289 template <typename B, typename C> 00290 B pointerize(C & c) { 00291 B b(c.size()); 00292 transform(c.begin(), c.end(), 00293 b.begin(), 00294 pointerize0<typename B::value_type, typename C::value_type>() ); 00295 return b; 00296 } 00297 00308 template <typename B, typename C> 00309 B pointerize1(C b, C e) { 00310 B x( distance(b,e) ); 00311 transform(b, e, 00312 x.begin(), 00313 pointerize0<typename B::value_type, typename C::value_type>() ); 00314 return x; 00315 } 00316 00318 00319 namespace i0 { 00322 00327 template <int> struct dummy { dummy(int) {} }; 00328 00330 } 00331 00332 }} 00333 00334 #endif 00335 00344