Skip to content

Commit

Permalink
Merge pull request #2237 from nvmkuruc/sdfequality
Browse files Browse the repository at this point in the history
Replace `boost::equality_comparable` with explicit implementation of `operator!=` in `pxr/usd/sdf`

(Internal change: 2282037)
  • Loading branch information
pixar-oss committed Jun 20, 2023
2 parents cd33bd6 + b43f828 commit cf002e9
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 13 deletions.
8 changes: 6 additions & 2 deletions pxr/usd/sdf/allowed.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include <string>
#include <utility>
#include <boost/operators.hpp>
#include <boost/optional.hpp>

PXR_NAMESPACE_OPEN_SCOPE
Expand All @@ -44,7 +43,7 @@ PXR_NAMESPACE_OPEN_SCOPE
/// A \c SdfAllowed either evaluates to \c true in a boolean context
/// or evaluates to \c false and has a string annotation.
///
class SdfAllowed : private boost::equality_comparable<SdfAllowed> {
class SdfAllowed {
private:
typedef boost::optional<std::string> _State;

Expand Down Expand Up @@ -113,6 +112,11 @@ class SdfAllowed : private boost::equality_comparable<SdfAllowed> {
return _state == other._state;
}

bool operator!=(const SdfAllowed& other) const
{
return !(*this == other);
}

private:
_State _state;
};
Expand Down
8 changes: 6 additions & 2 deletions pxr/usd/sdf/childrenProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@

#include <boost/iterator/iterator_facade.hpp>
#include <boost/iterator/reverse_iterator.hpp>
#include <boost/operators.hpp>
#include <iterator>
#include <map>
#include <utility>

PXR_NAMESPACE_OPEN_SCOPE

template <class _View>
class SdfChildrenProxy : boost::equality_comparable<SdfChildrenProxy<_View> > {
class SdfChildrenProxy {
public:
typedef _View View;
typedef typename View::Adapter Adapter;
Expand Down Expand Up @@ -353,6 +352,11 @@ class SdfChildrenProxy : boost::equality_comparable<SdfChildrenProxy<_View> > {
return _view == other._view;
}

bool operator!=(const This& other) const
{
return !(*this == other);
}

/// Explicit bool conversion operator. The proxy object converts to
/// \c true if it is valid, \c false otherwise.
explicit operator bool() const
Expand Down
12 changes: 12 additions & 0 deletions pxr/usd/sdf/namespaceEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ SdfNamespaceEdit::operator==(const SdfNamespaceEdit& rhs) const
index == rhs.index;
}

bool
SdfNamespaceEdit::operator!=(const SdfNamespaceEdit& rhs) const
{
return !(*this == rhs);
}

std::ostream&
operator<<(std::ostream& s, const SdfNamespaceEdit& x)
{
Expand Down Expand Up @@ -715,6 +721,12 @@ SdfNamespaceEditDetail::operator==(const SdfNamespaceEditDetail& rhs) const
reason == rhs.reason;
}

bool
SdfNamespaceEditDetail::operator!=(const SdfNamespaceEditDetail& rhs) const
{
return !(*this == rhs);
}

std::ostream&
operator<<(std::ostream& s, const SdfNamespaceEditDetail& x)
{
Expand Down
10 changes: 4 additions & 6 deletions pxr/usd/sdf/namespaceEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@
#include "pxr/usd/sdf/api.h"
#include "pxr/usd/sdf/path.h"

#include <boost/operators.hpp>

#include <functional>
#include <iosfwd>
#include <string>
Expand All @@ -44,8 +42,7 @@ PXR_NAMESPACE_OPEN_SCOPE
/// A single namespace edit. It supports renaming, reparenting, reparenting
/// with a rename, reordering, and removal.
///
struct SdfNamespaceEdit :
boost::equality_comparable<SdfNamespaceEdit> {
struct SdfNamespaceEdit {
public:
typedef SdfNamespaceEdit This;
typedef SdfPath Path;
Expand Down Expand Up @@ -114,6 +111,7 @@ struct SdfNamespaceEdit :
}

SDF_API bool operator==(const This& rhs) const;
SDF_API bool operator!=(const This& rhs) const;

public:
Path currentPath; ///< Path of the object when this edit starts.
Expand All @@ -131,8 +129,7 @@ SDF_API std::ostream& operator<<(std::ostream&, const SdfNamespaceEditVector&);
///
/// Detailed information about a namespace edit.
///
struct SdfNamespaceEditDetail :
boost::equality_comparable<SdfNamespaceEditDetail> {
struct SdfNamespaceEditDetail {
public:
/// Validity of an edit.
enum Result {
Expand All @@ -146,6 +143,7 @@ struct SdfNamespaceEditDetail :
const std::string& reason);

SDF_API bool operator==(const SdfNamespaceEditDetail& rhs) const;
SDF_API bool operator!=(const SdfNamespaceEditDetail& rhs) const;

public:
Result result; ///< Validity.
Expand Down
29 changes: 29 additions & 0 deletions pxr/usd/sdf/testenv/testSdfBatchNamespaceEdit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,35 @@
#verbose = True

class TestSdfBatchNamespaceEdit(unittest.TestCase):
def test_EqualityOperators(self):
self.assertEqual(Sdf.NamespaceEdit('/A', '/B'), Sdf.NamespaceEdit('/A', '/B'))
self.assertNotEqual(Sdf.NamespaceEdit('/B', '/A'), Sdf.NamespaceEdit('/A', '/B'))

# Validate the equality operators by varying a single field from a prototype edit
# at a time
prototype = Sdf.NamespaceEditDetail(
Sdf.NamespaceEditDetail.Okay,
Sdf.NamespaceEdit('/A', '/B'),
"reason"
)
self.assertEqual(prototype, Sdf.NamespaceEditDetail(
prototype.result,
prototype.edit,
prototype.reason))
self.assertNotEqual(prototype, Sdf.NamespaceEditDetail(
Sdf.NamespaceEditDetail.Unbatched,
prototype.edit,
prototype.reason))
self.assertNotEqual(prototype, Sdf.NamespaceEditDetail(
prototype.result,
Sdf.NamespaceEdit('/C', '/D'),
prototype.reason))
self.assertNotEqual(prototype, Sdf.NamespaceEditDetail(
prototype.result,
prototype.edit,
"a different reason"))


def test_Basic(self):
print('Test constructors')

Expand Down
8 changes: 7 additions & 1 deletion pxr/usd/sdf/testenv/testSdfTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,12 @@ def _TestValueTypeName(attrPath, expectedValueTypeName):

def test_Hash(self):
self.assertEqual(hash(Sdf.ValueTypeNames.Point3d), hash(Sdf.ValueTypeNames.Point3d))


def test_UnregisteredValueEquality(self):
self.assertEqual(Sdf.UnregisteredValue(str(5)),
Sdf.UnregisteredValue(str(5)))
self.assertNotEqual(Sdf.UnregisteredValue(str(5)),
Sdf.UnregisteredValue(str(6)))

if __name__ == "__main__":
unittest.main()
5 changes: 5 additions & 0 deletions pxr/usd/sdf/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ bool SdfUnregisteredValue::operator==(const SdfUnregisteredValue &other) const
return _value == other._value;
}

bool SdfUnregisteredValue::operator!=(const SdfUnregisteredValue &other) const
{
return !(*this == other);
}

std::ostream &operator << (std::ostream &out, const SdfUnregisteredValue &value)
{
return out << value.GetValue();
Expand Down
6 changes: 4 additions & 2 deletions pxr/usd/sdf/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,7 @@ std::ostream &VtStreamOut(const SdfVariantSelectionMap &, std::ostream &);
/// well as limited inspection and editing capabilities (e.g., moving
/// this data to a different spec or field) even when the data type
/// of the value isn't known.
class SdfUnregisteredValue :
public boost::equality_comparable<SdfUnregisteredValue>
class SdfUnregisteredValue
{
public:
/// Wraps an empty VtValue
Expand Down Expand Up @@ -513,6 +512,9 @@ class SdfUnregisteredValue :
/// Returns true if the wrapped VtValues are equal
SDF_API bool operator==(const SdfUnregisteredValue &other) const;

/// Returns true if the wrapped VtValues are not equal
SDF_API bool operator!=(const SdfUnregisteredValue &other) const;

private:
VtValue _value;
};
Expand Down

0 comments on commit cf002e9

Please sign in to comment.