gregorian_io.hpp
来自「Boost provides free peer-reviewed portab」· HPP 代码 · 共 778 行 · 第 1/2 页
HPP
778 行
operator>>(std::basic_istream<CharT, Traits>& is, greg_year& gy) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, gy); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, gy); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } /********** date generator types **********/ template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::partial_date& pd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), pd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), pd); } return os; } //! input operator for partial_date template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, partial_date& pd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, pd); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, pd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::nth_day_of_the_week_in_month& nkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), nkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), nkd); } return os; } //! input operator for nth_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, nth_day_of_the_week_in_month& nday) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, nday); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, nday); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_in_month& fkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fkd); } return os; } //! input operator for first_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_in_month& fkd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, fkd); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fkd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::last_day_of_the_week_in_month& lkd) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), lkd); else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), lkd); } return os; } //! input operator for last_day_of_the_week_in_month template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, last_day_of_the_week_in_month& lkd) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, lkd); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, lkd); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_after& fda) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) { std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fda); } else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fda); } return os; } //! input operator for first_day_of_the_week_after template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_after& fka) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, fka); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fka); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } template <class CharT, class TraitsT> inline std::basic_ostream<CharT, TraitsT>& operator<<(std::basic_ostream<CharT, TraitsT>& os, const boost::gregorian::first_day_of_the_week_before& fdb) { boost::io::ios_flags_saver iflags(os); typedef boost::date_time::date_facet<date, CharT> custom_date_facet; std::ostreambuf_iterator<CharT> output_itr(os); if (std::has_facet<custom_date_facet>(os.getloc())) { std::use_facet<custom_date_facet>(os.getloc()).put(output_itr, os, os.fill(), fdb); } else { custom_date_facet* f = new custom_date_facet(); std::locale l = std::locale(os.getloc(), f); os.imbue(l); f->put(output_itr, os, os.fill(), fdb); } return os; } //! input operator for first_day_of_the_week_before template <class CharT, class Traits> inline std::basic_istream<CharT, Traits>& operator>>(std::basic_istream<CharT, Traits>& is, first_day_of_the_week_before& fkb) { boost::io::ios_flags_saver iflags(is); typename std::basic_istream<CharT, Traits>::sentry strm_sentry(is, false); if (strm_sentry) { try { typedef typename date_time::date_input_facet<date, CharT> date_input_facet; std::istreambuf_iterator<CharT,Traits> sit(is), str_end; if(std::has_facet<date_input_facet>(is.getloc())) { std::use_facet<date_input_facet>(is.getloc()).get(sit, str_end, is, fkb); } else { date_input_facet* f = new date_input_facet(); std::locale l = std::locale(is.getloc(), f); is.imbue(l); f->get(sit, str_end, is, fkb); } } catch(...) { std::ios_base::iostate exception_mask = is.exceptions(); if(std::ios_base::failbit & exception_mask) { try { is.setstate(std::ios_base::failbit); } catch(std::ios_base::failure&) {} throw; // rethrow original exception } else { is.setstate(std::ios_base::failbit); } } } return is; } } } // namespaces#endif // DATE_TIME_GREGORIAN_IO_HPP__
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?