Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-21 09:18:20

0001 // Created on: 1993-01-04
0002 // Created by: J.P. BOUDIER - J.P. TIRAULT
0003 // Copyright (c) 1993-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _Quantity_Period_HeaderFile
0018 #define _Quantity_Period_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <Standard_Boolean.hxx>
0025 
0026 //! Manages date intervals. For example, a Period object
0027 //! gives the interval between two dates.
0028 //! A period is expressed in seconds and microseconds.
0029 class Quantity_Period
0030 {
0031 public:
0032   DEFINE_STANDARD_ALLOC
0033 
0034   //! Creates a Period
0035   //! With:
0036   //! 0 <= dd
0037   //! 0 <= hh
0038   //! 0 <= mn
0039   //! 0 <= ss
0040   //! 0 <= mis
0041   //! 0 <= mics
0042   Standard_EXPORT Quantity_Period(const int dd,
0043                                   const int hh,
0044                                   const int mn,
0045                                   const int ss,
0046                                   const int mis  = 0,
0047                                   const int mics = 0);
0048 
0049   //! Creates a Period with a number of seconds and microseconds.
0050   //! Exceptions
0051   //! Quantity_PeriodDefinitionError:
0052   //! -   if the number of seconds expressed either by:
0053   //! -   dd days, hh hours, mn minutes and ss seconds, or
0054   //! -   Ss
0055   //! is less than 0.
0056   //! -   if the number of microseconds expressed either by:
0057   //! -   mis milliseconds and mics microseconds, or
0058   //! -   Mics
0059   //! is less than 0.
0060   Standard_EXPORT Quantity_Period(const int ss, const int mics = 0);
0061 
0062   //! Decomposes this period into a number of days,hours,
0063   //! minutes,seconds,milliseconds and microseconds
0064   //! Example of return values:
0065   //! 2 days, 15 hours, 0 minute , 0 second
0066   //! 0 millisecond and 0 microsecond
0067   Standard_EXPORT void Values(int& dd, int& hh, int& mn, int& ss, int& mis, int& mics) const;
0068 
0069   //! Returns the number of seconds in Ss and the
0070   //! number of remainding microseconds in Mics of this period.
0071   //! Example of return values: 3600 seconds and 0 microseconds
0072   Standard_EXPORT void Values(int& ss, int& mics) const;
0073 
0074   //! Assigns to this period the time interval defined
0075   //! -   with dd days, hh hours, mn minutes, ss
0076   //! seconds, mis (defaulted to 0) milliseconds and
0077   //! mics (defaulted to 0) microseconds; or
0078   Standard_EXPORT void SetValues(const int dd,
0079                                  const int hh,
0080                                  const int mn,
0081                                  const int ss,
0082                                  const int mis  = 0,
0083                                  const int mics = 0);
0084 
0085   //! Assigns to this period the time interval defined
0086   //! -   with Ss seconds and Mics (defaulted to 0) microseconds.
0087   //! Exceptions
0088   //! Quantity_PeriodDefinitionError:
0089   //! -   if the number of seconds expressed either by:
0090   //! -   dd days, hh hours, mn minutes and ss seconds, or
0091   //! -   Ss
0092   //! is less than 0.
0093   //! -   if the number of microseconds expressed either by:
0094   //! -   mis milliseconds and mics microseconds, or
0095   //! -   Mics
0096   //! is less than 0.
0097   Standard_EXPORT void SetValues(const int ss, const int mics = 0);
0098 
0099   //! Subtracts one Period from another and returns the difference.
0100   Standard_EXPORT Quantity_Period Subtract(const Quantity_Period& anOther) const;
0101 
0102   Quantity_Period operator-(const Quantity_Period& anOther) const { return Subtract(anOther); }
0103 
0104   //! Adds one Period to another one.
0105   Standard_EXPORT Quantity_Period Add(const Quantity_Period& anOther) const;
0106 
0107   Quantity_Period operator+(const Quantity_Period& anOther) const { return Add(anOther); }
0108 
0109   //! Returns TRUE if both <me> and <other> are equal.
0110   constexpr bool IsEqual(const Quantity_Period& anOther) const noexcept
0111   {
0112     return (mySec == anOther.mySec && myUSec == anOther.myUSec);
0113   }
0114 
0115   constexpr bool operator==(const Quantity_Period& anOther) const noexcept
0116   {
0117     return IsEqual(anOther);
0118   }
0119 
0120   //! Returns TRUE if <me> is shorter than <other>.
0121   constexpr bool IsShorter(const Quantity_Period& anOther) const noexcept
0122   {
0123     return (mySec < anOther.mySec) || (mySec == anOther.mySec && myUSec < anOther.myUSec);
0124   }
0125 
0126   constexpr bool operator<(const Quantity_Period& anOther) const noexcept
0127   {
0128     return IsShorter(anOther);
0129   }
0130 
0131   //! Returns TRUE if <me> is longer then <other>.
0132   constexpr bool IsLonger(const Quantity_Period& anOther) const noexcept
0133   {
0134     return (mySec > anOther.mySec) || (mySec == anOther.mySec && myUSec > anOther.myUSec);
0135   }
0136 
0137   constexpr bool operator>(const Quantity_Period& anOther) const noexcept
0138   {
0139     return IsLonger(anOther);
0140   }
0141 
0142   //! Checks the validity of a Period in form (dd,hh,mn,ss,mil,mic)
0143   //! With:
0144   //! 0 <= dd
0145   //! 0 <= hh
0146   //! 0 <= mn
0147   //! 0 <= ss
0148   //! 0 <= mis
0149   //! 0 <= mics
0150   Standard_EXPORT static bool IsValid(const int dd,
0151                                       const int hh,
0152                                       const int mn,
0153                                       const int ss,
0154                                       const int mis  = 0,
0155                                       const int mics = 0);
0156 
0157   //! Checks the validity of a Period in form (ss,mic)
0158   //! With:
0159   //! 0 <= ss
0160   //! 0 <= mics
0161   Standard_EXPORT static bool IsValid(const int ss, const int mics = 0);
0162 
0163 private:
0164   int mySec;
0165   int myUSec;
0166 };
0167 
0168 #endif // _Quantity_Period_HeaderFile