Skip to content

Commit

Permalink
Merge pull request #2701 from nvmkuruc/tfpyenumordered
Browse files Browse the repository at this point in the history
Replace `boost::totally_ordered` and `boost::equality_comparable` in python bindings

(Internal change: 2297904)
  • Loading branch information
pixar-oss committed Oct 26, 2023
2 parents 8bef6d2 + dd3d97c commit 544f157
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
16 changes: 13 additions & 3 deletions pxr/base/tf/pyAnnotatedBoolResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "pxr/base/tf/pyLock.h"
#include "pxr/base/tf/pyUtils.h"

#include <boost/operators.hpp>
#include <boost/python/class.hpp>
#include <boost/python/operators.hpp>
#include <boost/python/return_by_value.hpp>
Expand All @@ -39,8 +38,7 @@
PXR_NAMESPACE_OPEN_SCOPE

template <class Annotation>
struct TfPyAnnotatedBoolResult :
boost::equality_comparable<TfPyAnnotatedBoolResult<Annotation>, bool>
struct TfPyAnnotatedBoolResult
{
TfPyAnnotatedBoolResult() {}

Expand All @@ -65,6 +63,18 @@ struct TfPyAnnotatedBoolResult :
return _val == rhs;
}

friend bool operator==(bool lhs, const TfPyAnnotatedBoolResult& rhs) {
return rhs == lhs;
}

friend bool operator!=(const TfPyAnnotatedBoolResult& lhs, bool rhs) {
return !(lhs == rhs);
}

friend bool operator!=(bool lhs, const TfPyAnnotatedBoolResult& rhs) {
return !(lhs == rhs);
}

template <class Derived>
static boost::python::class_<Derived>
Wrap(char const *name, char const *annotationName) {
Expand Down
28 changes: 25 additions & 3 deletions pxr/base/tf/pyEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ std::string Tf_PyEnumRepr(boost::python::object const &self);

// Private base class for types which are instantiated and exposed to python
// for each registered enum type.
struct Tf_PyEnumWrapper
: public Tf_PyEnum, boost::totally_ordered<Tf_PyEnumWrapper>
struct Tf_PyEnumWrapper : public Tf_PyEnum
{
typedef Tf_PyEnumWrapper This;

Expand Down Expand Up @@ -197,6 +196,11 @@ struct Tf_PyEnumWrapper
return lhs.value == rhs.value;
}

friend bool operator !=(Tf_PyEnumWrapper const &lhs,
Tf_PyEnumWrapper const &rhs) {
return !(lhs == rhs);
}

friend bool operator <(Tf_PyEnumWrapper const &lhs,
Tf_PyEnumWrapper const &rhs)
{
Expand All @@ -210,7 +214,25 @@ struct Tf_PyEnumWrapper
// If types do match, numerically compare values.
return lhs.GetValue() < rhs.GetValue();
}


friend bool operator >(Tf_PyEnumWrapper const& lhs,
Tf_PyEnumWrapper const& rhs)
{
return rhs < lhs;
}

friend bool operator <=(Tf_PyEnumWrapper const& lhs,
Tf_PyEnumWrapper const& rhs)
{
return !(lhs > rhs);
}

friend bool operator >=(Tf_PyEnumWrapper const& lhs,
Tf_PyEnumWrapper const& rhs)
{
return !(lhs < rhs);
}

//
// XXX Bitwise operators for Enums are a temporary measure to support the
// use of Enums as Bitmasks in libSd. It should be noted that Enums are
Expand Down

0 comments on commit 544f157

Please sign in to comment.