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 
15 #include <algorithm>
16 #include <functional>
17 #include <iosfwd>
18 
20 
21 /// \class SdfTimeCode
22 ///
23 /// Value type that represents a time code. It's equivalent to a double type
24 /// value but is used to indicate that this value should be resolved by any
25 /// time based value resolution.
26 ///
28 {
29 public:
30  /// \name Constructors
31  /// @{
32  ///
33 
34  /// Construct a time code with the given time.
35  /// A default constructed SdfTimeCode has a time of 0.0.
36  /// A double value can implicitly cast to SdfTimeCode.
37  constexpr SdfTimeCode(double time = 0.0) noexcept : _time(time) {};
38 
39  /// @}
40 
41  ///\name Operators
42  /// @{
43 
44  constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
45  { return _time == rhs._time; }
46  constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
47  { return _time != rhs._time; }
48  constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
49  { return _time < rhs._time; }
50  constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
51  { return _time > rhs._time; }
52  constexpr bool operator<=(const SdfTimeCode &rhs) const noexcept
53  { return _time <= rhs._time; }
54  constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
55  { return _time >= rhs._time; }
56 
57  constexpr SdfTimeCode operator*(const SdfTimeCode &rhs) const noexcept
58  { return SdfTimeCode(_time * rhs._time); }
59  constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
60  { return SdfTimeCode(_time / rhs._time); }
61  constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
62  { return SdfTimeCode(_time + rhs._time); }
63  constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
64  { return SdfTimeCode(_time - rhs._time); }
65 
66  /// Explicit conversion to double
67  explicit constexpr operator double() const noexcept {return _time;}
68 
69  /// Hash function
70  size_t GetHash() const {
71  return std::hash<double>()(_time);
72  }
73 
74  /// \class Hash
75  struct Hash
76  {
77  size_t operator()(const SdfTimeCode &ap) const {
78  return ap.GetHash();
79  }
80  };
81 
82  friend size_t hash_value(const SdfTimeCode &ap) { return ap.GetHash(); }
83 
84  /// @}
85 
86  /// \name Accessors
87  /// @{
88 
89  /// Return the time value.
90  constexpr double GetValue() const noexcept {
91  return _time;
92  }
93 
94  /// @}
95 
96 private:
97  friend inline void swap(SdfTimeCode &lhs, SdfTimeCode &rhs) {
98  std::swap(lhs._time, rhs._time);
99  }
100 
101  double _time;
102 };
103 
104 /// \name Related
105 /// Binary arithmetic and comparison operators with double valued lefthand side.
106 /// @{
107 
108 inline constexpr
109 SdfTimeCode operator*(double time, const SdfTimeCode &timeCode) noexcept
110  { return SdfTimeCode(time) * timeCode; }
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 bool 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 /// Stream insertion operator for the string representation of this time code.
149 SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
150 
151 /// @}
152 
154 
155 #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:137
constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:44
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:90
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:82
GT_API const UT_StringHolder time
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:97
constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:63
constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:50
constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:61
constexpr SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:113
constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:59
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:70
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 SDF_API
Definition: api.h:23
constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:46
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
constexpr bool operator<(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:133
constexpr bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:141
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
constexpr SdfTimeCode(double time=0.0) noexcept
Definition: timeCode.h:37
constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:54
constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:48
size_t operator()(const SdfTimeCode &ap) const
Definition: timeCode.h:77
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:57
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:52