inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_month& m) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_month_names(), f.get_long_month_names(), (greg_month::max)(), s); } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast bc){ std::cout << "Month exception caught" << std::endl; charT a = '\0'; const facet_def* f = create_facet_def(a); num = date_time::find_match(f->get_short_month_names(), f->get_long_month_names(), (greg_month::max)(), s); delete(f); } num += 1; // months numbered 1-12 m = greg_month(num); return is; }
inline std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is,greg_month& m) { typedef boost::date_time::all_date_names_put<greg_facet_config, charT> facet_def; std::basic_string<charT> s; is >> s; if(!std::has_facet<facet_def>(is.getloc())) { std::locale loc = is.getloc(); charT a = '\0'; is.imbue(generate_locale(loc, a)); } short num = 0; try{ const facet_def& f = std::use_facet<facet_def>(is.getloc()); num = date_time::find_match(f.get_short_month_names(), f.get_long_month_names(), (greg_month::max)(), s); // greg_month spans 1..12, so max returns the array size, // which is needed by find_match } /* bad_cast will be thrown if the desired facet is not accessible * so we can generate the facet. This has the drawback of using english * names as a default. */ catch(std::bad_cast&){ charT a = '\0'; std::auto_ptr< const facet_def > f(create_facet_def(a)); num = date_time::find_match(f->get_short_month_names(), f->get_long_month_names(), (greg_month::max)(), s); // greg_month spans 1..12, so max returns the array size, // which is needed by find_match } ++num; // months numbered 1-12 m = greg_month(num); return is; }