1 /***************************************************************************
4 begin : Sat Sep 14 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
25 * @brief Encapsulates a time, which can be set in various forms and outputted in various forms.
32 /** @brief Creates a GenTime object, with a time of 0 seconds. */
35 /** @brief Creates a GenTime object, with time given in seconds. */
36 explicit GenTime(double seconds);
38 /** @brief Creates a GenTime object, by passing number of frames and how many frames per second. */
39 GenTime(int frames, double framesPerSecond);
41 /** @brief Gets the time, in seconds. */
42 double seconds() const;
44 /** @brief Gets the time, in milliseconds */
47 /** @brief Gets the time in frames.
48 * @param framesPerSecond Number of frames per second */
49 double frames(double framesPerSecond) const;
51 /** @brief Rounds the GenTime's value to the nearest frame.
52 * @param framesPerSecond Number of frames per second */
53 GenTime & roundNearestFrame(double framesPerSecond);
60 GenTime & operator+=(GenTime op) {
65 GenTime & operator-=(GenTime op) {
70 /** @brief Adds two GenTimes. */
71 GenTime operator+(GenTime op) const {
72 return GenTime(m_time + op.m_time);
75 /** @brief Subtracts one genTime from another. */
76 GenTime operator-(GenTime op) const {
77 return GenTime(m_time - op.m_time);
80 /** @brief Multiplies one GenTime by a double value, returning a GenTime. */
81 GenTime operator*(double op) const {
82 return GenTime(m_time * op);
85 /** @brief Divides one GenTime by a double value, returning a GenTime. */
86 GenTime operator/(double op) const {
87 return GenTime(m_time / op);
90 bool operator<(GenTime op) const {
91 return m_time + s_delta < op.m_time;
94 bool operator>(GenTime op) const {
95 return m_time > op.m_time + s_delta;
98 bool operator>=(GenTime op) const {
99 return m_time + s_delta >= op.m_time;
102 bool operator<=(GenTime op) const {
103 return m_time <= op.m_time + s_delta;
106 bool operator==(GenTime op) const {
107 return fabs(m_time - op.m_time) < s_delta;
110 bool operator!=(GenTime op) const {
111 return fabs(m_time - op.m_time) >= s_delta;
115 /** Holds the time for this object. */
118 /** A delta value that is used to get around floating point rounding issues. */
119 static double s_delta;