7#ifndef PXR_USD_USD_UTILS_TIME_CODE_RANGE_H
8#define PXR_USD_USD_UTILS_TIME_CODE_RANGE_H
13#include "pxr/usd/usdUtils/api.h"
18#include "pxr/usd/usd/timeCode.h"
25PXR_NAMESPACE_OPEN_SCOPE
28#define USDUTILS_TIME_CODE_RANGE_TOKENS \
29 ((EmptyTimeCodeRange, "NONE")) \
30 ((RangeSeparator, ":")) \
31 ((StrideSeparator, "x"))
34 UsdUtilsTimeCodeRangeTokens,
36 USDUTILS_TIME_CODE_RANGE_TOKENS);
66 using iterator_category = std::forward_iterator_tag;
70 using difference_type = std::ptrdiff_t;
79 return &_currTimeCode;
91 _timeCodeRange->_startTimeCode.
GetValue() +
92 _timeCodeRange->_stride * _currStep);
94 _InvalidateIfExhausted();
105 return preAdvanceIter;
110 return _timeCodeRange == other._timeCodeRange &&
111 _currStep == other._currStep;
116 return !(*
this == other);
123 _timeCodeRange(timeCodeRange),
128 if (_timeCodeRange) {
129 const double startVal = _timeCodeRange->_startTimeCode.
GetValue();
130 const double endVal = _timeCodeRange->_endTimeCode.
GetValue();
131 const double stride = _timeCodeRange->_stride;
133 _maxSteps =
static_cast<size_t>(
134 GfFloor((endVal - startVal + stride) / stride));
135 _currTimeCode = _timeCodeRange->_startTimeCode;
138 _InvalidateIfExhausted();
141 void _InvalidateIfExhausted() {
142 bool finished =
false;
143 if (!_timeCodeRange) {
145 }
else if (_currStep >= _maxSteps) {
150 _timeCodeRange =
nullptr;
163 using iterator = const_iterator;
196 const std::string& frameSpec);
226 (endTimeCode >= startTimeCode) ? 1.0 : -1.0)
243 const double stride) :
244 _startTimeCode(startTimeCode),
245 _endTimeCode(endTimeCode),
250 "startTimeCode cannot be UsdTimeCode::EarliestTime()");
256 "startTimeCode cannot be UsdTimeCode::Default()");
262 "endTimeCode cannot be UsdTimeCode::EarliestTime()");
268 "endTimeCode cannot be UsdTimeCode::Default()");
274 if (_endTimeCode < _startTimeCode) {
276 "endTimeCode cannot be less than startTimeCode with "
281 }
else if (_stride < 0.0) {
282 if (_endTimeCode > _startTimeCode) {
284 "endTimeCode cannot be greater than startTimeCode with "
298 return _startTimeCode;
344 explicit operator bool()
const {
350 return _startTimeCode == other._startTimeCode &&
351 _endTimeCode == other._endTimeCode &&
352 _stride == other._stride;
357 return !(*
this == other);
389PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
double GetValue() const
Return the numeric value for this time.
bool IsDefault() const
Return true if this time represents the 'default' sentinel value, false otherwise.
bool IsEarliestTime() const
Return true if this time represents the lowest/earliest possible timeCode, false otherwise.
A forward iterator into a UsdUtilsTimeCodeRange.
bool operator!=(const const_iterator &other) const
Return true if this iterator is not equivalent to other.
pointer operator->()
Returns a pointer to the UsdTimeCode referenced by this iterator.
reference operator*()
Returns the UsdTimeCode referenced by this iterator.
const_iterator operator++(int)
Post-increment operator.
bool operator==(const const_iterator &other) const
Return true if this iterator is equivalent to other.
const_iterator & operator++()
Pre-increment operator.
Represents a range of UsdTimeCode values as start and end time codes and a stride value.
iterator begin() const
Return an iterator to the start of this range.
UsdUtilsTimeCodeRange(const UsdTimeCode timeCode)
Construct a range containing only the given timeCode.
UsdUtilsTimeCodeRange()
Construct an invalid empty range.
const_iterator cbegin() const
Return a const_iterator to the start of this range.
UsdTimeCode GetStartTimeCode() const
Return the start time code of this range.
bool operator==(const UsdUtilsTimeCodeRange &other) const
Return true if this range is equivalent to other.
UsdUtilsTimeCodeRange(const UsdTimeCode startTimeCode, const UsdTimeCode endTimeCode)
Construct a range containing the time codes from startTimeCode to endTimeCode.
double GetStride() const
Return the stride value of this range.
bool empty() const
Return true if this range contains no time codes, or false otherwise.
iterator end() const
Return the past-the-end iterator for this range.
static USDUTILS_API UsdUtilsTimeCodeRange CreateFromFrameSpec(const std::string &frameSpec)
Create a time code range from frameSpec.
bool operator!=(const UsdUtilsTimeCodeRange &other) const
Return true if this range is not equivalent to other.
const_iterator cend() const
Return the past-the-end const_iterator for this range.
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 ...
bool IsValid() const
Return true if this range contains one or more time codes, or false otherwise.
UsdTimeCode GetEndTimeCode() const
Return the end time code of this range.
Assorted mathematical utility functions.
double GfFloor(double f)
Return floor(f).
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
USDUTILS_API std::istream & operator>>(std::istream &is, UsdUtilsTimeCodeRange &timeCodeRange)
Stream extraction operator.