os/ossrv/ossrv_pub/boost_apis/boost/date_time/time.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/date_time/time.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,190 @@
     1.4 +#ifndef DATE_TIME_TIME_HPP___
     1.5 +#define DATE_TIME_TIME_HPP___
     1.6 +
     1.7 +/* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
     1.8 + * Use, modification and distribution is subject to the 
     1.9 + * Boost Software License, Version 1.0. (See accompanying
    1.10 + * file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0)
    1.11 + * Author: Jeff Garland, Bart Garst
    1.12 + * $Date: 2005/04/23 05:39:52 $
    1.13 + */
    1.14 +
    1.15 +
    1.16 +/*! @file time.hpp
    1.17 +  This file contains the interface for the time associated classes.
    1.18 +*/
    1.19 +#include "boost/date_time/time_defs.hpp"
    1.20 +#include "boost/operators.hpp"
    1.21 +#include <string>
    1.22 +
    1.23 +namespace boost {
    1.24 +namespace date_time {
    1.25 +
    1.26 +  //! Representation of a precise moment in time, including the date.
    1.27 +  /*! 
    1.28 +    This class is a skeleton for the interface of a temporal type
    1.29 +    with a resolution that is higher than a day.  It is intended that 
    1.30 +    this class be the base class and that the actual time 
    1.31 +    class be derived using the BN pattern.  In this way, the derived 
    1.32 +    class can make decisions such as 'should there be a default constructor' 
    1.33 +    and what should it set its value to, should there be optional constructors
    1.34 +    say allowing only an time_durations that generate a time from a clock,etc.
    1.35 +    So, in fact multiple time types can be created for a time_system with
    1.36 +    different construction policies, and all of them can perform basic
    1.37 +    operations by only writing a copy constructor.  Finally, compiler 
    1.38 +    errors are also shorter. 
    1.39 +    
    1.40 +    The real behavior of the time class is provided by the time_system
    1.41 +    template parameter.  This class must provide all the logic
    1.42 +    for addition, subtraction, as well as define all the interface
    1.43 +    types.
    1.44 +    
    1.45 +  */
    1.46 +
    1.47 +  template <class T, class time_system>
    1.48 +  class base_time : private
    1.49 +      boost::less_than_comparable<T
    1.50 +    , boost::equality_comparable<T
    1.51 +      > >
    1.52 +  {
    1.53 +  public:
    1.54 +    typedef T time_type;
    1.55 +    typedef typename time_system::time_rep_type time_rep_type;
    1.56 +    typedef typename time_system::date_type date_type;
    1.57 +    typedef typename time_system::date_duration_type date_duration_type;
    1.58 +    typedef typename time_system::time_duration_type time_duration_type;
    1.59 +    //typedef typename time_system::hms_type hms_type;
    1.60 +    
    1.61 +    base_time(const date_type& day, 
    1.62 +              const time_duration_type& td, 
    1.63 +              dst_flags dst=not_dst) :
    1.64 +      time_(time_system::get_time_rep(day, td, dst))
    1.65 +    {}
    1.66 +    base_time(special_values sv) :
    1.67 +      time_(time_system::get_time_rep(sv))
    1.68 +    {}
    1.69 +    base_time(const time_rep_type& rhs) :
    1.70 +      time_(rhs)
    1.71 +    {}
    1.72 +    date_type date() const
    1.73 +    {
    1.74 +      return time_system::get_date(time_);
    1.75 +    }
    1.76 +    time_duration_type time_of_day() const
    1.77 +    {
    1.78 +      return time_system::get_time_of_day(time_);
    1.79 +    }
    1.80 +    /*! Optional bool parameter will return time zone as an offset 
    1.81 +     * (ie "+07:00"). Empty string is returned for classes that do 
    1.82 +     * not use a time_zone */
    1.83 +    std::string zone_name(bool as_offset=false) const
    1.84 +    {
    1.85 +      return time_system::zone_name(time_);
    1.86 +    }
    1.87 +    /*! Optional bool parameter will return time zone as an offset 
    1.88 +     * (ie "+07:00"). Empty string is returned for classes that do 
    1.89 +     * not use a time_zone */
    1.90 +    std::string zone_abbrev(bool as_offset=false) const
    1.91 +    {
    1.92 +      return time_system::zone_name(time_);
    1.93 +    }
    1.94 +    //! An empty string is returned for classes that do not use a time_zone
    1.95 +    std::string zone_as_posix_string() const
    1.96 +    {
    1.97 +      return std::string("");
    1.98 +    }
    1.99 +
   1.100 +    //! check to see if date is not a value
   1.101 +    bool is_not_a_date_time()  const
   1.102 +    {
   1.103 +      return time_.is_not_a_date_time();
   1.104 +    }
   1.105 +    //! check to see if date is one of the infinity values
   1.106 +    bool is_infinity()  const
   1.107 +    {
   1.108 +      return (is_pos_infinity() || is_neg_infinity()); 
   1.109 +    }
   1.110 +    //! check to see if date is greater than all possible dates
   1.111 +    bool is_pos_infinity()  const
   1.112 +    {
   1.113 +      return time_.is_pos_infinity();
   1.114 +    }
   1.115 +    //! check to see if date is greater than all possible dates
   1.116 +    bool is_neg_infinity()  const
   1.117 +    {
   1.118 +      return time_.is_neg_infinity();
   1.119 +    }
   1.120 +    //! check to see if time is a special value
   1.121 +    bool is_special() const
   1.122 +    {
   1.123 +      return(is_not_a_date_time() || is_infinity());
   1.124 +    }
   1.125 +    //!Equality operator -- others generated by boost::equality_comparable
   1.126 +    bool operator==(const time_type& rhs) const
   1.127 +    {
   1.128 +      return time_system::is_equal(time_,rhs.time_);
   1.129 +    }
   1.130 +    //!Equality operator -- others generated by boost::less_than_comparable
   1.131 +    bool operator<(const time_type& rhs) const
   1.132 +    {
   1.133 +      return time_system::is_less(time_,rhs.time_);
   1.134 +    }
   1.135 +    //! difference between two times
   1.136 +    time_duration_type operator-(const time_type& rhs) const
   1.137 +    {
   1.138 +      return time_system::subtract_times(time_, rhs.time_);
   1.139 +    }
   1.140 +    //! add date durations
   1.141 +    time_type operator+(const date_duration_type& dd) const
   1.142 +    {
   1.143 +      return time_system::add_days(time_, dd);
   1.144 +    }
   1.145 +    time_type operator+=(const date_duration_type& dd)
   1.146 +    {
   1.147 +      time_ = (time_system::get_time_rep(date() + dd, time_of_day()));
   1.148 +      return time_type(time_);
   1.149 +    }
   1.150 +    //! subtract date durations
   1.151 +    time_type operator-(const date_duration_type& dd) const
   1.152 +    {
   1.153 +      return time_system::subtract_days(time_, dd);
   1.154 +    }
   1.155 +    time_type operator-=(const date_duration_type& dd)
   1.156 +    {
   1.157 +      time_ = (time_system::get_time_rep(date() - dd, time_of_day()));
   1.158 +      return time_type(time_);
   1.159 +    }
   1.160 +    //! add time durations
   1.161 +    time_type operator+(const time_duration_type& td) const
   1.162 +    {
   1.163 +      return time_type(time_system::add_time_duration(time_, td));
   1.164 +    }
   1.165 +    time_type operator+=(const time_duration_type& td)
   1.166 +    {
   1.167 +      time_ = (time_system::get_time_rep(date(), time_of_day() + td));
   1.168 +      return time_type(time_);
   1.169 +    }
   1.170 +    //! subtract time durations
   1.171 +    time_type operator-(const time_duration_type& rhs) const
   1.172 +    {
   1.173 +      return time_system::subtract_time_duration(time_, rhs);
   1.174 +    }
   1.175 +    time_type operator-=(const time_duration_type& td) 
   1.176 +    {
   1.177 +      time_ = (time_system::get_time_rep(date(), time_of_day() - td));
   1.178 +      return time_type(time_);
   1.179 +    }
   1.180 +    
   1.181 +  protected:
   1.182 +    time_rep_type time_;
   1.183 +  };
   1.184 +
   1.185 +
   1.186 +
   1.187 +
   1.188 +
   1.189 +} } //namespace date_time::boost
   1.190 +
   1.191 +
   1.192 +#endif
   1.193 +