All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
11
12#include "pxr/pxr.h"
13#include "pxr/usd/sdf/api.h"
14
15#include <algorithm>
16#include <functional>
17#include <iosfwd>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
28{
29public:
33
37 constexpr SdfTimeCode(double time = 0.0) noexcept : _time(time) {};
38
40
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
67 explicit constexpr operator double() const noexcept {return _time;}
68
70 size_t GetHash() const {
71 return std::hash<double>()(_time);
72 }
73
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
85
88
90 constexpr double GetValue() const noexcept {
91 return _time;
92 }
93
95
96private:
97 friend inline void swap(SdfTimeCode &lhs, SdfTimeCode &rhs) {
98 std::swap(lhs._time, rhs._time);
99 }
100
101 double _time;
102};
103
107
108inline constexpr
109SdfTimeCode operator*(double time, const SdfTimeCode &timeCode) noexcept
110 { return SdfTimeCode(time) * timeCode; }
111
112inline constexpr
113SdfTimeCode operator/(double time, const SdfTimeCode &timeCode) noexcept
114 { return SdfTimeCode(time) / timeCode; }
115
116inline constexpr
117SdfTimeCode operator+(double time, const SdfTimeCode &timeCode) noexcept
118 { return SdfTimeCode(time) + timeCode; }
119
120inline constexpr
121SdfTimeCode operator-(double time, const SdfTimeCode &timeCode) noexcept
122 { return SdfTimeCode(time) - timeCode; }
123
124inline constexpr
125bool operator==(double time, const SdfTimeCode &timeCode) noexcept
126 { return SdfTimeCode(time) == timeCode; }
127
128inline constexpr
129bool operator!=(double time, const SdfTimeCode &timeCode) noexcept
130 { return SdfTimeCode(time) != timeCode; }
131
132inline constexpr
133bool operator<(double time, const SdfTimeCode &timeCode) noexcept
134 { return SdfTimeCode(time) < timeCode; }
135
136inline constexpr
137bool operator>(double time, const SdfTimeCode &timeCode) noexcept
138 { return SdfTimeCode(time) > timeCode; }
139
140inline constexpr
141bool operator<=(double time, const SdfTimeCode &timeCode) noexcept
142 { return SdfTimeCode(time) <= timeCode; }
143
144inline constexpr
145bool operator>=(double time, const SdfTimeCode &timeCode) noexcept
146 { return SdfTimeCode(time) >= timeCode; }
147
149SDF_API std::ostream& operator<<(std::ostream& out, const SdfTimeCode& ap);
150
152
153PXR_NAMESPACE_CLOSE_SCOPE
154
155#endif // PXR_USD_SDF_TIME_CODE_H
Value type that represents a time code.
Definition: timeCode.h:28
constexpr double GetValue() const noexcept
Return the time value.
Definition: timeCode.h:90
constexpr SdfTimeCode(double time=0.0) noexcept
Construct a time code with the given time.
Definition: timeCode.h:37
size_t GetHash() const
Hash function.
Definition: timeCode.h:70
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].