Coin Logo Coin3D is Free Software,
published under the BSD 3-clause license.
https://bitbucket.org/Coin3D/
http://www.kongsberg.com/kogt/
SbTime.h
1 #ifndef COIN_SBTIME_H
2 #define COIN_SBTIME_H
3 
4 /**************************************************************************\
5  * Copyright (c) Kongsberg Oil & Gas Technologies AS
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in the
17  * documentation and/or other materials provided with the distribution.
18  *
19  * Neither the name of the copyright holder nor the names of its
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
29  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 \**************************************************************************/
35 
36 #include <cstdio>
37 
38 #include <Inventor/system/inttypes.h>
39 #include <Inventor/SbBasic.h>
40 #include <Inventor/SbString.h>
41 
42 // Avoid problem with Microsoft Visual C++ Win32 API headers (they
43 // #define "max" (in 3 different header files, no less)).
44 #ifdef max
45 #define SBTIME_UNDEF_MAX
46 #undef max
47 #endif // max
48 
49 
50 class COIN_DLL_API SbTime {
51 public:
52  SbTime(void);
53  SbTime(const double sec);
54  SbTime(const int32_t sec, const long usec);
55  SbTime(const struct timeval * const tv);
56  static SbTime getTimeOfDay(void);
57  void setToTimeOfDay(void);
58  static SbTime zero(void);
59 
60  static SbTime max(void);
61  static SbTime maxTime(void);
62  static void sleep(int msec);
63  void setValue(const double sec);
64  void setValue(const int32_t sec, const long usec);
65  void setValue(const struct timeval * const tv);
66  void setMsecValue(const unsigned long msec);
67  double getValue(void) const;
68  void getValue(time_t & sec, long & usec) const;
69  void getValue(struct timeval * tv) const;
70  unsigned long getMsecValue(void) const;
71  SbString format(const char * const fmt = "%S.%i") const;
72  SbString formatDate(const char * const fmt = NULL) const;
73  SbBool parsedate(const char * const date);
74  friend COIN_DLL_API SbTime operator +(const SbTime & t0, const SbTime & t1);
75  friend COIN_DLL_API SbTime operator -(const SbTime & t0, const SbTime & t1);
76  SbTime & operator +=(const SbTime & tm);
77  SbTime & operator -=(const SbTime & tm);
78  SbTime operator-(void) const;
79  friend COIN_DLL_API SbTime operator *(const double s, const SbTime & tm);
80  friend COIN_DLL_API SbTime operator *(const SbTime & tm, const double s);
81  friend COIN_DLL_API SbTime operator /(const SbTime & tm, const double s);
82  SbTime & operator *=(const double s);
83  SbTime & operator /=(const double s);
84  double operator /(const SbTime & tm) const;
85  SbTime operator %(const SbTime & tm) const;
86  int operator ==(const SbTime & tm) const;
87  int operator !=(const SbTime & tm) const;
88  SbBool operator <(const SbTime & tm) const;
89  SbBool operator >(const SbTime & tm) const;
90  SbBool operator <=(const SbTime & tm) const;
91  SbBool operator >=(const SbTime & tm) const;
92 
93  void print(FILE * fp) const;
94 
95 private:
96  double dtime;
97  void addToString(SbString & str, const double val) const;
98 };
99 
100 COIN_DLL_API SbTime operator +(const SbTime & t0, const SbTime & t1);
101 COIN_DLL_API SbTime operator -(const SbTime & t0, const SbTime & t1);
102 COIN_DLL_API SbTime operator *(const double s, const SbTime & tm);
103 COIN_DLL_API SbTime operator *(const SbTime & tm, const double s);
104 COIN_DLL_API SbTime operator /(const SbTime & tm, const double s);
105 
106 // Avoid problem with Microsoft Win32 API headers (see above).
107 // Redefine macro max() back to a definition compatible with what it
108 // is in the MSVC header files.
109 #ifdef SBTIME_UNDEF_MAX
110 #define max(a,b) (((a) > (b)) ? (a) : (b))
111 #undef SBTIME_UNDEF_MAX
112 #endif // SBTIME_UNDEF_MAX
113 
114 #endif // !COIN_SBTIME_H
SbVec2s operator-(const SbVec2s &v1, const SbVec2s &v2)
The SbTime class instances represents time values.
Definition: SbTime.h:50
SbVec2s operator/(const SbVec2s &v, int d)
SbVec2s operator*(const SbVec2s &v, int d)
The SbString class is a string class with convenience functions for string operations.
Definition: SbString.h:52
SbVec2s operator+(const SbVec2s &v1, const SbVec2s &v2)