42cf5bc1 |
1 | // Created on: 1993-01-04 |
2 | // Created by: J.P. BOUDIER - J.P. TIRAULT |
3 | // Copyright (c) 1993-1999 Matra Datavision |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
5 | // |
6 | // This file is part of Open CASCADE Technology software library. |
7 | // |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
13 | // |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
16 | |
17 | #ifndef _Quantity_Period_HeaderFile |
18 | #define _Quantity_Period_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <Standard_Integer.hxx> |
25 | #include <Standard_Boolean.hxx> |
26 | class Quantity_PeriodDefinitionError; |
27 | |
42cf5bc1 |
28 | //! Manages date intervals. For example, a Period object |
29 | //! gives the interval between two dates. |
30 | //! A period is expressed in seconds and microseconds. |
31 | class Quantity_Period |
32 | { |
33 | public: |
34 | |
35 | DEFINE_STANDARD_ALLOC |
36 | |
42cf5bc1 |
37 | //! Creates a Period |
38 | //! With: 0 <= dd |
39 | //! 0 <= hh |
40 | //! 0 <= mn |
41 | //! 0 <= ss |
42 | //! 0 <= mis |
43 | //! 0 <= mics |
44 | Standard_EXPORT Quantity_Period(const Standard_Integer dd, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0); |
45 | |
46 | //! Creates a Period with a number of seconds and microseconds. |
47 | //! Exceptions |
48 | //! Quantity_PeriodDefinitionError: |
49 | //! - if the number of seconds expressed either by: |
50 | //! - dd days, hh hours, mn minutes and ss seconds, or |
51 | //! - Ss |
52 | //! is less than 0. |
53 | //! - if the number of microseconds expressed either by: |
54 | //! - mis milliseconds and mics microseconds, or |
55 | //! - Mics |
56 | //! is less than 0. |
57 | Standard_EXPORT Quantity_Period(const Standard_Integer ss, const Standard_Integer mics = 0); |
58 | |
59 | //! Decomposes this period into a number of days,hours, |
60 | //! minutes,seconds,milliseconds and microseconds |
61 | //! Example of return values: |
62 | //! 2 days, 15 hours, 0 minute , 0 second |
63 | //! 0 millisecond and 0 microsecond |
64 | Standard_EXPORT void Values (Standard_Integer& dd, Standard_Integer& hh, Standard_Integer& mn, Standard_Integer& ss, Standard_Integer& mis, Standard_Integer& mics) const; |
65 | |
66 | //! Returns the number of seconds in Ss and the |
67 | //! number of remainding microseconds in Mics of this period. |
68 | //! Example of return values: 3600 seconds and 0 microseconds |
69 | Standard_EXPORT void Values (Standard_Integer& ss, Standard_Integer& mics) const; |
70 | |
71 | //! Assigns to this period the time interval defined |
72 | //! - with dd days, hh hours, mn minutes, ss |
73 | //! seconds, mis (defaulted to 0) milliseconds and |
74 | //! mics (defaulted to 0) microseconds; or |
75 | Standard_EXPORT void SetValues (const Standard_Integer dd, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0); |
76 | |
77 | //! Assigns to this period the time interval defined |
78 | //! - with Ss seconds and Mics (defaulted to 0) microseconds. |
79 | //! Exceptions |
80 | //! Quantity_PeriodDefinitionError: |
81 | //! - if the number of seconds expressed either by: |
82 | //! - dd days, hh hours, mn minutes and ss seconds, or |
83 | //! - Ss |
84 | //! is less than 0. |
85 | //! - if the number of microseconds expressed either by: |
86 | //! - mis milliseconds and mics microseconds, or |
87 | //! - Mics |
88 | //! is less than 0. |
89 | Standard_EXPORT void SetValues (const Standard_Integer ss, const Standard_Integer mics = 0); |
90 | |
91 | //! Subtracts one Period from another and returns the difference. |
92 | Standard_EXPORT Quantity_Period Subtract (const Quantity_Period& anOther) const; |
93 | Quantity_Period operator - (const Quantity_Period& anOther) const |
94 | { |
95 | return Subtract(anOther); |
96 | } |
97 | |
98 | //! Adds one Period to another one. |
99 | Standard_EXPORT Quantity_Period Add (const Quantity_Period& anOther) const; |
100 | Quantity_Period operator + (const Quantity_Period& anOther) const |
101 | { |
102 | return Add(anOther); |
103 | } |
104 | |
105 | //! Returns TRUE if both <me> and <other> are equal. |
106 | Standard_EXPORT Standard_Boolean IsEqual (const Quantity_Period& anOther) const; |
107 | Standard_Boolean operator == (const Quantity_Period& anOther) const |
108 | { |
109 | return IsEqual(anOther); |
110 | } |
111 | |
112 | //! Returns TRUE if <me> is shorter than <other>. |
113 | Standard_EXPORT Standard_Boolean IsShorter (const Quantity_Period& anOther) const; |
114 | Standard_Boolean operator < (const Quantity_Period& anOther) const |
115 | { |
116 | return IsShorter(anOther); |
117 | } |
118 | |
119 | //! Returns TRUE if <me> is longer then <other>. |
120 | Standard_EXPORT Standard_Boolean IsLonger (const Quantity_Period& anOther) const; |
121 | Standard_Boolean operator > (const Quantity_Period& anOther) const |
122 | { |
123 | return IsLonger(anOther); |
124 | } |
125 | |
126 | //! Checks the validity of a Period in form (dd,hh,mn,ss,mil,mic) |
127 | //! With: 0 <= dd |
128 | //! 0 <= hh |
129 | //! 0 <= mn |
130 | //! 0 <= ss |
131 | //! 0 <= mis |
132 | //! 0 <= mics |
133 | Standard_EXPORT static Standard_Boolean IsValid (const Standard_Integer dd, const Standard_Integer hh, const Standard_Integer mn, const Standard_Integer ss, const Standard_Integer mis = 0, const Standard_Integer mics = 0); |
134 | |
135 | //! Checks the validity of a Period in form (ss,mic) |
136 | //! With: 0 <= ss |
137 | //! 0 <= mics |
138 | Standard_EXPORT static Standard_Boolean IsValid (const Standard_Integer ss, const Standard_Integer mics = 0); |
139 | |
42cf5bc1 |
140 | private: |
141 | |
42cf5bc1 |
142 | Standard_Integer mySec; |
143 | Standard_Integer myUSec; |
144 | |
42cf5bc1 |
145 | }; |
146 | |
42cf5bc1 |
147 | #endif // _Quantity_Period_HeaderFile |