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"
42PXR_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);
406PXR_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.