Visualization Library 2.0.0

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Time.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Time_INCLUDE_ONCE
33 #define Time_INCLUDE_ONCE
34 
35 #include <vlCore/Object.hpp>
36 
37 namespace vl
38 {
39  //-----------------------------------------------------------------------------
40  // Time
41  // Under Windows, due to BIOS or HAL bugs this function could return different
42  // results on different threads, which means that if more than one thread needs
43  // to sinchronize with the others using this function they should use the time
44  // returned in one of those threads as reference.
45  //-----------------------------------------------------------------------------
49  class VLCORE_EXPORT Time: public Object
50  {
52 
53  public:
54  Time();
55 
56  int year() const { return mYear; }
57 
58  int month() const { return mMonth; }
59 
60  int dayOfWeek() const { return mDayOfWeek; }
61 
62  int dayOfMonth() const { return mDayOfMonth; }
63 
64  int hour() const { return mHour; }
65 
66  int minute() const { return mMinute; }
67 
68  int second() const { return mSecond; }
69 
70  int microsecond() const { return mMicrosecond; }
71 
72  static real currentTime();
73 
74  static void sleep(unsigned int milliseconds);
75 
76  void start(int index=0) { mStart[index] = currentTime(); }
77 
78  void stop(int index=0) { mStart[index] = -1.0; }
79 
80  bool isStarted(int index=0) const { return mStart[index] != -1; }
81 
82  real elapsed(int index=0) const { return mStart[index] >= 0 ? currentTime() - mStart[index] : -1; }
83 
84  protected:
85  int mYear; // 1601 through 30827.
86  int mMonth; // 1..12
87  int mDayOfWeek; // 0 = Sunday, 6 = Saturday
88  int mDayOfMonth; // 1..31
89  int mHour; // 0..23
90  int mMinute; // 0..59
91  int mSecond; // 0..59
92  int mMicrosecond; // 0 ... 999999
93 
94  real mStart[VL_MAX_TIMERS];
95  };
96 }
97 
98 #endif
void start(int index=0)
Definition: Time.hpp:76
int mHour
Definition: Time.hpp:89
int mMicrosecond
Definition: Time.hpp:92
real elapsed(int index=0) const
Definition: Time.hpp:82
int second() const
Definition: Time.hpp:68
int microsecond() const
Definition: Time.hpp:70
int mSecond
Definition: Time.hpp:91
int year() const
Definition: Time.hpp:56
int mDayOfWeek
Definition: Time.hpp:87
int mYear
Definition: Time.hpp:85
int mMonth
Definition: Time.hpp:86
int dayOfMonth() const
Definition: Time.hpp:62
int mMinute
Definition: Time.hpp:90
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
Visualization Library main namespace.
int dayOfWeek() const
Definition: Time.hpp:60
Simple class to be used as a timer and to retrieve the current time and date.
Definition: Time.hpp:49
The base class for all the reference counted objects.
Definition: Object.hpp:158
void stop(int index=0)
Definition: Time.hpp:78
int month() const
Definition: Time.hpp:58
int hour() const
Definition: Time.hpp:64
int minute() const
Definition: Time.hpp:66
int mDayOfMonth
Definition: Time.hpp:88
bool isStarted(int index=0) const
Definition: Time.hpp:80