- Main Page
- Related Pages
- Namespaces
- Classes
- Files

# time.h

Go to the documentation of this file.

    00001 /* === S Y N F I G ========================================================= */
    00022 /* ========================================================================= */
    00023
    00024 /* === S T A R T =========================================================== */
    00025
    00026 #ifndef __SYNFIG_TIME_H
    00027 #define __SYNFIG_TIME_H
    00028
    00029 /* === H E A D E R S ======================================================= */
    00030
    00031 #include "string_decl.h"
    00032
    00033 /* === M A C R O S ========================================================= */
    00034
    00035 /* === T Y P E D E F S ===================================================== */
    00036
    00037 /* === C L A S S E S & S T R U C T S ======================================= */
    00038
    00039 namespace synfig {
    00040
    00045 class Time
    00046 {
    00047 public:
    00048     typedef double value_type;
    00049
    00053     enum Format
    00054     {
    00055         FORMAT_NORMAL=0,
    00056         FORMAT_NOSPACES=(1<<0),
    00057         FORMAT_FULL=(1<<1),
    00058         FORMAT_VIDEO=(1<<2),
    00059         FORMAT_FRAMES=(1<<3),
    00060
    00061         FORMAT_END=(1<<4)
    00062     }; // END of enum Format
    00063
    00064 private:
    00065     value_type value_;
    00066
    00067     static value_type epsilon_() { return static_cast<value_type>(0.0005); }
    00068
    00069 public:
    00070     Time() { }
    00071
    00072     Time(const value_type &x):value_(x) { }
    00073
    00074     Time(int x):value_(x) { }
    00075
    00076     Time(int hour, int minute, float second):value_(static_cast<value_type>(second+hour*3600+minute*60)) { }
    00077
    00079
    00085     Time(const String &string, float fps=0);
    00086
    00088     static const Time begin() { return static_cast<synfig::Time>(-32767.0f*512.0f); }
    00089
    00091     static const Time end() { return static_cast<synfig::Time>(32767.0f*512.0f); }
    00092
    00094     static const Time zero() { return static_cast<synfig::Time>(0); }
    00095
    00097     static const Time epsilon() { return static_cast<synfig::Time>(epsilon_()); }
    00098
    00100
    00101     String get_string(float fps=0, Time::Format format=FORMAT_NORMAL)const;
    00102
    00103 #ifdef _DEBUG
    00104     const char *c_str()const;
    00105 #endif
    00106
    00108     bool is_valid()const;
    00109
    00111     Time round(float fps)const;
    00112
    00113     bool is_equal(const Time& rhs)const { return (value_>rhs.value_)?value_-rhs.value_<=epsilon_():rhs.value_-value_<=epsilon_(); }
    00114     bool is_less_than(const Time& rhs)const { return rhs.value_-value_ > epsilon_(); }
    00115     bool is_more_than(const Time& rhs)const { return value_-rhs.value_ > epsilon_(); }
    00116
    00117     operator double()const { return value_; }
    00118
    00119     template<typename U> bool operator<(const U& rhs)const { return value_<rhs; }
    00120     template<typename U> bool operator>(const U& rhs)const { return value_>rhs; }
    00121     template<typename U> bool operator<=(const U& rhs)const { return value_<=rhs; }
    00122     template<typename U> bool operator>=(const U& rhs)const { return value_>=rhs; }
    00123     template<typename U> bool operator==(const U& rhs)const { return value_==rhs; }
    00124     template<typename U> bool operator!=(const U& rhs)const { return value_!=rhs; }
    00125
    00126 #if 0
    00127     bool operator<(const Time& rhs)const { return value_<rhs.value_; }
    00128     bool operator>(const Time& rhs)const { return value_>rhs.value_; }
    00129     bool operator<=(const Time& rhs)const { return value_<=rhs.value_; }
    00130     bool operator>=(const Time& rhs)const { return value_>=rhs.value_; }
    00131     bool operator==(const Time& rhs)const { return value_==rhs.value_; }
    00132     bool operator!=(const Time& rhs)const { return value_!=rhs.value_; }
    00133 #else
    00134     bool operator<(const Time& rhs)const { return is_less_than(rhs); }
    00135     bool operator>(const Time& rhs)const { return is_more_than(rhs); }
    00136     bool operator<=(const Time& rhs)const { return is_less_than(rhs)||is_equal(rhs); }
    00137     bool operator>=(const Time& rhs)const { return is_more_than(rhs)||is_equal(rhs); }
    00138     bool operator==(const Time& rhs)const { return is_equal(rhs); }
    00139     bool operator!=(const Time& rhs)const { return !is_equal(rhs); }
    00140 #endif
    00141
    00142     template<typename U> const Time& operator+=(const U &rhs) { value_+=static_cast<value_type>(rhs); return *this; }
    00143     template<typename U> const Time& operator-=(const U &rhs) { value_-=static_cast<value_type>(rhs); return *this; }
    00144     template<typename U> const Time& operator*=(const U &rhs) { value_*=static_cast<value_type>(rhs); return *this; }
    00145     template<typename U> const Time& operator/=(const U &rhs) { value_/=static_cast<value_type>(rhs); return *this; }
    00146
    00147     template<typename U> Time operator+(const U &rhs)const { return value_+static_cast<value_type>(rhs); }
    00148     template<typename U> Time operator-(const U &rhs)const { return value_-static_cast<value_type>(rhs); }
    00149     template<typename U> Time operator*(const U &rhs)const { return value_*static_cast<value_type>(rhs); }
    00150     template<typename U> Time operator/(const U &rhs)const { return value_/static_cast<value_type>(rhs); }
    00151
    00152     Time operator-()const { return -value_; }
    00153 }; // END of class Time
    00154
    00156
    00157 inline Time::Format operator|(Time::Format lhs, Time::Format rhs)
    00158 { return static_cast<Time::Format>((int)lhs|(int)rhs); }
    00159
    00161
    00164 inline bool operator<=(Time::Format lhs, Time::Format rhs)
    00165 { return (static_cast<int>(lhs) & static_cast<int>(rhs))==static_cast<int>(rhs); }
    00166
    00167 }; // END of namespace synfig
    00168
    00169 /* === E N D =============================================================== */
    00170
    00171 #endif