1 /* Time class declaration.
2    Copyright (C) 2001-2010 Roberto Bagnara <bagnara@cs.unipr.it>
3    Copyright (C) 2010-2016 BUGSENG srl (http://bugseng.com)
4 
5 This file is part of the Parma Polyhedra Library (PPL).
6 
7 The PPL is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 The PPL is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307, USA.
20 
21 For the most up-to-date information see the Parma Polyhedra Library
22 site: http://bugseng.com/products/ppl/ . */
23 
24 #ifndef PPL_Time_defs_hh
25 #define PPL_Time_defs_hh 1
26 
27 #include "Time_types.hh"
28 
29 namespace Parma_Polyhedra_Library {
30 
31 namespace Implementation {
32 
33 namespace Watchdog {
34 
35 //! Returns <CODE>true</CODE> if and only if \p x and \p y are equal.
36 bool operator==(const Time& x, const Time& y);
37 
38 //! Returns <CODE>true</CODE> if and only if \p x and \p y are different.
39 bool operator!=(const Time& x, const Time& y);
40 
41 //! Returns <CODE>true</CODE> if and only if \p x is shorter than \p y.
42 bool operator<(const Time& x, const Time& y);
43 
44 /*! \brief
45   Returns <CODE>true</CODE> if and only if \p x is shorter than
46   or equal to \p y.
47 */
48 bool operator<=(const Time& x, const Time& y);
49 
50 //! Returns <CODE>true</CODE> if and only if \p x is longer than \p y.
51 bool operator>(const Time& x, const Time& y);
52 
53 /*! \brief
54   Returns <CODE>true</CODE> if and only if \p x is longer than
55   or equal to \p y.
56 */
57 bool operator>=(const Time& x, const Time& y);
58 
59 //! Returns the sum of \p x and \p y.
60 Time operator+(const Time& x, const Time& y);
61 
62 /*! \brief
63   Returns the difference of \p x and \p y or the null interval,
64   if \p x is shorter than \p y.
65 */
66 Time operator-(const Time& x, const Time& y);
67 
68 } // namespace Watchdog
69 
70 } // namespace Implementation
71 
72 } // namespace Parma_Polyhedra_Library
73 
74 //! A class for representing and manipulating positive time intervals.
75 class Parma_Polyhedra_Library::Implementation::Watchdog::Time {
76 public:
77   //! Zero seconds.
78   Time();
79 
80   //! Constructor taking a number of centiseconds.
81   explicit Time(long centisecs);
82 
83   //! Constructor with seconds and microseconds.
84   Time(long s, long m);
85 
86   /*! \brief
87     Returns the number of whole seconds contained in the represented
88     time interval.
89   */
90   long seconds() const;
91 
92   /*! \brief
93     Returns the number of microseconds that, when added to the number
94     of seconds returned by seconds(), give the represent time interval.
95   */
96   long microseconds() const;
97 
98   //! Adds \p y to \p *this.
99   Time& operator+=(const Time& y);
100 
101   /*! \brief
102     Subtracts \p y from \p *this; if \p *this is shorter than \p y,
103     \p *this is set to the null interval.
104   */
105   Time& operator-=(const Time& y);
106 
107   //! Checks if all the invariants are satisfied.
108   bool OK() const;
109 
110 private:
111   //! Number of microseconds in a second.
112   static const long USECS_PER_SEC = 1000000L;
113 
114   //! Number of centiseconds in a second.
115   static const long CSECS_PER_SEC = 100L;
116 
117   //! Number of seconds.
118   long secs;
119 
120   //! Number of microseconds.
121   long microsecs;
122 };
123 
124 #include "Time_inlines.hh"
125 
126 #endif // !defined(PPL_Time_defs_hh)
127