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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_SDF_TIME_CODE_H
25 #define PXR_USD_SDF_TIME_CODE_H
26 
27 /// \file sdf/timeCode.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 
32 #include <algorithm>
33 #include <functional>
34 #include <iosfwd>
35 
37 
38 /// \class SdfTimeCode
39 ///
40 /// Value type that represents a time code. It's equivalent to a double type
41 /// value but is used to indicate that this value should be resolved by any
42 /// time based value resolution.
43 ///
45 {
46 public:
47  /// \name Constructors
48  /// @{
49  ///
50 
51  /// Construct a time code with the given time.
52  /// A default constructed SdfTimeCode has a time of 0.0.
53  /// A double value can implicitly cast to SdfTimeCode.
54  constexpr SdfTimeCode(double time = 0.0) noexcept : _time(time) {};
55 
56  /// @}
57 
58  ///\name Operators
59  /// @{
60 
61  constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
62  { return _time == rhs._time; }
63  constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
64  { return _time != rhs._time; }
65  constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
66  { return _time < rhs._time; }
67  constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
68  { return _time > rhs._time; }
69  constexpr bool operator<=(const SdfTimeCode &rhs) const noexcept
70  { return _time <= rhs._time; }
71  constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
72  { return _time >= rhs._time; }
73 
74  constexpr SdfTimeCode operator*(const SdfTimeCode &rhs) const noexcept
75  { return SdfTimeCode(_time * rhs._time); }
76  constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
77  { return SdfTimeCode(_time / rhs._time); }
78  constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
79  { return SdfTimeCode(_time + rhs._time); }
80  constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
81  { return SdfTimeCode(_time - rhs._time); }
82 
83  /// Explicit conversion to double
84  explicit constexpr operator double() const noexcept {return _time;}
85 
86  /// Hash function
87  size_t GetHash() const {
88  return std::hash<double>()(_time);
89  }
90 
91  /// \class Hash
92  struct Hash
93  {
94  size_t operator()(const SdfTimeCode &ap) const {
95  return ap.GetHash();
96  }
97  };
98 
99  friend size_t hash_value(const SdfTimeCode &ap) { return ap.GetHash(); }
100 
101  /// @}
102 
103  /// \name Accessors
104  /// @{
105 
106  /// Return the time value.
107  constexpr double GetValue() const noexcept {
108  return _time;
109  }
110 
111  /// @}
112 
113 private:
114  friend inline void swap(SdfTimeCode &lhs, SdfTimeCode &rhs) {
115  std::swap(lhs._time, rhs._time);
116  }
117 
118  double _time;
119 };
120 
121 /// \name Related
122 /// Binary arithmetic and comparison operators with double valued lefthand side.
123 /// @{
124 
125 inline constexpr
126 SdfTimeCode operator*(double time, const SdfTimeCode &timeCode) noexcept
127  { return SdfTimeCode(time) * timeCode; }
128 
129 inline constexpr
130 SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
131  { return SdfTimeCode(time) / timeCode; }
132 
133 inline constexpr
134 SdfTimeCode operator+(double time, const SdfTimeCode &timeCode) noexcept
135  { return SdfTimeCode(time) + timeCode; }
136 
137 inline constexpr
138 SdfTimeCode operator-(double time, const SdfTimeCode &timeCode) noexcept
139  { return SdfTimeCode(time) - timeCode; }
140 
141 inline constexpr
142 bool operator==(double time, const SdfTimeCode &timeCode) noexcept
143  { return SdfTimeCode(time) == timeCode; }
144 
145 inline constexpr
146 bool operator!=(double time, const SdfTimeCode &timeCode) noexcept
147  { return SdfTimeCode(time) != timeCode; }
148 
149 inline constexpr
150 bool operator<(double time, const SdfTimeCode &timeCode) noexcept
151  { return SdfTimeCode(time) < timeCode; }
152 
153 inline constexpr
154 bool operator>(double time, const SdfTimeCode &timeCode) noexcept
155  { return SdfTimeCode(time) > timeCode; }
156 
157 inline constexpr
158 bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
159  { return SdfTimeCode(time) <= timeCode; }
160 
161 inline constexpr
162 bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
163  { return SdfTimeCode(time) >= timeCode; }
164 
165 /// Stream insertion operator for the string representation of this time code.
166 SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
167 
168 /// @}
169 
171 
172 #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:154
constexpr bool operator==(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:61
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:107
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:1639
friend size_t hash_value(const SdfTimeCode &ap)
Explicit conversion to double.
Definition: timeCode.h:99
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:114
constexpr SdfTimeCode operator-(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:80
constexpr bool operator>(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:67
constexpr SdfTimeCode operator+(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:78
constexpr SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:130
constexpr SdfTimeCode operator/(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:76
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:87
constexpr bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:162
#define SDF_API
Definition: api.h:40
constexpr bool operator!=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:63
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
constexpr bool operator<(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:150
constexpr bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
Stream insertion operator for the string representation of this time code.
Definition: timeCode.h:158
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
constexpr SdfTimeCode(double time=0.0) noexcept
Definition: timeCode.h:54
constexpr bool operator>=(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:71
constexpr bool operator<(const SdfTimeCode &rhs) const noexcept
Explicit conversion to double.
Definition: timeCode.h:65
size_t operator()(const SdfTimeCode &ap) const
Definition: timeCode.h:94
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:74
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:69