HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
time.h
Go to the documentation of this file.
1 //
2 // Copyright 2025 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_EXEC_EF_TIME_H
8 #define PXR_EXEC_EF_TIME_H
9 
10 /// \file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
15 
16 #include "pxr/usd/usd/timeCode.h"
17 
18 #include <cstdint>
19 #include <iosfwd>
20 
22 
23 ///////////////////////////////////////////////////////////////////////////////
24 ///
25 /// A class that represents a point in time for execution.
26 ///
27 /// Time has a frame value that can be double-valued or set to "default". The
28 /// "default" frame can be thought to represent a point that is not on the
29 /// timeline.
30 ///
31 /// EfTime also contains spline evaluation flags that cause splines to be
32 /// evaluated in application-specific, special ways. These flags should
33 /// be consumed when spline evaluation is dispatched to the application-level
34 /// evaluation logic.
35 ///
36 class EfTime
37 {
38 public:
39  /// Data type for storing app-specific spline evaluation flags.
40  ///
41  using SplineEvaluationFlags = uint8_t;
42 
43  /// A default constructed EfTime is set to the default frame value.
44  ///
45  EfTime() :
46  _timeCode(UsdTimeCode::Default()),
47  _splineFlags(0)
48  {}
49 
50  /// Constructs an EfTime object for a specific frame with an optional
51  /// evaluation location and set of spline flags.
52  ///
53  explicit EfTime(
54  const UsdTimeCode timeCode,
55  SplineEvaluationFlags splineFlags = 0) :
56  _timeCode(timeCode),
57  _splineFlags(splineFlags)
58  {}
59 
60 
61  /// \name Time code
62  /// @{
63 
64  /// Returns the time code.
65  ///
66  const UsdTimeCode GetTimeCode() const {
67  return _timeCode;
68  }
69 
70  /// Sets the time code to \p timeCode.
71  ///
72  void SetTimeCode(const UsdTimeCode timeCode) {
73  _timeCode = timeCode;
74  }
75 
76  /// @}
77 
78 
79  /// \name Spline evaluation flags
80  /// @{
81 
82  /// Returns the spline evaluation flags that will be used during evaluation.
83  ///
85  return _splineFlags;
86  }
87 
88  /// Sets the spline evaluation flags that will be used during evaluation.
89  ///
91  _splineFlags = flags;
92  }
93 
94  /// @}
95 
96 
97  /// Returns \c true if *this == rhs.
98  ///
99  bool operator==(const EfTime &rhs) const {
100  if (!_timeCode.IsDefault() && !rhs._timeCode.IsDefault()) {
101  return _timeCode == rhs._timeCode
102  && _splineFlags == rhs._splineFlags;
103  }
104  return _timeCode.IsDefault() == rhs._timeCode.IsDefault();
105  }
106 
107  bool operator!=(const EfTime &rhs) const {
108  return !(*this == rhs);
109  }
110 
111  /// Returns \c true if *this < rhs.
112  ///
113  /// Note that a time with frame set to "default" is lesser than all
114  /// non-default times.
115  ///
116  /// Also note that evaluation location and spline flags have no effect on
117  /// ordering for the default frame. Spline flags are only used for stable
118  /// ordering, but there is no logical ordering between two sets of spline
119  /// flags.
120  ///
121  bool operator<(const EfTime &rhs) const {
122  if (_timeCode.IsDefault() || rhs._timeCode.IsDefault()) {
123  return _timeCode < rhs._timeCode;
124  }
125 
126  return _timeCode < rhs._timeCode ||
127  (_timeCode == rhs._timeCode && _splineFlags < rhs._splineFlags);
128  }
129 
130  bool operator<=(const EfTime &rhs) const {
131  return !(rhs < *this);
132  }
133 
134  bool operator>(const EfTime &rhs) const {
135  return rhs < *this;
136  }
137 
138  bool operator>=(const EfTime &rhs) const {
139  return !(*this < rhs);
140  }
141 
142  /// Provides a hash function for EfTime.
143  ///
144  template <class HashState>
145  friend void TfHashAppend(HashState &h, const EfTime &t) {
146  h.Append(t._timeCode);
147  if (!t._timeCode.IsDefault()) {
148  h.Append(t._splineFlags);
149  }
150  }
151 
152  /// Returns this object as string. Note that evaluation location will only
153  /// be denoted in the output string if the time code IsPreTime().
154  ///
155  EF_API
156  std::string GetAsString() const;
157 
158 private:
159 
160  // The time code value.
161  UsdTimeCode _timeCode;
162 
163  // The spline evaluation flags to use during computation.
164  SplineEvaluationFlags _splineFlags;
165 };
166 
167 /// Output an EfTime.
168 ///
169 EF_API
170 std::ostream &operator<<(std::ostream &os, const EfTime &time);
171 
173 
174 #endif
GLbitfield flags
Definition: glcorearb.h:1596
uint8_t SplineEvaluationFlags
Definition: time.h:41
bool operator>=(const EfTime &rhs) const
Definition: time.h:138
GT_API const UT_StringHolder time
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
EfTime(const UsdTimeCode timeCode, SplineEvaluationFlags splineFlags=0)
Definition: time.h:53
Definition: time.h:36
EfTime()
Definition: time.h:45
void SetSplineEvaluationFlags(SplineEvaluationFlags flags)
Definition: time.h:90
bool IsDefault() const
Definition: timeCode.h:145
const UsdTimeCode GetTimeCode() const
Definition: time.h:66
bool operator>(const EfTime &rhs) const
Definition: time.h:134
EF_API std::string GetAsString() const
bool operator!=(const EfTime &rhs) const
Definition: time.h:107
bool operator==(const EfTime &rhs) const
Definition: time.h:99
void SetTimeCode(const UsdTimeCode timeCode)
Definition: time.h:72
GLdouble t
Definition: glad.h:2397
friend void TfHashAppend(HashState &h, const EfTime &t)
Definition: time.h:145
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
bool operator<=(const EfTime &rhs) const
Definition: time.h:130
SplineEvaluationFlags GetSplineEvaluationFlags() const
Definition: time.h:84
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool operator<(const EfTime &rhs) const
Definition: time.h:121
EF_API std::ostream & operator<<(std::ostream &os, const EfTime &time)
#define EF_API
Definition: api.h:25