This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
timestamp.h
Go to the documentation of this file.
1//
2// Copyright 2021 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_AR_TIMESTAMP_H
8#define PXR_USD_AR_TIMESTAMP_H
9
11
12#include "pxr/pxr.h"
13#include "pxr/usd/ar/api.h"
14
15#include "pxr/base/arch/hints.h"
16#include "pxr/base/tf/hash.h"
17
18#include <limits>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
26{
27public:
30 : _time(std::numeric_limits<double>::quiet_NaN())
31 {
32 }
33
35 explicit ArTimestamp(double time)
36 : _time(time)
37 {
38 }
39
41 bool IsValid() const
42 {
43 return !std::isnan(_time);
44 }
45
49 double GetTime() const
50 {
51 if (ARCH_UNLIKELY(!IsValid())) {
52 _IssueInvalidGetTimeError();
53 }
54 return _time;
55 }
56
61
62 friend bool operator==(const ArTimestamp& lhs, const ArTimestamp& rhs)
63 {
64 return (!lhs.IsValid() && !rhs.IsValid()) ||
65 (lhs.IsValid() && rhs.IsValid() && lhs._time == rhs._time);
66 }
67
68 friend bool operator!=(const ArTimestamp& lhs, const ArTimestamp& rhs)
69 {
70 return !(lhs == rhs);
71 }
72
73 friend bool operator<(const ArTimestamp& lhs, const ArTimestamp& rhs)
74 {
75 return (!lhs.IsValid() && rhs.IsValid()) ||
76 (lhs.IsValid() && rhs.IsValid() && lhs._time < rhs._time);
77 }
78
79 friend bool operator>=(const ArTimestamp& lhs, const ArTimestamp& rhs)
80 {
81 return !(lhs < rhs);
82 }
83
84 friend bool operator<=(const ArTimestamp& lhs, const ArTimestamp& rhs)
85 {
86 return !lhs.IsValid() || (rhs.IsValid() && lhs._time <= rhs._time);
87 }
88
89 friend bool operator>(const ArTimestamp& lhs, const ArTimestamp& rhs)
90 {
91 return !(lhs <= rhs);
92 }
93
95
96private:
97 AR_API
98 void _IssueInvalidGetTimeError() const;
99
100 // TfHash support.
101 template <class HashState>
102 friend void TfHashAppend(HashState& h, const ArTimestamp& t)
103 {
104 h.Append(t._time);
105 }
106
107 double _time;
108};
109
110PXR_NAMESPACE_CLOSE_SCOPE
111
112#endif
Represents a timestamp for an asset.
Definition: timestamp.h:26
friend bool operator==(const ArTimestamp &lhs, const ArTimestamp &rhs)
Comparison operators Note that invalid timestamps are considered less than all other timestamps.
Definition: timestamp.h:62
double GetTime() const
Return the time represented by this timestamp as a double.
Definition: timestamp.h:49
ArTimestamp(double time)
Create a timestamp at time, which must be a Unix time value.
Definition: timestamp.h:35
ArTimestamp()
Create an invalid timestamp.
Definition: timestamp.h:29
bool IsValid() const
Return true if this timestamp is valid, false otherwise.
Definition: timestamp.h:41
Compiler hints.
STL namespace.