Skip to content

Commit

Permalink
Merge pull request #2235 from nvmkuruc/usdprimdataadaptor
Browse files Browse the repository at this point in the history
Replace `boost::iterator_adaptor` with explicitly specified iterator definition for `Usd_PrimData{Sibling,Subtree}Iterator`

(Internal change: 2286217)
  • Loading branch information
pixar-oss committed Jul 26, 2023
2 parents 56abb0b + 3594c42 commit 40f0551
Showing 1 changed file with 76 additions and 32 deletions.
108 changes: 76 additions & 32 deletions pxr/usd/usd/primData.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include "pxr/usd/sdf/path.h"

#include <boost/range/iterator_range.hpp>
#include <boost/iterator/iterator_adaptor.hpp>
#include <boost/intrusive_ptr.hpp>

#include <atomic>
Expand Down Expand Up @@ -353,31 +352,53 @@ class Usd_PrimData
};

// Sibling iterator class.
class Usd_PrimDataSiblingIterator : public boost::iterator_adaptor<
Usd_PrimDataSiblingIterator, // crtp.
Usd_PrimData *, // base iterator.
Usd_PrimData *, // value.
boost::forward_traversal_tag, // traversal.
Usd_PrimData * // reference.
>
{
class Usd_PrimDataSiblingIterator {
using _UnderylingIterator = Usd_PrimData*;
public:
using iterator_category = std::forward_iterator_tag;
using value_type = Usd_PrimData*;
using reference = Usd_PrimData*;
using pointer = void;
using difference_type = std::ptrdiff_t;

// Default ctor.
Usd_PrimDataSiblingIterator() {}
Usd_PrimDataSiblingIterator() = default;

reference operator*() const { return _underlyingIterator; }

// pre-increment
Usd_PrimDataSiblingIterator& operator++() {
increment();
return *this;
}

// post-increment
Usd_PrimDataSiblingIterator operator++(int) {
Usd_PrimDataSiblingIterator result = *this;
increment();
return result;
}

bool operator==(const Usd_PrimDataSiblingIterator& other) const {
return _underlyingIterator == other._underlyingIterator;
}

bool operator!=(const Usd_PrimDataSiblingIterator& other) const {
return _underlyingIterator != other._underlyingIterator;
}

private:
friend class Usd_PrimData;

// Constructor used by Prim.
Usd_PrimDataSiblingIterator(const base_type &i)
: iterator_adaptor_(i) {}
Usd_PrimDataSiblingIterator(const _UnderylingIterator &i)
: _underlyingIterator(i) {}

// Core primitives implementation.
friend class boost::iterator_core_access;
reference dereference() const { return base(); }
void increment() {
base_reference() = base_reference()->GetNextSibling();
_underlyingIterator = _underlyingIterator->GetNextSibling();
}

_UnderylingIterator _underlyingIterator = nullptr;
};

// Sibling range.
Expand Down Expand Up @@ -412,33 +433,56 @@ Usd_PrimData::_GetChildrenRange() const


// Tree iterator class.
class Usd_PrimDataSubtreeIterator : public boost::iterator_adaptor<
Usd_PrimDataSubtreeIterator, // crtp.
Usd_PrimData *, // base iterator.
Usd_PrimData *, // value.
boost::forward_traversal_tag, // traversal.
Usd_PrimData * // reference.
>
{
class Usd_PrimDataSubtreeIterator {
using _UnderlyingIterator = Usd_PrimData*;
public:
using iterator_category = std::forward_iterator_tag;
using value_type = Usd_PrimData*;
using reference = Usd_PrimData*;
using pointer = void;
using difference_type = std::ptrdiff_t;

// Default ctor.
Usd_PrimDataSubtreeIterator() {}
Usd_PrimDataSubtreeIterator() = default;

reference operator*() const { return _underlyingIterator; }

// pre-increment
Usd_PrimDataSubtreeIterator& operator++() {
increment();
return *this;
}

// post-increment
Usd_PrimDataSubtreeIterator operator++(int) {
Usd_PrimDataSubtreeIterator result = *this;
increment();
return result;
}

bool operator==(const Usd_PrimDataSubtreeIterator& other) const {
return _underlyingIterator == other._underlyingIterator;
}

bool operator!=(const Usd_PrimDataSubtreeIterator& other) const {
return _underlyingIterator != other._underlyingIterator;
}

private:
friend class Usd_PrimData;
friend class UsdPrimSubtreeIterator;

// Constructor used by Prim.
Usd_PrimDataSubtreeIterator(const base_type &i)
: iterator_adaptor_(i) {}
Usd_PrimDataSubtreeIterator(const _UnderlyingIterator &i)
: _underlyingIterator(i) {}

// Core primitives implementation.
friend class boost::iterator_core_access;
reference dereference() const { return base(); }
void increment() {
base_type &b = base_reference();
b = b->GetFirstChild() ? b->GetFirstChild() : b->GetNextPrim();
_underlyingIterator = _underlyingIterator->GetFirstChild() ?
_underlyingIterator->GetFirstChild() :
_underlyingIterator->GetNextPrim();
}

_UnderlyingIterator _underlyingIterator = nullptr;
};

// Tree range.
Expand Down

0 comments on commit 40f0551

Please sign in to comment.