Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:39

0001 #ifndef DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
0002 #define DATE_TIME_TIME_FORMATTING_STREAMS_HPP___
0003 
0004 /* Copyright (c) 2002,2003 CrystalClear Software, Inc.
0005  * Use, modification and distribution is subject to the 
0006  * Boost Software License, Version 1.0. (See accompanying
0007  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
0008  * Author: Jeff Garland, Bart Garst
0009  * $Date$
0010  */
0011 
0012 #include <boost/date_time/compiler_config.hpp>
0013 
0014 #ifndef BOOST_DATE_TIME_NO_LOCALE
0015 
0016 #include <locale>
0017 #include <iomanip>
0018 #include <iostream>
0019 #include <boost/date_time/date_formatting_locales.hpp>
0020 #include <boost/date_time/time_resolution_traits.hpp>
0021 
0022 namespace boost {
0023 namespace date_time {
0024 
0025 
0026   //! Put a time type into a stream using appropriate facets
0027   template<class time_duration_type,
0028            class charT = char>
0029   class ostream_time_duration_formatter
0030   {
0031   public:
0032     typedef std::basic_ostream<charT> ostream_type;
0033     typedef typename time_duration_type::fractional_seconds_type fractional_seconds_type;
0034 
0035     //! Put time into an ostream 
0036     static void duration_put(const time_duration_type& td, 
0037                              ostream_type& os)
0038     {
0039       if(td.is_special()) {
0040         os << td.get_rep(); 
0041       }
0042       else {
0043         charT fill_char = '0';
0044         if(td.is_negative()) {
0045           os << '-';
0046         }
0047         os  << std::setw(2) << std::setfill(fill_char) 
0048             << absolute_value(td.hours()) << ":";
0049         os  << std::setw(2) << std::setfill(fill_char) 
0050             << absolute_value(td.minutes()) << ":";
0051         os  << std::setw(2) << std::setfill(fill_char) 
0052             << absolute_value(td.seconds());
0053         fractional_seconds_type frac_sec = 
0054           absolute_value(td.fractional_seconds());
0055         if (frac_sec != 0) {
0056           os  << "." 
0057               << std::setw(time_duration_type::num_fractional_digits())
0058               << std::setfill(fill_char)
0059               << frac_sec;
0060         }
0061       } // else
0062     } // duration_put
0063   }; //class ostream_time_duration_formatter
0064 
0065   //! Put a time type into a stream using appropriate facets
0066   template<class time_type,
0067            class charT = char>
0068   class ostream_time_formatter
0069   {
0070   public:
0071     typedef std::basic_ostream<charT> ostream_type;
0072     typedef typename time_type::date_type date_type;
0073     typedef typename time_type::time_duration_type time_duration_type;
0074     typedef ostream_time_duration_formatter<time_duration_type, charT> duration_formatter;
0075 
0076     //! Put time into an ostream 
0077     static void time_put(const time_type& t, 
0078                          ostream_type& os)
0079     {
0080       date_type d = t.date();
0081       os << d;
0082       if(!d.is_infinity() && !d.is_not_a_date())
0083       {
0084         os << " "; //TODO: fix the separator here.
0085         duration_formatter::duration_put(t.time_of_day(), os);
0086       }
0087       
0088     } // time_to_ostream    
0089   }; //class ostream_time_formatter
0090 
0091 
0092   //! Put a time period into a stream using appropriate facets
0093   template<class time_period_type,
0094            class charT = char>
0095   class ostream_time_period_formatter
0096   {
0097   public:
0098     typedef std::basic_ostream<charT> ostream_type;
0099     typedef typename time_period_type::point_type time_type;
0100     typedef ostream_time_formatter<time_type, charT> time_formatter;
0101 
0102     //! Put time into an ostream 
0103     static void period_put(const time_period_type& tp, 
0104                            ostream_type& os)
0105     {
0106       os << '['; //TODO: facet or manipulator for periods?
0107       time_formatter::time_put(tp.begin(), os);
0108       os << '/'; //TODO: facet or manipulator for periods?
0109       time_formatter::time_put(tp.last(), os);
0110       os << ']'; 
0111 
0112     } // period_put
0113 
0114   }; //class ostream_time_period_formatter
0115 
0116 
0117   
0118 } } //namespace date_time
0119 
0120 #endif //BOOST_DATE_TIME_NO_LOCALE
0121 
0122 #endif