CppEphem
CERunningDate.h
Go to the documentation of this file.
1 /***************************************************************************
2  * CERunningDate.h: CppEphem *
3  * ----------------------------------------------------------------------- *
4  * Copyright © 2017 JCardenzana *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 
22 #ifndef CERunningDate_h
23 #define CERunningDate_h
24 
25 #include <chrono>
26 
27 #include "CEDate.h"
28 
29 
30 class CERunningDate : public CEDate {
31 public:
32  CERunningDate() ;
33  CERunningDate(const CERunningDate& other);
34  virtual ~CERunningDate() ;
35 
36  CERunningDate& operator=(const CERunningDate& other);
37 
38  // Some overloaded methods to make sure that the current
39  // values are obtained first
40  virtual double JD() const;
41  virtual double MJD() const;
42  virtual double Gregorian() const;
43 
45  virtual double RunTime(void) const;
46  double ScaledRunTime(void) const;
47  void ResetTime(void);
48  virtual double GetTimerSpeed(void) const;
49  virtual void SetTimerSpeed(const double& scale=1.0);
50 
51 private:
52 
53  void copy_members(const CERunningDate& other);
54  void init_members(void);
55  void free_members(void);
56 
59  std::chrono::high_resolution_clock::time_point start_;
60 
62  double timer_speed_factor_;
63 };
64 
65 
66 /**********************************************************************/
71 inline
72 double CERunningDate::GetTimerSpeed(void) const
73 {
74  return timer_speed_factor_ ;
75 }
76 
77 
78 /**********************************************************************/
81 inline
82 void CERunningDate::ResetTime(void)
83 {
84  start_ = std::chrono::high_resolution_clock::now();
85 }
86 
87 /**********************************************************************/
92 inline
93 void CERunningDate::SetTimerSpeed(const double& scale)
94 {
95  timer_speed_factor_ = scale;
96 }
97 
98 /**********************************************************************/
103 inline
104 double CERunningDate::ScaledRunTime(void) const
105 {
106  return timer_speed_factor_ * RunTime();
107 }
108 
109 #endif /* CERunningDate_h */
CERunningDate
Definition: CERunningDate.h:29
CEDate
Definition: CEDate.h:43
CERunningDate::MJD
virtual double MJD() const
Get the current modified Julian date.
Definition: CERunningDate.cpp:107
CERunningDate::CERunningDate
CERunningDate()
Default constructor.
Definition: CERunningDate.cpp:46
CERunningDate::ResetTime
void ResetTime(void)
Method for resetting the 'start' variable.
Definition: CERunningDate.h:81
CEDate.h
CERunningDate::free_members
void free_members(void)
Deallocate data members.
Definition: CERunningDate.cpp:167
CERunningDate::Gregorian
virtual double Gregorian() const
Get the current Gregorian calendar date formatted as YYYYMMDD.D.
Definition: CERunningDate.cpp:117
CERunningDate::RunTime
virtual double RunTime(void) const
Method for getting the number of seconds since this object was created or reset.
Definition: CERunningDate.cpp:126
CERunningDate::init_members
void init_members(void)
Initialize data members.
Definition: CERunningDate.cpp:157
CERunningDate::~CERunningDate
virtual ~CERunningDate()
Destructor.
Definition: CERunningDate.cpp:69
CERunningDate::ScaledRunTime
double ScaledRunTime(void) const
Return the scaled ellapsed time since this object was created.
Definition: CERunningDate.h:103
CERunningDate::copy_members
void copy_members(const CERunningDate &other)
Copy data members from another object.
Definition: CERunningDate.cpp:147
CERunningDate::GetTimerSpeed
virtual double GetTimerSpeed(void) const
Get the rate at which the timer is progressing.
Definition: CERunningDate.h:71
CERunningDate::operator=
CERunningDate & operator=(const CERunningDate &other)
Copy assignment operator.
Definition: CERunningDate.cpp:80
CERunningDate::SetTimerSpeed
virtual void SetTimerSpeed(const double &scale=1.0)
Set the rate at which the timer progresses.
Definition: CERunningDate.h:92
CERunningDate::timer_speed_factor_
double timer_speed_factor_
Variable that can be used to speed up, slow down, or reverse the rate of time.
Definition: CERunningDate.h:79
CERunningDate::start_
std::chrono::high_resolution_clock::time_point start_
Variable to hold the starting time.
Definition: CERunningDate.h:76
CERunningDate::JD
virtual double JD() const
Get the current Julian date.
Definition: CERunningDate.cpp:96