AVPKit
com::avpkit::core::TimeValue Class Reference
Inheritance diagram for com::avpkit::core::TimeValue:
Collaboration diagram for com::avpkit::core::TimeValue:

Public Member Functions

virtual int64_t get (Unit unit)
 Get the value of this ITimeValue, in the specified Unit. More...
 
virtual int32_t compareTo (ITimeValue *other)
 Compare this timeValue to another. More...
 
Unit getNativeUnit ()
 
- Public Member Functions inherited from com::avpkit::ferry::RefCounted
virtual int32_t acquire ()
 Internal Only. More...
 
virtual int32_t release ()
 Internal Only. More...
 
virtual RefCountedcopyReference ()
 Create a new Java object that refers to the same native object. More...
 
virtual int32_t getCurrentRefCount ()
 Return the current reference count on this object. More...
 
void setJavaAllocator (void *allocator)
 This method is public but not part of the standard API. More...
 
void * getJavaAllocator ()
 This method is public but not part of the standard API. More...
 

Static Public Member Functions

static TimeValuemake (int64_t value, Unit unit)
 
static TimeValuemake (TimeValue *src)
 
static int32_t compare (int64_t thisValue, int64_t thatValue)
 
- Static Public Member Functions inherited from com::avpkit::core::ITimeValue
static ITimeValuemake (int64_t value, Unit unit)
 Make a new time value. More...
 
static ITimeValuemake (ITimeValue *src)
 Make a copy of a time value from another time value. More...
 
static int32_t compare (ITimeValue *a, ITimeValue *b)
 Convenience method that calls a.compareTo(b). More...
 
static int32_t compare (int64_t a, int64_t b)
 And another convenience method that deals with un-unitted long values. More...
 

Additional Inherited Members

- Public Types inherited from com::avpkit::core::ITimeValue
enum  Unit {
  DAYS , HOURS , MINUTES , SECONDS ,
  MILLISECONDS , MICROSECONDS , NANOSECONDS
}
 
- Protected Member Functions inherited from com::avpkit::ferry::RefCounted
virtual void destroy ()
 This method is called by RefCounted objects when their Ref Count reaches zero and they are about to be destroyed.
 
- Protected Attributes inherited from com::avpkit::ferry::RefCounted
AtomicIntegermRefCount
 This is the internal reference count, represented as an AtomicInteger to make sure it is thread safe.
 
void * mAllocator
 Not part of public API.
 

Detailed Description

Definition at line 35 of file TimeValue.h.

Member Function Documentation

◆ compareTo()

int32_t com::avpkit::core::TimeValue::compareTo ( ITimeValue other)
virtual

Compare this timeValue to another.

This compareTo will compare the values, but will assume that the values can never be more than half of int64_t's MAX_VALUE apart. If they are it will assume long wrapping has occurred. This is required especially if you're using TimeValue's as absolute time stamps, and want to know which is earlier.

Parameters
otherthe value to compare to
Returns
-1 if this < other; +1 if this > other; 0 otherwise

Implements com::avpkit::core::ITimeValue.

Definition at line 106 of file TimeValue.cpp.

107 {
108  int32_t retval = -1;
109  TimeValue* that = dynamic_cast<TimeValue*>(aThat);
110  if (that)
111  {
112  // convert both to NANOSECONDS
113  Unit thisUnit = this->getNativeUnit();
114  Unit thatUnit = that->getNativeUnit();
115 
116  // NOTE: Order of the entires in the Enum matters here.
117  Unit minUnit = thisUnit > thatUnit ? thisUnit : thatUnit;
118 
119  int64_t thisValue = this->get(minUnit);
120  int64_t thatValue = that->get(minUnit);
121  retval = TimeValue::compare(thisValue, thatValue);
122  }
123  return retval;
124 }
virtual int64_t get(Unit unit)
Get the value of this ITimeValue, in the specified Unit.
Definition: TimeValue.cpp:84

References get().

◆ get()

int64_t com::avpkit::core::TimeValue::get ( Unit  unit)
virtual

Get the value of this ITimeValue, in the specified Unit.

Parameters
unitThe unit you want to get a value as.
Returns
The value, converted into the appropriate Unit.

Implements com::avpkit::core::ITimeValue.

Definition at line 84 of file TimeValue.cpp.

85 {
86  if (mUnit == aUnit)
87  return mValue;
88 
89  int64_t retval = 0;
90  bool multiply = false;
91  int64_t factor = sConversionTable[aUnit][mUnit];
92  if (!factor)
93  {
94  factor = sConversionTable[mUnit][aUnit];
95  multiply = true;
96  }
97  if (multiply)
98  retval = mValue * factor;
99  else
100  retval = mValue / factor;
101 
102  return retval;
103 }

Referenced by compareTo().


The documentation for this class was generated from the following files: