From 882de98242ed607c4cee1ca6a7fa780248ce8eed Mon Sep 17 00:00:00 2001 From: Matt Kuruc Date: Wed, 6 Sep 2023 21:09:04 -0700 Subject: [PATCH] Replace `boost::optional` with `std::optional` in `usd` --- pxr/usd/usd/clip.cpp | 25 ++++++++++++------------- pxr/usd/usd/clipSet.cpp | 3 ++- pxr/usd/usd/clipSetDefinition.cpp | 8 ++++---- pxr/usd/usd/clipSetDefinition.h | 15 +++++++-------- pxr/usd/usd/stage.cpp | 20 ++++++++++---------- pxr/usd/usd/stage.h | 5 ++--- 6 files changed, 37 insertions(+), 39 deletions(-) diff --git a/pxr/usd/usd/clip.cpp b/pxr/usd/usd/clip.cpp index f248d5df51..60aba17546 100644 --- a/pxr/usd/usd/clip.cpp +++ b/pxr/usd/usd/clip.cpp @@ -42,8 +42,7 @@ #include "pxr/base/gf/interval.h" #include "pxr/base/tf/stringUtils.h" -#include - +#include #include #include #include @@ -305,7 +304,7 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( return true; } - boost::optional translatedLower, translatedUpper; + std::optional translatedLower, translatedUpper; auto _CanTranslate = [&time, &upperInClip, &lowerInClip, this, &translatedLower, &translatedUpper]( const TimeMappings& mappings, size_t i1, size_t i2, @@ -331,19 +330,19 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( if (lower <= timeInClip && timeInClip <= upper) { if (map1.internalTime != map2.internalTime) { - translated.reset( - this->_TranslateTimeToExternal(timeInClip, i1, i2)); + translated = + this->_TranslateTimeToExternal(timeInClip, i1, i2); } else { const bool lowerUpperMatch = (lowerInClip == upperInClip); if (lowerUpperMatch && time == map1.externalTime) { - translated.reset(map1.externalTime); + translated = map1.externalTime; } else if (lowerUpperMatch && time == map2.externalTime) { - translated.reset(map2.externalTime); + translated = map2.externalTime; } else { if (translatingLower) { - translated.reset(map1.externalTime); + translated = map1.externalTime; } else { - translated.reset(map2.externalTime); + translated = map2.externalTime; } } } @@ -378,17 +377,17 @@ Usd_Clip::_GetBracketingTimeSamplesForPathFromClipLayer( // The 'timingOutsideClip' test case in testUsdModelClips exercises // this behavior. if (lowerInClip < times->front().internalTime) { - translatedLower.reset(times->front().externalTime); + translatedLower = times->front().externalTime; } else if (lowerInClip > times->back().internalTime) { - translatedLower.reset(times->back().externalTime); + translatedLower = times->back().externalTime; } if (upperInClip < times->front().internalTime) { - translatedUpper.reset(times->front().externalTime); + translatedUpper = times->front().externalTime; } else if (upperInClip > times->back().internalTime) { - translatedUpper.reset(times->back().externalTime); + translatedUpper = times->back().externalTime; } } diff --git a/pxr/usd/usd/clipSet.cpp b/pxr/usd/usd/clipSet.cpp index 0ea49bb4f6..a9ed48d6e5 100644 --- a/pxr/usd/usd/clipSet.cpp +++ b/pxr/usd/usd/clipSet.cpp @@ -307,7 +307,8 @@ Usd_ClipSet::New( // message.. if (!_ValidateClipFields( *clipDef.clipAssetPaths, *clipDef.clipPrimPath, - *clipDef.clipActive, clipDef.clipTimes.get_ptr(), + *clipDef.clipActive, + clipDef.clipTimes ? &(clipDef.clipTimes.value()) : nullptr, status)) { return nullptr; } diff --git a/pxr/usd/usd/clipSetDefinition.cpp b/pxr/usd/usd/clipSetDefinition.cpp index ac432b2ed7..c8041eec44 100644 --- a/pxr/usd/usd/clipSetDefinition.cpp +++ b/pxr/usd/usd/clipSetDefinition.cpp @@ -149,9 +149,9 @@ _DeriveClipInfo(const std::string& templateAssetPath, const double activeOffset, const double startTimeCode, const double endTimeCode, - boost::optional* clipTimes, - boost::optional* clipActive, - boost::optional>* clipAssetPaths, + std::optional* clipTimes, + std::optional* clipActive, + std::optional>* clipAssetPaths, const SdfPath& usdPrimPath, const PcpLayerStackPtr& sourceLayerStack, const size_t indexOfSourceLayer) @@ -329,7 +329,7 @@ struct _ClipSet { template static bool -_SetInfo(const VtDictionary& dict, const TfToken& key, boost::optional* out) +_SetInfo(const VtDictionary& dict, const TfToken& key, std::optional* out) { const VtValue* v = TfMapLookupPtr(dict, key.GetString()); if (v && v->IsHolding()) { diff --git a/pxr/usd/usd/clipSetDefinition.h b/pxr/usd/usd/clipSetDefinition.h index e445f8d39a..274d2e837b 100644 --- a/pxr/usd/usd/clipSetDefinition.h +++ b/pxr/usd/usd/clipSetDefinition.h @@ -33,8 +33,7 @@ #include "pxr/base/tf/declarePtrs.h" #include "pxr/base/tf/hash.h" -#include - +#include #include #include @@ -110,12 +109,12 @@ class Usd_ClipSetDefinition h.Append(definition.GetHash()); } - boost::optional > clipAssetPaths; - boost::optional clipManifestAssetPath; - boost::optional clipPrimPath; - boost::optional clipActive; - boost::optional clipTimes; - boost::optional interpolateMissingClipValues; + std::optional> clipAssetPaths; + std::optional clipManifestAssetPath; + std::optional clipPrimPath; + std::optional clipActive; + std::optional clipTimes; + std::optional interpolateMissingClipValues; PcpLayerStackPtr sourceLayerStack; SdfPath sourcePrimPath; diff --git a/pxr/usd/usd/stage.cpp b/pxr/usd/usd/stage.cpp index cc324ffc78..87202b6263 100644 --- a/pxr/usd/usd/stage.cpp +++ b/pxr/usd/usd/stage.cpp @@ -96,8 +96,6 @@ #include "pxr/base/work/utils.h" #include "pxr/base/work/withScopedParallelism.h" -#include - #include #include @@ -105,6 +103,7 @@ #include #include #include +#include #include #include #include @@ -1036,7 +1035,7 @@ _OpenLayer( const std::string &filePath, const ArResolverContext &resolverContext = ArResolverContext()) { - boost::optional binder; + std::optional binder; if (!resolverContext.IsEmpty()) binder.emplace(resolverContext); @@ -1178,8 +1177,8 @@ class Usd_StageOpenRequest : public UsdStageCacheRequest private: SdfLayerHandle _rootLayer; - boost::optional _sessionLayer; - boost::optional _pathResolverContext; + std::optional _sessionLayer; + std::optional _pathResolverContext; UsdStage::InitialLoadSet _initialLoadSet; }; @@ -3251,11 +3250,11 @@ UsdStage::_ComposeSubtreesInParallel( } } catch (...) { - _dispatcher = boost::none; + _dispatcher = std::nullopt; throw; } - _dispatcher = boost::none; + _dispatcher = std::nullopt; }); } @@ -3408,7 +3407,7 @@ UsdStage::_DestroyPrimsInParallel(const vector& paths) }); } } - _dispatcher = boost::none; + _dispatcher = std::nullopt; }); } @@ -8416,12 +8415,13 @@ struct UsdStage::_ResolveInfoResolver { const SdfLayerOffset layerToStageOffset = _GetLayerToStageOffset(node, layer); - boost::optional localTime; + std::optional localTime; if (time) { localTime = layerToStageOffset.GetInverse() * (*time); } - if (_HasTimeSamples(layer, specPath, localTime.get_ptr(), + if (_HasTimeSamples(layer, specPath, + localTime ? std::addressof(*localTime) : nullptr, &_extraInfo->lowerSample, &_extraInfo->upperSample)) { _resolveInfo->_source = UsdResolveInfoSourceTimeSamples; diff --git a/pxr/usd/usd/stage.h b/pxr/usd/usd/stage.h index 212e1a1fca..ba6ecad8f1 100644 --- a/pxr/usd/usd/stage.h +++ b/pxr/usd/usd/stage.h @@ -51,8 +51,6 @@ #include "pxr/base/vt/value.h" #include "pxr/base/work/dispatcher.h" -#include - #include #include #include @@ -61,6 +59,7 @@ #include #include #include +#include #include #include @@ -2321,7 +2320,7 @@ class UsdStage : public TfRefBase, public TfWeakBase { class _PendingChanges; _PendingChanges* _pendingChanges; - boost::optional _dispatcher; + std::optional _dispatcher; // To provide useful aggregation of malloc stats, we bill everything // for this stage - from all access points - to this tag.