X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fgentime.h;h=8b735b44ed290b0a3ab842e2359f8a05afb1f961;hb=56aee6aedeeed3efd10ada8fe3c229eddc01ef05;hp=6a4354b411115e463f2655be0ac5edd437abcc29;hpb=c42a026234a44a2d766e57bc64a6ac7bbd094000;p=kdenlive diff --git a/src/gentime.h b/src/gentime.h index 6a4354b4..8b735b44 100644 --- a/src/gentime.h +++ b/src/gentime.h @@ -18,84 +18,111 @@ #ifndef GENTIME_H #define GENTIME_H +#include #include -/**Encapsulates a time, which can be set in various forms and outputted in various forms. - *@author Jason Wood - */ +/** + * @class GenTime + * @brief Encapsulates a time, which can be set in various forms and outputted in various forms. + * @author Jason Wood + */ class GenTime { public: - /** Creates a time object, with a time of 0 seconds. */ + /** @brief Creates a GenTime object, with a time of 0 seconds. */ GenTime(); - /** Creates a time object, with time given in seconds. */ + /** @brief Creates a GenTime object, with time given in seconds. */ explicit GenTime(double seconds); - /** Creates a time object, by passing number of frames and how many frames per second */ + /** @brief Creates a GenTime object, by passing number of frames and how many frames per second. */ GenTime(int frames, double framesPerSecond); - /** returns the time, in seconds */ - double seconds() const { - return m_time; - } - /** Returns the time, in milliseconds */ double ms() const; + /** @brief Gets the time, in seconds. */ + double seconds() const; + + /** @brief Gets the time, in milliseconds */ + double ms() const; - /** Returns the time in frames, after being given the number of frames per second */ + /** @brief Gets the time in frames. + * @param framesPerSecond Number of frames per second */ double frames(double framesPerSecond) const; + /** @brief Rounds the GenTime's value to the nearest frame. + * @param framesPerSecond Number of frames per second */ + GenTime & roundNearestFrame(double framesPerSecond); + + QString toString() const; + + + /* + * Operators. + */ + + /// Unary minus + GenTime operator -() { + return GenTime(-m_time); + } + + /// Addition GenTime & operator+=(GenTime op) { m_time += op.m_time; return *this; } - /** Adds two GenTimes */ GenTime operator+(GenTime op) const { + + /// Subtraction + GenTime & operator-=(GenTime op) { + m_time -= op.m_time; + return *this; + } + + /** @brief Adds two GenTimes. */ + GenTime operator+(GenTime op) const { return GenTime(m_time + op.m_time); } - /** Subtracts one genTime from another */ GenTime operator-(GenTime op) const { + + /** @brief Subtracts one genTime from another. */ + GenTime operator-(GenTime op) const { return GenTime(m_time - op.m_time); } - /** Multiplies one GenTime by a double value, returning a GenTime */ + + /** @brief Multiplies one GenTime by a double value, returning a GenTime. */ GenTime operator*(double op) const { return GenTime(m_time * op); } - /** Divides one GenTime by a double value, returning a GenTime */ + + /** @brief Divides one GenTime by a double value, returning a GenTime. */ GenTime operator/(double op) const { return GenTime(m_time / op); } - /* Implementation of < operator; Works identically as with basic types. */ + bool operator<(GenTime op) const { return m_time + s_delta < op.m_time; } - /* Implementation of > operator; Works identically as with basic types. */ + bool operator>(GenTime op) const { return m_time > op.m_time + s_delta; } - /* Implementation of >= operator; Works identically as with basic types. */ + bool operator>=(GenTime op) const { return m_time + s_delta >= op.m_time; } - /* Implementation of <= operator; Works identically as with basic types. */ + bool operator<=(GenTime op) const { return m_time <= op.m_time + s_delta; } - /* Implementation of == operator; Works identically as with basic types. */ + bool operator==(GenTime op) const { return fabs(m_time - op.m_time) < s_delta; } - /* Implementation of != operator; Works identically as with basic types. */ + bool operator!=(GenTime op) const { return fabs(m_time - op.m_time) >= s_delta; } - /* Rounds the GenTIme's value to the nearest frame */ - GenTime & roundNearestFrame(double framesPerSecond) { - m_time = floor((m_time * framesPerSecond) + 0.5) / framesPerSecond; - return *this; - } - ~GenTime(); -private: // Private attributes - /** Holds the time for this object. */ +private: + /** Holds the time in seconds for this object. */ double m_time; /** A delta value that is used to get around floating point rounding issues. */