24 #ifndef PXR_USD_SDF_CHILDREN_VIEW_H
25 #define PXR_USD_SDF_CHILDREN_VIEW_H
34 #include <hboost/iterator/filter_iterator.hpp>
35 #include <hboost/iterator/iterator_facade.hpp>
36 #include <hboost/iterator/reverse_iterator.hpp>
75 template <
typename _Owner,
typename _InnerIterator,
typename _DummyPredicate>
85 _Predicate() : _owner(NULL) { }
86 _Predicate(
const _Owner* owner) : _owner(owner) { }
90 return _owner->GetPredicate()(
91 _Owner::Adapter::Convert(x));
105 const _InnerIterator& i,
108 _InnerIterator
end(owner,size);
122 template <
typename _Owner,
typename _InnerIterator>
131 const _InnerIterator& i,
size_t size)
163 template <
typename _ChildPolicy,
164 typename _Predicate =
166 typename _ChildPolicy::ValueType>,
169 typename _ChildPolicy::ValueType> >
190 class _InnerIterator :
191 public hboost::iterator_facade<_InnerIterator,
193 std::random_access_iterator_tag,
201 _owner(NULL), _pos(0) { }
202 _InnerIterator(
const This* owner,
const size_t& pos) :
203 _owner(owner), _pos(pos) { }
206 friend class hboost::iterator_core_access;
208 reference dereference()
const
210 return _owner->_Get(_pos);
213 bool equal(
const _InnerIterator& other)
const
215 return _pos == other._pos;
231 return other._pos-_pos;
253 _children(layer, path, childrenKey, keyPolicy)
261 _children(layer, path, childrenKey, keyPolicy),
262 _predicate(predicate)
267 _children(other._children),
268 _predicate(other._predicate)
272 template <
class OtherAdapter>
274 OtherAdapter> &other) :
275 _children(other._children),
276 _predicate(other._predicate)
286 _children= other._children;
287 _predicate = other._predicate;
293 _InnerIterator i(
this,0);
299 _InnerIterator i(
this,_GetSize());
344 _InnerIterator inner(
this, _children.
Find(x));
358 return (i !=
end() && *i == x) ? i :
end();
368 return _children.
FindKey(Adapter::Convert(x));
373 return std::vector<value_type>(
begin(),
end());
377 template <
typename V>
385 std::vector<key_type>
keys()
const {
386 std::vector<key_type>
result;
387 result.reserve(
size());
389 result.push_back(
key(i));
395 template <
typename V>
397 std::vector<key_type> k =
keys();
398 return V(k.begin(), k.end());
402 template <
typename Dict>
406 result.insert(std::make_pair(
key(i), *i));
413 return (_children.
Find(x) != _GetSize());
419 return has(
key(Adapter::Convert(x)));
431 if (index == _GetSize()) {
441 if (index == _GetSize()) {
456 return _children.
IsEqualTo(other._children);
463 return !_children.
IsEqualTo(other._children);
484 return Adapter::Convert(_children.
GetChild(index));
488 size_t _GetSize()
const {
500 template <
class _View,
class _Adapter>
505 typename _View::Predicate,
515 template <
typename C,
typename P,
typename A>
519 template <
typename C,
typename P,
typename A>
526 template <
typename C,
typename P,
typename A>
536 #endif // PXR_USD_SDF_CHILDREN_VIEW_H
SDF_API bool IsEqualTo(const This &other) const
Return true if this object and other are equivalent.
Dict items_as() const
Returns the elements as a dictionary.
SDF_API size_t GetSize() const
Return the number of children that this object contains.
Sdf_Children< ChildPolicy > ChildrenType
SdfChildrenView(const SdfLayerHandle &layer, const SdfPath &path, const TfToken &childrenKey, const KeyPolicy &keyPolicy=KeyPolicy())
value_type back() const
Returns the last element.
SdfChildrenView< typename _View::ChildPolicy, typename _View::Predicate, _Adapter > AdaptedView
static IteratorType Begin(Type const &c)
OIIO_UTIL_API bool copy(string_view from, string_view to, std::string &err)
static const const_iterator & GetIterator(const _Owner *, const _InnerIterator &i, size_t size)
static const _InnerIterator & GetBase(const const_iterator &i)
ptrdiff_t difference_type
GLsizei const GLchar *const * path
_Traits::const_iterator const_iterator
ChildrenType & GetChildren()
static IteratorType End(Type const &c)
Type::const_reverse_iterator IteratorType
V values_as() const
Returns the elements, in order.
IMATH_HOSTDEVICE constexpr bool equal(T1 a, T2 b, T3 t) IMATH_NOEXCEPT
_InnerIterator const_iterator
**But if you need a result
bool empty() const
Returns true if the vector is empty.
bool has(const value_type &x) const
const_iterator begin() const
Returns an const_iterator pointing to the beginning of the vector.
SDF_API KeyType FindKey(const ValueType &value) const
Type::const_iterator IteratorType
static IteratorType End(Type const &c)
GLenum GLuint GLint GLint layer
V keys_as() const
Returns the keys for all elements, in order.
ChildPolicy::KeyType key_type
std::vector< value_type > values() const
Returns the elements, in order.
SdfChildrenView< C, P, A > Type
size_type size() const
Returns the size of the vector.
SdfChildrenView(const SdfChildrenView< ChildPolicy, Predicate, OtherAdapter > &other)
size_type count(const key_type &x) const
Returns the number of elements with key x in the container.
SDF_API ValueType GetChild(size_t index) const
Return the child at the specified index.
value_type front() const
Returns the first element.
const_iterator find(const value_type &x) const
Finds element x, if present in this view.
Adapter::PublicType value_type
SdfChildrenView & operator=(const SdfChildrenView &other)
static IteratorType Begin(Type const &c)
const_reverse_iterator rend() const
SdfChildrenView< _ChildPolicy, _Predicate, _Adapter > This
bool operator()(const T &x) const
key_type key(const value_type &x) const
Returns the key for a value.
SdfChildrenView< C, P, A > Type
hboost::filter_iterator< _Predicate, _InnerIterator > const_iterator
value_type operator[](size_type n) const
Returns the n'th element.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
bool has(const key_type &x) const
Returns true if an element with key x is in the container.
SdfChildrenView(const SdfLayerHandle &layer, const SdfPath &path, const TfToken &childrenKey, const Predicate &predicate, const KeyPolicy &keyPolicy=KeyPolicy())
key_type key(const const_iterator &x) const
Returns the key for an element.
value_type operator[](const key_type &x) const
static const PublicType & Convert(const PrivateType &t)
const Predicate & GetPredicate() const
#define PXR_NAMESPACE_CLOSE_SCOPE
static AdaptedView Create(const OriginalView &view)
static const _InnerIterator & GetBase(const const_iterator &i)
const_iterator end() const
Returns an const_iterator pointing to the end of the vector.
std::vector< key_type > keys() const
Returns the keys for all elements, in order.
hboost::reverse_iterator< const_iterator > const_reverse_iterator
static const_iterator GetIterator(const _Owner *owner, const _InnerIterator &i, size_t size)
const_reverse_iterator rbegin() const
SIM_API const UT_StringHolder distance
ChildPolicy::KeyPolicy KeyPolicy
bool operator==(const This &other) const
Sdf_ChildrenViewTraits< This, _InnerIterator, Predicate > _Traits
const_iterator find(const key_type &x) const
Finds the element with key x.
SDF_API bool IsValid() const
Return whether this object is valid.
bool operator!=(const This &other) const
SdfChildrenView(const SdfChildrenView &other)
SDF_API size_t Find(const KeyType &key) const
Find the index of the specified key, or return the size if it's not found.