HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
timeCode.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_USD_SDF_TIME_CODE_H
8 #define PXR_USD_SDF_TIME_CODE_H
9 
10 /// \file sdf/timeCode.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/sdf/api.h"
14 #include "pxr/base/vt/traits.h"
15 
16 #include <algorithm>
17 #include <functional>
18 #include <iosfwd>
19 
21 
22 /// \class SdfTimeCode
23 ///
24 /// Value type that represents a time code. It's equivalent to a double type
25 /// value but is used to indicate that this value should be resolved by any
26 /// time based value resolution.
27 ///
29 {
30 public:
31  /// \name Constructors
32  /// @{
33  ///
34 
35  /// Construct a time code with the given time.
36  /// A default constructed SdfTimeCode has a time of 0.0.
37  /// A double value can implicitly cast to SdfTimeCode.
38  constexpr SdfTimeCode(double time = 0.0) noexcept : _time(time) {};
39 
40  /// @}
41 
42  ///\name Operators
43  /// @{
44 
45  constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
46  { return _time == rhs._time; }
47  constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
48  { return _time != rhs._time; }
49  constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
50  { return _time < rhs._time; }
51  constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
52  { return _time > rhs._time; }
53  constexpr bool operator<=(const SdfTimeCode &rhs) const noexcept
54  { return _time <= rhs._time; }
55  constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
56  { return _time >= rhs._time; }
57 
58  constexpr SdfTimeCode operator*(const SdfTimeCode &rhs) const noexcept
59  { return SdfTimeCode(_time * rhs._time); }
60  constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
61  { return SdfTimeCode(_time / rhs._time); }
62  constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
63  { return SdfTimeCode(_time + rhs._time); }
64  constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
65  { return SdfTimeCode(_time - rhs._time); }
66 
67  /// Explicit conversion to double
68  explicit constexpr operator double() const noexcept {return _time;}
69 
70  /// Hash function
71  size_t GetHash() const {
72  return std::hash<double>()(_time);
73  }
74 
75  /// \class Hash
76  struct Hash
77  {
78  size_t operator()(const SdfTimeCode &ap) const {
79  return ap.GetHash();
80  }
81  };
82 
83  friend size_t hash_value(const SdfTimeCode &ap) { return ap.GetHash(); }
84 
85  /// @}
86 
87  /// \name Accessors
88  /// @{
89 
90  /// Return the time value.
91  constexpr double GetValue() const noexcept {
92  return _time;
93  }
94 
95  /// @}
96 
97 private:
98  friend inline void swap(SdfTimeCode &lhs, SdfTimeCode &rhs) {
99  std::swap(lhs._time, rhs._time);
100  }
101 
102  double _time;
103 };
104 
105 // SdfTimeCode supports value transformations.
107 
108 /// \name Related
109 /// Binary arithmetic and comparison operators with double valued lefthand side.
110 /// @{
111 
112 inline constexpr
113 SdfTimeCode operator*(double time, const SdfTimeCode &timeCode) noexcept
114  { return SdfTimeCode(time) * timeCode; }
115 
116 inline constexpr
117 SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
118  { return SdfTimeCode(time) / timeCode; }
119 
120 inline constexpr
121 SdfTimeCode operator+(double time, const SdfTimeCode &timeCode) noexcept
122  { return SdfTimeCode(time) + timeCode; }
123 
124 inline constexpr
125 SdfTimeCode operator-(double time, const SdfTimeCode &timeCode) noexcept
126  { return SdfTimeCode(time) - timeCode; }
127 
128 inline constexpr
129 bool operator==(double time, const SdfTimeCode &timeCode) noexcept
130  { return SdfTimeCode(time) == timeCode; }
131 
132 inline constexpr
133 bool operator!=(double time, const SdfTimeCode &timeCode) noexcept
134  { return SdfTimeCode(time) != timeCode; }
135 
136 inline constexpr
137 bool operator<(double time, const SdfTimeCode &timeCode) noexcept
138  { return SdfTimeCode(time) < timeCode; }
139 
140 inline constexpr
141 bool operator>(double time, const SdfTimeCode &timeCode) noexcept
142  { return SdfTimeCode(time) > timeCode; }
143 
144 inline constexpr
145 bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
146  { return SdfTimeCode(time) <= timeCode; }
147 
148 inline constexpr
149 bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
150  { return SdfTimeCode(time) >= timeCode; }
151 
152 /// Stream insertion operator for the string representation of this time code.
153 SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
154 
155 /// @}
156 
158 
159 #endif // PXR_USD_SDF_TIME_CODE_H
Mat3< typename promote< S, T >::type > operator*(S scalar, const Mat3< T > &m)
Multiply each element of the given matrix by scalar and return the result.
Definition: Mat3.h:561
constexpr bool operator>(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:141
constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:45
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:91
void swap(UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &a, UT::ArraySet< Key, MULTI, MAX_LOAD_FACTOR_256, Clearer, Hash, KeyEqual > &b)
Definition: UT_ArraySet.h:1699
friend size_t hash_value(const SdfTimeCode &ap)
Explicit conversion to double.
Definition: timeCode.h:83
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
Mat3< typename promote< T0, T1 >::type > operator+(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Add corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:577
friend void swap(SdfTimeCode &lhs, SdfTimeCode &rhs)
Definition: timeCode.h:98
constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:64
constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:51
constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:62
constexpr SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:117
constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:60
Mat3< typename promote< T0, T1 >::type > operator-(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Subtract corresponding elements of m0 and m1 and return the result.
Definition: Mat3.h:587
bool operator!=(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Inequality operator, does exact floating point comparisons.
Definition: Mat3.h:556
size_t GetHash() const
Hash function.
Definition: timeCode.h:71
constexpr bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:149
#define SDF_API
Definition: api.h:23
constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:47
constexpr bool operator<(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:137
constexpr bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:145
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
constexpr SdfTimeCode(double time=0.0) noexcept
Definition: timeCode.h:38
VT_VALUE_TYPE_CAN_TRANSFORM(SdfTimeCode)
constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:55
constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:49
size_t operator()(const SdfTimeCode &ap) const
Definition: timeCode.h:78
SDF_API std::ostream & operator<<(std::ostream &out, const SdfTimeCode &ap)
Stream insertion operator for the string representation of this time code.
constexpr SdfTimeCode operator*(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:58
bool operator==(const Mat3< T0 > &m0, const Mat3< T1 > &m1)
Equality operator, does exact floating point comparisons.
Definition: Mat3.h:542
constexpr bool operator<=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:53