24 #ifndef PXR_USD_USD_UTILS_TIME_CODE_RANGE_H 25 #define PXR_USD_USD_UTILS_TIME_CODE_RANGE_H 30 #include "pxr/usd/usdUtils/api.h" 35 #include "pxr/usd/usd/timeCode.h" 42 PXR_NAMESPACE_OPEN_SCOPE
45 #define USDUTILS_TIME_CODE_RANGE_TOKENS \ 46 ((EmptyTimeCodeRange, "NONE")) \ 47 ((RangeSeparator, ":")) \ 48 ((StrideSeparator, "x")) 51 UsdUtilsTimeCodeRangeTokens,
53 USDUTILS_TIME_CODE_RANGE_TOKENS);
83 using iterator_category = std::forward_iterator_tag;
87 using difference_type = std::ptrdiff_t;
96 return &_currTimeCode;
104 if (_timeCodeRange) {
108 _timeCodeRange->_startTimeCode.
GetValue() +
109 _timeCodeRange->_stride * _currStep);
111 _InvalidateIfExhausted();
122 return preAdvanceIter;
127 return _timeCodeRange == other._timeCodeRange &&
128 _currStep == other._currStep;
133 return !(*
this == other);
140 _timeCodeRange(timeCodeRange),
145 if (_timeCodeRange) {
146 const double startVal = _timeCodeRange->_startTimeCode.
GetValue();
147 const double endVal = _timeCodeRange->_endTimeCode.
GetValue();
148 const double stride = _timeCodeRange->_stride;
150 _maxSteps = static_cast<size_t>(
151 GfFloor((endVal - startVal + stride) / stride));
152 _currTimeCode = _timeCodeRange->_startTimeCode;
155 _InvalidateIfExhausted();
158 void _InvalidateIfExhausted() {
159 bool finished =
false;
160 if (!_timeCodeRange) {
162 }
else if (_currStep >= _maxSteps) {
167 _timeCodeRange =
nullptr;
180 using iterator = const_iterator;
213 const std::string& frameSpec);
243 (endTimeCode >= startTimeCode) ? 1.0 : -1.0)
260 const double stride) :
261 _startTimeCode(startTimeCode),
262 _endTimeCode(endTimeCode),
267 "startTimeCode cannot be UsdTimeCode::EarliestTime()");
273 "startTimeCode cannot be UsdTimeCode::Default()");
279 "endTimeCode cannot be UsdTimeCode::EarliestTime()");
285 "endTimeCode cannot be UsdTimeCode::Default()");
291 if (_endTimeCode < _startTimeCode) {
293 "endTimeCode cannot be less than startTimeCode with " 298 }
else if (_stride < 0.0) {
299 if (_endTimeCode > _startTimeCode) {
301 "endTimeCode cannot be greater than startTimeCode with " 315 return _startTimeCode;
361 explicit operator bool()
const {
367 return _startTimeCode == other._startTimeCode &&
368 _endTimeCode == other._endTimeCode &&
369 _stride == other._stride;
374 return !(*
this == other);
406 PXR_NAMESPACE_CLOSE_SCOPE
const_iterator cend() const
Return the past-the-end const_iterator for this range.
bool IsValid() const
Return true if this range contains one or more time codes, or false otherwise.
reference operator *()
Returns the UsdTimeCode referenced by this iterator.
const_iterator cbegin() const
Return a const_iterator to the start of this range.
UsdUtilsTimeCodeRange(const UsdTimeCode timeCode)
Construct a range containing only the given timeCode.
bool operator==(const UsdUtilsTimeCodeRange &other) const
Return true if this range is equivalent to other.
Assorted mathematical utility functions.
bool operator !=(const UsdUtilsTimeCodeRange &other) const
Return true if this range is not equivalent to other.
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
double GfFloor(double f)
Return floor(f).
Low-level utilities for informing users of various internal and external diagnostic conditions.
iterator end() const
Return the past-the-end iterator for this range.
bool operator==(const const_iterator &other) const
Return true if this iterator is equivalent to other.
bool empty() const
Return true if this range contains no time codes, or false otherwise.
UsdUtilsTimeCodeRange()
Construct an invalid empty range.
iterator begin() const
Return an iterator to the start of this range.
UsdTimeCode GetStartTimeCode() const
Return the start time code of this range.
Represents a range of UsdTimeCode values as start and end time codes and a stride value.
double GetStride() const
Return the stride value of this range.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
UsdUtilsTimeCodeRange(const UsdTimeCode startTimeCode, const UsdTimeCode endTimeCode)
Construct a range containing the time codes from startTimeCode to endTimeCode.
USDUTILS_API std::istream & operator>>(std::istream &is, UsdUtilsTimeCodeRange &timeCodeRange)
Stream extraction operator.
A forward iterator into a UsdUtilsTimeCodeRange.
const_iterator operator++(int)
Post-increment operator.
pointer operator->()
Returns a pointer to the UsdTimeCode referenced by this iterator.
bool operator !=(const const_iterator &other) const
Return true if this iterator is not equivalent to other.
This file defines some macros that are useful for declaring and using static TfTokens.
bool IsEarliestTime() const
Return true if this time represents the lowest/earliest possible timeCode, false otherwise.
UsdUtilsTimeCodeRange(const UsdTimeCode startTimeCode, const UsdTimeCode endTimeCode, const double stride)
Construct a range containing the time codes from startTimeCode to endTimeCode using the stride value ...
static USDUTILS_API UsdUtilsTimeCodeRange CreateFromFrameSpec(const std::string &frameSpec)
Create a time code range from frameSpec.
double GetValue() const
Return the numeric value for this time.
const_iterator & operator++()
Pre-increment operator.
bool IsDefault() const
Return true if this time represents the 'default' sentinel value, false otherwise.
UsdTimeCode GetEndTimeCode() const
Return the end time code of this range.
USDUTILS_API std::ostream & operator<<(std::ostream &os, const UsdUtilsTimeCodeRange &timeCodeRange)
Stream insertion operator.