AVPKit
TimeValue.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 /*
21  * TimeValue.h
22  *
23  * Created on: Sep 19, 2008
24  * Author: aclarke
25  */
26 
27 #ifndef TIMEVALUE_H_
28 #define TIMEVALUE_H_
29 
30 #include <climits>
31 #include <com/avpkit/core/ITimeValue.h>
32 
33 namespace com { namespace avpkit { namespace core {
34 
35 class TimeValue: public ITimeValue
36 {
37  VS_JNIUTILS_REFCOUNTED_OBJECT_PRIVATE_MAKE(TimeValue);
38 public:
39  virtual int64_t get(Unit unit);
40  virtual int32_t compareTo(ITimeValue* other);
41 
42  Unit getNativeUnit();
43 
44  static TimeValue* make(int64_t value, Unit unit);
45  static TimeValue* make(TimeValue *src);
46  static inline int32_t compare(int64_t thisValue, int64_t thatValue)
47  {
48  int64_t retval;
49  int64_t adjustment = 1;
50  const static int64_t sMaxDistance = LLONG_MAX/2;
51  if ((thisValue > sMaxDistance && thatValue <= -sMaxDistance) ||
52  (thatValue > sMaxDistance && thisValue <= -sMaxDistance))
53  // in these cases we assume the time value has looped over
54  // a int64_t value, and we really want to invert the diff.
55  adjustment = -1;
56 
57  if (thisValue < thatValue)
58  retval = -adjustment;
59  else if (thisValue > thatValue)
60  retval = adjustment;
61  else
62  retval = 0;
63  return retval;
64  }
65 
66 protected:
67  TimeValue();
68  virtual ~TimeValue();
69 private:
70  void set(int64_t value, Unit unit);
71  int64_t mValue;
72  Unit mUnit;
73 };
74 
75 }}}
76 
77 #endif /* TIMEVALUE_H_ */
Time (duration) values with units.
Definition: ITimeValue.h:43
virtual int32_t compareTo(ITimeValue *other)
Compare this timeValue to another.
Definition: TimeValue.cpp:106
virtual int64_t get(Unit unit)
Get the value of this ITimeValue, in the specified Unit.
Definition: TimeValue.cpp:84
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...