X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fsub_time.h;h=93088cb2fbf596c7cb53be6e680fede074255f38;hb=73740022051f377e3965ac9f8494ae3fbc65da8b;hp=ee14745f61512f48fb2556c69a075b1cc42ff4de;hpb=7f20aa518356f188946eb508239caf7c113da819;p=libsub.git diff --git a/src/sub_time.h b/src/sub_time.h index ee14745..93088cb 100644 --- a/src/sub_time.h +++ b/src/sub_time.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2014 Carl Hetherington + Copyright (C) 2014-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,10 +17,11 @@ */ -#ifndef LIBSUB_TIME_H -#define LIBSUB_TIME_H +#ifndef LIBSUB_SUB_TIME_H +#define LIBSUB_SUB_TIME_H -#include +#include "rational.h" +#include namespace sub { @@ -28,32 +29,49 @@ class Time { public: Time () - : _hours (0) - , _minutes (0) - , _seconds (0) + : _seconds (0) , _frames (0) {} - - Time (int h, int m, int s, int f) - : _hours (h) - , _minutes (m) - , _seconds (s) - , _frames (f) - {} + + int hours () const; + int minutes () const; + int seconds () const; + + int frames_at (Rational rate) const; + int milliseconds () const; + + double all_as_seconds () const; + + void add (Time t); + void scale (float f); + + static Time from_hmsf (int h, int m, int s, int f, boost::optional rate = boost::optional ()); + static Time from_hms (int h, int m, int s, int ms); + static Time from_frames (int frames, Rational rate); private: + friend bool operator< (Time const & a, Time const & b); + friend bool operator> (Time const & a, Time const & b); friend bool operator== (Time const & a, Time const & b); friend std::ostream& operator<< (std::ostream& s, Time const & t); - - int _hours; - int _minutes; + + Time (int seconds, int frames, boost::optional rate) + : _seconds (seconds) + , _frames (frames) + , _rate (rate) + {} + int _seconds; int _frames; + boost::optional _rate; }; +bool operator< (Time const & a, Time const & b); +bool operator> (Time const & a, Time const & b); bool operator== (Time const & a, Time const & b); -std::ostream& operator<< (std::ostream&, Time const & t); - +bool operator!= (Time const & a, Time const & b); +std::ostream& operator<< (std::ostream& s, Time const & t); + } #endif