Loading [MathJax]/extensions/tex2jax.js
JSBSim Flight Dynamics Model 1.2.2 (22 Mar 2025)
An Open Source Flight Dynamics and Control Software Library in C++
All Classes Functions Variables Enumerations Enumerator Friends Pages
Timer Class Reference

Detailed Description

The Timer class measures the elapsed real time and can be paused and resumed.

It inherits from SGPropertyChangeListener to restart the timer whenever a property change is detected.

Definition at line 190 of file JSBSim.cpp.

+ Inheritance diagram for Timer:
+ Collaboration diagram for Timer:

Public Member Functions

double getElapsedTime (void)
 Get the elapsed real time in seconds since the timer was started.
 
void pause (bool paused)
 Pause the timer if the paused parameter is true and resume it if the paused parameter is false.
 
void start (void)
 
void valueChanged (SGPropertyNode *prop) override
 Restart the timer when the listened property is modified.
 

Constructor & Destructor Documentation

◆ Timer()

Timer ( )
inline

Definition at line 192 of file JSBSim.cpp.

192: SGPropertyChangeListener(), isPaused(false) { start(); }

Member Function Documentation

◆ getElapsedTime()

double getElapsedTime ( void  )
inline

Get the elapsed real time in seconds since the timer was started.

Definition at line 201 of file JSBSim.cpp.

201{ return getcurrentseconds() - initial_seconds; }

◆ pause()

void pause ( bool  paused)
inline

Pause the timer if the paused parameter is true and resume it if the paused parameter is false.

Definition at line 205 of file JSBSim.cpp.

205 {
206 if (paused) {
207 if (!isPaused) {
208 isPaused = true;
209 pause_start_seconds = getcurrentseconds();
210 }
211 } else {
212 if (isPaused) {
213 isPaused = false;
214 double pause_duration = getcurrentseconds() - pause_start_seconds;
215 initial_seconds += pause_duration; // Shift the initial time to account for the pause duration.
216 }
217 }
218 }

◆ start()

void start ( void  )
inline

Definition at line 193 of file JSBSim.cpp.

193{ initial_seconds = getcurrentseconds(); }

◆ valueChanged()

void valueChanged ( SGPropertyNode *  prop)
inlineoverride

Restart the timer when the listened property is modified.

Definition at line 196 of file JSBSim.cpp.

196 {
197 start();
198 if (isPaused) pause_start_seconds = initial_seconds;
199 }

The documentation for this class was generated from the following file: