Class duration

Synopsis

#include <include/EASTL/chrono.h>

template <class Rep, class Period>
class duration

Description

duration fwd_decl

duration

Methods

duration overloadconversion constructors
countreturns the count of ticks
max
min
operator%= overload
operator*=
operator+const arithmetic operations
operator++ overloadarithmetic operations
operator+=
operator-
operator-- overload
operator-=
operator/=
operator=
zerostatic accessors of special duration values

Source

Lines 214-291 in include/EASTL/chrono.h.

template <class Rep, class Period>
class duration
{
    Rep mRep;   
public:
    typedef Rep rep;
    typedef Period period;
    typedef duration<Rep, Period> this_type;
   #if defined(EA_COMPILER_NO_DEFAULTED_FUNCTIONS)
    EA_CONSTEXPR duration() 
        : mRep() {}
    duration(const duration& other)
        : mRep(Rep(other.mRep)) {}
    duration& operator=(const duration& other)
        { mRep = other.mRep; return *this; }
#else
    EA_CONSTEXPR duration() = default;
    duration(const duration&) = default;
    duration& operator=(const duration&) = default;
   #endif
    ///////////////////////////////////////////////////////////////////////////////
    // conversion constructors 
    ///////////////////////////////////////////////////////////////////////////////
    template <class Rep2>
    inline EA_CONSTEXPR explicit duration(
        const Rep2& rep2,
        typename eastl::enable_if<eastl::is_convertible<Rep2, Rep>::value &&
                                  (treat_as_floating_point<Rep>::value ||
                                   !treat_as_floating_point<Rep2>::value)>::type** = 0)
        : mRep(static_cast<Rep>(rep2)) {}
    template <class Rep2, class Period2>
    EA_CONSTEXPR duration(const duration<Rep2, Period2>& d2,
                          typename eastl::enable_if<treat_as_floating_point<Rep>::value ||
                                                        (eastl::ratio_divide<Period2, Period>::type::den == 1 &&
                                                         !treat_as_floating_point<Rep2>::value),
                                                    void>::type** = 0)
        : mRep(duration_cast<duration>(d2).count()) {}
    ///////////////////////////////////////////////////////////////////////////////
    // returns the count of ticks 
    ///////////////////////////////////////////////////////////////////////////////
    EA_CONSTEXPR Rep count() const { return mRep; }
    ///////////////////////////////////////////////////////////////////////////////
    // static accessors of special duration values 
    ///////////////////////////////////////////////////////////////////////////////
    EA_CONSTEXPR inline static duration zero() { return duration(duration_values<Rep>::zero()); }
    EA_CONSTEXPR inline static duration min()  { return duration(duration_values<Rep>::min()); }
    EA_CONSTEXPR inline static duration max()  { return duration(duration_values<Rep>::max()); }
    ///////////////////////////////////////////////////////////////////////////////
    // const arithmetic operations
    ///////////////////////////////////////////////////////////////////////////////
    EA_CONSTEXPR inline duration operator+() const { return *this; }
    EA_CONSTEXPR inline duration operator-() const { return duration(0-mRep); }
    ///////////////////////////////////////////////////////////////////////////////
    // arithmetic operations
    ///////////////////////////////////////////////////////////////////////////////
    inline duration operator++(int)                  { return duration(mRep++); }
    inline duration operator--(int)                  { return duration(mRep--); }
    inline duration& operator++()                    { ++mRep; return *this; }
    inline duration& operator--()                    { --mRep; return *this; }
    inline duration& operator+=(const duration& d)   { mRep += d.count(); return *this; }
    inline duration& operator-=(const duration& d)   { mRep -= d.count(); return *this; }
    inline duration& operator*=(const Rep& rhs)      { mRep *= rhs; return *this; }
    inline duration& operator/=(const Rep& rhs)      { mRep /= rhs; return *this; }
    inline duration& operator%=(const Rep& rhs)      { mRep %= rhs; return *this; }
    inline duration& operator%=(const duration& d)   { mRep %= d.count(); return *this; }
};





Add Discussion as Guest

Log in