Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace boost::optional with std::optional for sdf list operations #2715

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pxr/usd/pcp/composeSite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ _PcpComposeSiteReferencesOrPayloads(
// relative to the layer where they were expressed.
curListOp.ApplyOperations(result,
[&](SdfListOpType opType, const RefOrPayloadType& refOrPayload)
-> boost::optional<RefOrPayloadType>
-> std::optional<RefOrPayloadType>
{
// Fill in the result reference or payload with the anchored
// asset path instead of the authored asset path. This
Expand All @@ -126,7 +126,7 @@ _PcpComposeSiteReferencesOrPayloads(
// layer. If the empty result was due to an error, that
// will have already been saved to the errors list above.
if (authoredAssetPath.empty()) {
return boost::none;
return std::nullopt;
}

assetPath = SdfComputeAssetPathRelativeToLayer(
Expand Down
17 changes: 8 additions & 9 deletions pxr/usd/pcp/targetIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@

#include "pxr/base/trace/trace.h"

#include <boost/optional.hpp>

#include <functional>
#include <optional>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -319,7 +318,7 @@ _RemoveTargetPathErrorsForPath(

// Callback used to translate paths as path list operations from
// various nodes are applied.
static boost::optional<SdfPath>
static std::optional<SdfPath>
_PathTranslateCallback(
SdfListOpType opType,
const PcpSite &propSite,
Expand Down Expand Up @@ -352,7 +351,7 @@ _PathTranslateCallback(
_RemoveTargetPathErrorsForPath(translatedPath, targetPathErrors);
return translatedPath;
}
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

if (!pathIsMappable) {
Expand All @@ -367,11 +366,11 @@ _PathTranslateCallback(
err->layer = owningProp->GetLayer();
err->composedTargetPath = SdfPath();
targetPathErrors->push_back(err);
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

if (translatedPath.IsEmpty()) {
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

if (cacheForValidation) {
Expand All @@ -390,7 +389,7 @@ _PathTranslateCallback(
err->layer = owningProp->GetLayer();
err->composedTargetPath = translatedPath;
targetPathErrors->push_back(err);
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

// Check if the connection is invalid due to permissions or
Expand All @@ -410,7 +409,7 @@ _PathTranslateCallback(
err->layer = owningProp->GetLayer();
err->composedTargetPath = translatedPath;
targetPathErrors->push_back(err);
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

case InvalidTarget:
Expand All @@ -424,7 +423,7 @@ _PathTranslateCallback(
err->layer = owningProp->GetLayer();
err->composedTargetPath = translatedPath;
targetPathErrors->push_back(err);
return boost::optional<SdfPath>();
return std::optional<SdfPath>();
}

case NoError:
Expand Down
5 changes: 3 additions & 2 deletions pxr/usd/sdf/layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include <functional>
#include <iostream>
#include <mutex>
#include <optional>
#include <set>
#include <thread>
#include <vector>
Expand Down Expand Up @@ -3204,7 +3205,7 @@ SdfLayer::GetExternalAssetDependencies() const
// ModifyItemEdits() callback that updates a reference's or payload's
// asset path for SdfReferenceListEditor and SdfPayloadListEditor.
template <class RefOrPayloadType>
static boost::optional<RefOrPayloadType>
static std::optional<RefOrPayloadType>
_UpdateRefOrPayloadPath(
const string &oldLayerPath,
const string &newLayerPath,
Expand All @@ -3213,7 +3214,7 @@ _UpdateRefOrPayloadPath(
if (refOrPayload.GetAssetPath() == oldLayerPath) {
// Delete if new layer path is empty, otherwise rename.
if (newLayerPath.empty()) {
return boost::optional<RefOrPayloadType>();
return std::optional<RefOrPayloadType>();
} else {
RefOrPayloadType updatedRefOrPayload = refOrPayload;
updatedRefOrPayload.SetAssetPath(newLayerPath);
Expand Down
7 changes: 3 additions & 4 deletions pxr/usd/sdf/listEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
#include "pxr/usd/sdf/schema.h"
#include "pxr/usd/sdf/spec.h"

#include <boost/optional.hpp>

#include <functional>
#include <optional>

PXR_NAMESPACE_OPEN_SCOPE

Expand Down Expand Up @@ -119,7 +118,7 @@ class Sdf_ListEditor
virtual bool ClearEditsAndMakeExplicit() = 0;

typedef std::function<
boost::optional<value_type>(const value_type&)
std::optional<value_type>(const value_type&)
>
ModifyCallback;

Expand All @@ -132,7 +131,7 @@ class Sdf_ListEditor
virtual void ModifyItemEdits(const ModifyCallback& cb) = 0;

typedef std::function<
boost::optional<value_type>(SdfListOpType, const value_type&)
std::optional<value_type>(SdfListOpType, const value_type&)
>
ApplyCallback;

Expand Down
7 changes: 3 additions & 4 deletions pxr/usd/sdf/listEditorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@

#include "pxr/base/vt/value.h" // for Vt_DefaultValueFactory

#include <boost/optional.hpp>

#include <functional>
#include <memory>
#include <optional>

PXR_NAMESPACE_OPEN_SCOPE

Expand All @@ -63,11 +62,11 @@ class SdfListEditorProxy {
typedef std::vector<value_type> value_vector_type;

// ApplyEdits types.
typedef std::function<boost::optional<value_type>
typedef std::function<std::optional<value_type>
(SdfListOpType, const value_type&)> ApplyCallback;

// ModifyEdits types.
typedef std::function<boost::optional<value_type>
typedef std::function<std::optional<value_type>
(const value_type&)> ModifyCallback;

/// Creates a default proxy object. The object evaluates to \c false in a
Expand Down
20 changes: 9 additions & 11 deletions pxr/usd/sdf/listOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include "pxr/base/tf/token.h"
#include "pxr/base/trace/trace.h"

#include <boost/optional.hpp>

#include <ostream>

using std::string;
Expand Down Expand Up @@ -344,7 +342,7 @@ SdfListOp<T>::ApplyOperations(ItemVector* vec, const ApplyCallback& cb) const
}

template <typename T>
boost::optional<SdfListOp<T>>
std::optional<SdfListOp<T>>
SdfListOp<T>::ApplyOperations(const SdfListOp<T> &inner) const
{
if (IsExplicit()) {
Expand Down Expand Up @@ -422,7 +420,7 @@ SdfListOp<T>::ApplyOperations(const SdfListOp<T> &inner) const
// and there is no way to express the relative order dependency
// between 0 and 1.
//
return boost::optional<SdfListOp<T>>();
return std::optional<SdfListOp<T>>();
}

template <class ItemType, class ListType, class MapType>
Expand Down Expand Up @@ -468,7 +466,7 @@ SdfListOp<T>::_AddKeys(
{
TF_FOR_ALL(i, GetItems(op)) {
if (callback) {
if (boost::optional<T> item = callback(op, *i)) {
if (std::optional<T> item = callback(op, *i)) {
// Only append if the item isn't already present.
_InsertIfUnique(*item, result, search);
}
Expand All @@ -490,7 +488,7 @@ SdfListOp<T>::_PrependKeys(
const ItemVector& items = GetItems(op);
if (callback) {
for (auto i = items.rbegin(), iEnd = items.rend(); i != iEnd; ++i) {
if (boost::optional<T> mappedItem = callback(op, *i)) {
if (std::optional<T> mappedItem = callback(op, *i)) {
_InsertOrMove(*mappedItem, result->begin(), result, search);
}
}
Expand All @@ -512,7 +510,7 @@ SdfListOp<T>::_AppendKeys(
const ItemVector& items = GetItems(op);
if (callback) {
for (const T& item: items) {
if (boost::optional<T> mappedItem = callback(op, item)) {
if (std::optional<T> mappedItem = callback(op, item)) {
_InsertOrMove(*mappedItem, result->end(), result, search);
}
}
Expand All @@ -533,7 +531,7 @@ SdfListOp<T>::_DeleteKeys(
{
TF_FOR_ALL(i, GetItems(op)) {
if (callback) {
if (boost::optional<T> item = callback(op, *i)) {
if (std::optional<T> item = callback(op, *i)) {
_RemoveIfPresent(*item, result, search);
}
}
Expand All @@ -556,7 +554,7 @@ SdfListOp<T>::_ReorderKeys(
std::set<ItemType, _ItemComparator> orderSet;
TF_FOR_ALL(i, GetItems(op)) {
if (callback) {
if (boost::optional<T> item = callback(op, *i)) {
if (std::optional<T> item = callback(op, *i)) {
if (orderSet.insert(*item).second) {
order.push_back(*item);
}
Expand Down Expand Up @@ -612,10 +610,10 @@ _ModifyCallbackHelper(const typename SdfListOp<T>::ModifyCallback& cb,
TfDenseHashSet<T, TfHash> existingSet;

for (const T& item : *itemVector) {
boost::optional<T> modifiedItem = cb(item);
std::optional<T> modifiedItem = cb(item);
if (removeDuplicates && modifiedItem) {
if (!existingSet.insert(*modifiedItem).second) {
modifiedItem = boost::none;
modifiedItem = std::nullopt;
}
}

Expand Down
9 changes: 4 additions & 5 deletions pxr/usd/sdf/listOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/hash.h"

#include <boost/optional/optional_fwd.hpp>

#include <functional>
#include <iosfwd>
#include <list>
#include <map>
#include <optional>
#include <string>
#include <vector>

Expand Down Expand Up @@ -188,7 +187,7 @@ class SdfListOp {

/// Callback type for ApplyOperations.
typedef std::function<
boost::optional<ItemType>(SdfListOpType, const ItemType&)
std::optional<ItemType>(SdfListOpType, const ItemType&)
> ApplyCallback;

/// Applies edit operations to the given ItemVector.
Expand All @@ -211,12 +210,12 @@ class SdfListOp {
/// the explicit, prepended, appended, and deleted portions of
/// SdfListOp are closed under composition with ApplyOperations().
SDF_API
boost::optional<SdfListOp<T>>
std::optional<SdfListOp<T>>
ApplyOperations(const SdfListOp<T> &inner) const;

/// Callback type for ModifyOperations.
typedef std::function<
boost::optional<ItemType>(const ItemType&)
std::optional<ItemType>(const ItemType&)
> ModifyCallback;

/// Modifies operations specified in this object.
Expand Down
4 changes: 2 additions & 2 deletions pxr/usd/sdf/listOpListEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ class Sdf_ListOpListEditor

private:
static
boost::optional<value_type>
std::optional<value_type>
_ModifyCallbackHelper(const ModifyCallback& cb,
const TypePolicy& typePolicy,
const value_type& v)
{
boost::optional<value_type> value = cb(v);
std::optional<value_type> value = cb(v);
return value ? typePolicy.Canonicalize(*value) : value;
}

Expand Down
6 changes: 3 additions & 3 deletions pxr/usd/sdf/listProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
#include "pxr/base/tf/diagnostic.h"
#include "pxr/base/tf/errorMark.h"
#include "pxr/base/tf/iterator.h"
#include <boost/optional.hpp>

#include <memory>
#include <optional>
#include <type_traits>

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -663,10 +663,10 @@ class SdfListProxy {
/// Modify all edits in this list.
///
/// \p callback must be a callable that accepts an argument of type
/// value_type and returns a boost::optional<value_type>.
/// value_type and returns a std::optional<value_type>.
///
/// \p callback is called with every item in the list. If an invalid
/// boost::optional is returned, the item is removed. Otherwise it's
/// std::optional is returned, the item is removed. Otherwise it's
/// replaced with the returned item. If a returned item matches an
/// item that was previously returned, the returned item will be
/// removed.
Expand Down
12 changes: 6 additions & 6 deletions pxr/usd/sdf/pyListEditorProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Sdf_PyListEditorUtils {
// Do nothing
}

boost::optional<V> operator()(SdfListOpType op, const V& value)
std::optional<V> operator()(SdfListOpType op, const V& value)
{
using namespace boost::python;

Expand All @@ -63,14 +63,14 @@ class Sdf_PyListEditorUtils {
if (! TfPyIsNone(result)) {
extract<V> e(result);
if (e.check()) {
return boost::optional<V>(e());
return std::optional<V>(e());
}
else {
TF_CODING_ERROR("ApplyEditsToList callback has "
"incorrect return type.");
}
}
return boost::optional<V>();
return std::optional<V>();
}

private:
Expand All @@ -87,7 +87,7 @@ class Sdf_PyListEditorUtils {
// Do nothing
}

boost::optional<V> operator()(const V& value)
std::optional<V> operator()(const V& value)
{
using namespace boost::python;

Expand All @@ -96,14 +96,14 @@ class Sdf_PyListEditorUtils {
if (! TfPyIsNone(result)) {
extract<V> e(result);
if (e.check()) {
return boost::optional<V>(e());
return std::optional<V>(e());
}
else {
TF_CODING_ERROR("ModifyItemEdits callback has "
"incorrect return type.");
}
}
return boost::optional<V>();
return std::optional<V>();
}

private:
Expand Down
2 changes: 1 addition & 1 deletion pxr/usd/sdf/pyListOp.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SdfPyWrapListOp {
}
static boost::python::object
_ApplyOperations2(const T& outer, const T& inner) {
if (boost::optional<T> r = outer.ApplyOperations(inner)) {
if (std::optional<T> r = outer.ApplyOperations(inner)) {
return boost::python::object(*r);
} else {
return boost::python::object();
Expand Down
Loading
Loading