BVB Source Codes

mars Show time.hpp Source code

Return Download mars: download time.hpp Source code - Download mars Source code - Type:.hpp
  1. #ifndef DATE_TIME_TIME_HPP___
  2. #define DATE_TIME_TIME_HPP___
  3.  
  4. /* Copyright (c) 2002,2003,2005 CrystalClear Software, Inc.
  5.  * Use, modification and distribution is subject to the
  6.  * Boost Software License, Version 1.0. (See accompanying
  7.  * file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
  8.  * Author: Jeff Garland, Bart Garst
  9.  * $Date$
  10.  */
  11.  
  12.  
  13. /*! @file time.hpp
  14.   This file contains the interface for the time associated classes.
  15. */
  16. #include <string>
  17. #include <boost/operators.hpp>
  18. #include <boost/date_time/time_defs.hpp>
  19. #include <boost/date_time/special_defs.hpp>
  20.  
  21. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost {
  22. namespace date_time {
  23.  
  24.   //! Representation of a precise moment in time, including the date.
  25.   /*!
  26.     This class is a skeleton for the interface of a temporal type
  27.     with a resolution that is higher than a day.  It is intended that
  28.     this class be the base class and that the actual time
  29.     class be derived using the BN pattern.  In this way, the derived
  30.     class can make decisions such as 'should there be a default constructor'
  31.     and what should it set its value to, should there be optional constructors
  32.     say allowing only an time_durations that generate a time from a clock,etc.
  33.     So, in fact multiple time types can be created for a time_system with
  34.     different construction policies, and all of them can perform basic
  35.     operations by only writing a copy constructor.  Finally, compiler
  36.     errors are also shorter.
  37.    
  38.     The real behavior of the time class is provided by the time_system
  39.     template parameter.  This class must provide all the logic
  40.     for addition, subtraction, as well as define all the interface
  41.     types.
  42.    
  43.   */
  44.  
  45.   template <class T, class time_system>
  46.   class base_time : private
  47.       mars_boost::less_than_comparable<T
  48.     , mars_boost::equality_comparable<T
  49.       > >
  50.   {
  51.   public:
  52.     // A tag for type categorization. Can be used to detect Boost.DateTime time points in generic code.
  53.     typedef void _is_boost_date_time_time_point;
  54.     typedef T time_type;
  55.     typedef typename time_system::time_rep_type time_rep_type;
  56.     typedef typename time_system::date_type date_type;
  57.     typedef typename time_system::date_duration_type date_duration_type;
  58.     typedef typename time_system::time_duration_type time_duration_type;
  59.     //typedef typename time_system::hms_type hms_type;
  60.    
  61.     base_time(const date_type& day,
  62.               const time_duration_type& td,
  63.               dst_flags dst=not_dst) :
  64.       time_(time_system::get_time_rep(day, td, dst))
  65.     {}
  66.     base_time(special_values sv) :
  67.       time_(time_system::get_time_rep(sv))
  68.     {}
  69.     base_time(const time_rep_type& rhs) :
  70.       time_(rhs)
  71.     {}
  72.     date_type date() const
  73.     {
  74.       return time_system::get_date(time_);
  75.     }
  76.     time_duration_type time_of_day() const
  77.     {
  78.       return time_system::get_time_of_day(time_);
  79.     }
  80.     /*! Optional bool parameter will return time zone as an offset
  81.      * (ie "+07:00"). Empty string is returned for classes that do
  82.      * not use a time_zone */
  83.     std::string zone_name(bool /*as_offset*/=false) const
  84.     {
  85.       return time_system::zone_name(time_);
  86.     }
  87.     /*! Optional bool parameter will return time zone as an offset
  88.      * (ie "+07:00"). Empty string is returned for classes that do
  89.      * not use a time_zone */
  90.     std::string zone_abbrev(bool /*as_offset*/=false) const
  91.     {
  92.       return time_system::zone_name(time_);
  93.     }
  94.     //! An empty string is returned for classes that do not use a time_zone
  95.     std::string zone_as_posix_string() const
  96.     {
  97.       return std::string();
  98.     }
  99.  
  100.     //! check to see if date is not a value
  101.     bool is_not_a_date_time()  const
  102.     {
  103.       return time_.is_not_a_date_time();
  104.     }
  105.     //! check to see if date is one of the infinity values
  106.     bool is_infinity()  const
  107.     {
  108.       return (is_pos_infinity() || is_neg_infinity());
  109.     }
  110.     //! check to see if date is greater than all possible dates
  111.     bool is_pos_infinity()  const
  112.     {
  113.       return time_.is_pos_infinity();
  114.     }
  115.     //! check to see if date is greater than all possible dates
  116.     bool is_neg_infinity()  const
  117.     {
  118.       return time_.is_neg_infinity();
  119.     }
  120.     //! check to see if time is a special value
  121.     bool is_special() const
  122.     {
  123.       return(is_not_a_date_time() || is_infinity());
  124.     }
  125.     //!Equality operator -- others generated by mars_boost::equality_comparable
  126.     bool operator==(const time_type& rhs) const
  127.     {
  128.       return time_system::is_equal(time_,rhs.time_);
  129.     }
  130.     //!Equality operator -- others generated by mars_boost::less_than_comparable
  131.     bool operator<(const time_type& rhs) const
  132.     {
  133.       return time_system::is_less(time_,rhs.time_);
  134.     }
  135.     //! difference between two times
  136.     time_duration_type operator-(const time_type& rhs) const
  137.     {
  138.       return time_system::subtract_times(time_, rhs.time_);
  139.     }
  140.     //! add date durations
  141.     time_type operator+(const date_duration_type& dd) const
  142.     {
  143.       return time_system::add_days(time_, dd);
  144.     }
  145.     time_type operator+=(const date_duration_type& dd)
  146.     {
  147.       time_ = (time_system::get_time_rep(date() + dd, time_of_day()));
  148.       return time_type(time_);
  149.     }
  150.     //! subtract date durations
  151.     time_type operator-(const date_duration_type& dd) const
  152.     {
  153.       return time_system::subtract_days(time_, dd);
  154.     }
  155.     time_type operator-=(const date_duration_type& dd)
  156.     {
  157.       time_ = (time_system::get_time_rep(date() - dd, time_of_day()));
  158.       return time_type(time_);
  159.     }
  160.     //! add time durations
  161.     time_type operator+(const time_duration_type& td) const
  162.     {
  163.       return time_type(time_system::add_time_duration(time_, td));
  164.     }
  165.     time_type operator+=(const time_duration_type& td)
  166.     {
  167.       time_ = (time_system::get_time_rep(date(), time_of_day() + td));
  168.       return time_type(time_);
  169.     }
  170.     //! subtract time durations
  171.     time_type operator-(const time_duration_type& rhs) const
  172.     {
  173.       return time_system::subtract_time_duration(time_, rhs);
  174.     }
  175.     time_type operator-=(const time_duration_type& td)
  176.     {
  177.       time_ = (time_system::get_time_rep(date(), time_of_day() - td));
  178.       return time_type(time_);
  179.     }
  180.    
  181.   protected:
  182.     time_rep_type time_;
  183.   };
  184.  
  185.  
  186.  
  187.  
  188.  
  189. } } //namespace date_time::boost
  190.  
  191.  
  192. #endif
  193.  
  194.  
downloadtime.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top