Back to home page

EIC code displayed by LXR

 
 

    


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

0001 #ifndef POSIX_TIME_PRE133_OPERATORS_HPP___
0002 #define POSIX_TIME_PRE133_OPERATORS_HPP___
0003 
0004 /* Copyright (c) 2002-2004 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 /*! @file posix_time_pre133_operators.hpp
0013  * These input and output operators are for use with the 
0014  * pre 1.33 version of the date_time libraries io facet code. 
0015  * The operators used in version 1.33 and later can be found 
0016  * in posix_time_io.hpp */
0017 
0018 #include <iostream>
0019 #include <string>
0020 #include <sstream>
0021 #include "boost/date_time/compiler_config.hpp"
0022 #include "boost/date_time/gregorian/gregorian.hpp"
0023 #include "boost/date_time/posix_time/posix_time_duration.hpp"
0024 #include "boost/date_time/posix_time/ptime.hpp"
0025 #include "boost/date_time/posix_time/time_period.hpp"
0026 #include "boost/date_time/time_parsing.hpp"
0027 
0028 namespace boost {
0029 namespace posix_time {
0030 
0031 
0032 //The following code is removed for configurations with poor std::locale support (eg: MSVC6, gcc 2.9x)
0033 #ifndef BOOST_DATE_TIME_NO_LOCALE
0034 #if defined(USE_DATE_TIME_PRE_1_33_FACET_IO)
0035   //! ostream operator for posix_time::time_duration
0036   template <class charT, class traits>
0037   inline
0038   std::basic_ostream<charT, traits>&
0039   operator<<(std::basic_ostream<charT, traits>& os, const time_duration& td)
0040   {
0041     typedef boost::date_time::ostream_time_duration_formatter<time_duration, charT> duration_formatter;
0042     duration_formatter::duration_put(td, os);
0043     return os;
0044   }
0045 
0046   //! ostream operator for posix_time::ptime
0047   template <class charT, class traits>
0048   inline
0049   std::basic_ostream<charT, traits>&
0050   operator<<(std::basic_ostream<charT, traits>& os, const ptime& t)
0051   {
0052     typedef boost::date_time::ostream_time_formatter<ptime, charT> time_formatter;
0053     time_formatter::time_put(t, os);
0054     return os;
0055   }
0056 
0057   //! ostream operator for posix_time::time_period
0058   template <class charT, class traits>
0059   inline
0060   std::basic_ostream<charT, traits>&
0061   operator<<(std::basic_ostream<charT, traits>& os, const time_period& tp)
0062   {
0063     typedef boost::date_time::ostream_time_period_formatter<time_period, charT> period_formatter;
0064     period_formatter::period_put(tp, os);
0065     return os;
0066   }
0067 #endif // USE_DATE_TIME_PRE_1_33_FACET_IO
0068 /******** input streaming ********/
0069   template<class charT>
0070   inline
0071   std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_duration& td)
0072   {
0073     // need to create a std::string and parse it
0074     std::basic_string<charT> inp_s;
0075     std::stringstream out_ss;
0076     is >> inp_s;
0077     typename std::basic_string<charT>::iterator b = inp_s.begin();
0078     // need to use both iterators because there is no requirement
0079     // for the data held by a std::basic_string<> be terminated with
0080     // any marker (such as '\0').
0081     typename std::basic_string<charT>::iterator e = inp_s.end();
0082     while(b != e){
0083       out_ss << is.narrow(*b, 0);
0084       ++b;
0085     }
0086 
0087     td = date_time::parse_delimited_time_duration<time_duration>(out_ss.str());
0088     return is;
0089   }
0090 
0091   template<class charT>
0092   inline
0093   std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, ptime& pt)
0094   {
0095     gregorian::date d(not_a_date_time);
0096     time_duration td(0,0,0);
0097     is >> d >> td;
0098     pt = ptime(d, td);
0099 
0100     return is;
0101   }
0102 
0103   /** operator>> for time_period. time_period must be in 
0104    * "[date time_duration/date time_duration]" format. */
0105   template<class charT>
0106   inline
0107   std::basic_istream<charT>& operator>>(std::basic_istream<charT>& is, time_period& tp)
0108   {
0109     gregorian::date d(not_a_date_time);
0110     time_duration td(0,0,0);
0111     ptime beg(d, td);
0112     ptime end(beg);
0113     std::basic_string<charT> s;
0114     // get first date string and remove leading '['
0115     is >> s;
0116     {
0117       std::basic_stringstream<charT> ss;
0118       ss << s.substr(s.find('[')+1);
0119       ss >> d;
0120     }
0121     // get first time_duration & second date string, remove the '/'
0122     // and split into 2 strings
0123     is >> s; 
0124     {
0125       std::basic_stringstream<charT> ss;
0126       ss << s.substr(0, s.find('/'));
0127       ss >> td;
0128     }
0129     beg = ptime(d, td);
0130     {
0131       std::basic_stringstream<charT> ss;
0132       ss << s.substr(s.find('/')+1);
0133       ss >> d;
0134     }
0135     // get last time_duration and remove the trailing ']'
0136     is >> s;
0137     {
0138       std::basic_stringstream<charT> ss;
0139       ss << s.substr(0, s.find(']'));
0140       ss >> td;
0141     }
0142     end = ptime(d, td);
0143 
0144     tp = time_period(beg,end);
0145     return is;
0146   }
0147 
0148 
0149 #endif //BOOST_DATE_TIME_NO_LOCALE
0150 
0151 } } // namespaces
0152 
0153 #endif // POSIX_TIME_PRE133_OPERATORS_HPP___