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 SDF_TIMECODE_H
25 #define SDF_TIMECODE_H
26 
28 
29 #include "pxr/pxr.h"
30 #include "pxr/usd/sdf/api.h"
31 
32 #include <algorithm>
33 #include <functional>
34 #include <iosfwd>
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
45 {
46 public:
50 
54  constexpr SdfTimeCode(double time = 0.0) noexcept : _time(time) {};
55 
57 
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 
84  explicit constexpr operator double() const noexcept {return _time;}
85 
87  size_t GetHash() const {
88  return std::hash<double>()(_time);
89  }
90 
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 
102 
105 
107  constexpr double GetValue() const noexcept {
108  return _time;
109  }
110 
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 
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 
166 SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
167 
169 
170 PXR_NAMESPACE_CLOSE_SCOPE
171 
172 #endif // SDF_TIMECODE_H
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:107
AR_API bool operator!=(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
AR_API bool operator==(const ArAssetInfo &lhs, const ArAssetInfo &rhs)
size_t GetHash() const
Hash function.
Definition: timeCode.h:87
void swap(UsdStageLoadRules &l, UsdStageLoadRules &r)
Swap the contents of rules l and r.
Value type that represents a time code.
Definition: timeCode.h:44
constexpr SdfTimeCode(double time=0.0) noexcept
Construct a time code with the given time.
Definition: timeCode.h:54
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].