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::iterator_adaptor with explicitly specified iterator definition for Usd_PrimData{Sibling,Subtree}Iterator #2235

Merged
merged 2 commits into from
Jul 27, 2023
Merged
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
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