Loading...
Searching...
No Matches
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
28
29#include "pxr/pxr.h"
30#include "pxr/usd/sdf/api.h"
31
32#include <algorithm>
33#include <functional>
34#include <iosfwd>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
45{
46public:
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
113private:
114 friend inline void swap(SdfTimeCode &lhs, SdfTimeCode &rhs) {
115 std::swap(lhs._time, rhs._time);
116 }
117
118 double _time;
119};
120
124
125inline constexpr
126SdfTimeCode operator*(double time, const SdfTimeCode &timeCode) noexcept
127 { return SdfTimeCode(time) * timeCode; }
128
129inline constexpr
130SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
131 { return SdfTimeCode(time) / timeCode; }
132
133inline constexpr
134SdfTimeCode operator+(double time, const SdfTimeCode &timeCode) noexcept
135 { return SdfTimeCode(time) + timeCode; }
136
137inline constexpr
138SdfTimeCode operator-(double time, const SdfTimeCode &timeCode) noexcept
139 { return SdfTimeCode(time) - timeCode; }
140
141inline constexpr
142bool operator==(double time, const SdfTimeCode &timeCode) noexcept
143 { return SdfTimeCode(time) == timeCode; }
144
145inline constexpr
146bool operator!=(double time, const SdfTimeCode &timeCode) noexcept
147 { return SdfTimeCode(time) != timeCode; }
148
149inline constexpr
150bool operator<(double time, const SdfTimeCode &timeCode) noexcept
151 { return SdfTimeCode(time) < timeCode; }
152
153inline constexpr
154bool operator>(double time, const SdfTimeCode &timeCode) noexcept
155 { return SdfTimeCode(time) > timeCode; }
156
157inline constexpr
158bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
159 { return SdfTimeCode(time) <= timeCode; }
160
161inline constexpr
162bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
163 { return SdfTimeCode(time) >= timeCode; }
164
166SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
167
169
170PXR_NAMESPACE_CLOSE_SCOPE
171
172#endif // PXR_USD_SDF_TIME_CODE_H
Value type that represents a time code.
Definition: timeCode.h:45
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:107
constexpr SdfTimeCode(double time=0.0) noexcept
Construct a time code with the given time.
Definition: timeCode.h:54
size_t GetHash() const
Hash function.
Definition: timeCode.h:87
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].