HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HUSD_PathSet.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Side Effects Software Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 
18 #ifndef __HUSD_PathSet_h__
19 #define __HUSD_PathSet_h__
20 
21 #include "HUSD_API.h"
22 #include <UT/UT_StringArray.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_StringSet.h>
25 #include <pxr/pxr.h>
26 #include <initializer_list>
27 #include <stddef.h>
28 #include <iosfwd>
29 
31 class XUSD_PathSet;
33 
34 class UT_WorkBuffer;
35 class HUSD_Path;
36 
37 /// This class is a "safe" wrapper around an XUSD_PathSet (which is itself a
38 /// wrapper around an SdfPathSet). This class provides a bunch of convenient
39 /// signatures for operating with HUSD_Path and UT_StringRef objects.
40 ///
41 /// The iterator implementation is fairly lacking, and only really useful
42 /// for simple walking through the set because of the need to hide the
43 /// SdfPathSet class and it's iterator class. So HUSD_PathSet::iterator
44 /// uses a void * that points to an SdfPathSet::iterator, but it allocates
45 /// that iterator with new(). So some nice APIs like "iterator erase(iterator)"
46 /// would be very inefficient with HUSD_PathSet::iterator, and so are not
47 /// implemented.
48 
50 {
51 public:
52  HUSD_PathSet();
54  HUSD_PathSet(const PXR_NS::XUSD_PathSet &src);
55  explicit HUSD_PathSet(std::initializer_list<HUSD_Path> init);
56  ~HUSD_PathSet();
57 
58  static const HUSD_PathSet &getEmptyPathSet();
59 
60  const HUSD_PathSet &operator=(const HUSD_PathSet &src);
61  bool operator==(const HUSD_PathSet &other) const;
62  bool operator!=(const HUSD_PathSet &other) const;
63  const HUSD_PathSet &operator=(const PXR_NS::XUSD_PathSet &src);
64  bool operator==(const PXR_NS::XUSD_PathSet
65  &other) const;
66  bool operator!=(const PXR_NS::XUSD_PathSet
67  &other) const;
68 
69  bool empty() const;
70  size_t size() const;
71  bool contains(const UT_StringRef &path) const;
72  bool contains(const HUSD_Path &path) const;
73  bool contains(const HUSD_PathSet &paths) const;
74  bool containsPathOrAncestor(const UT_StringRef &path) const;
75  bool containsPathOrAncestor(const HUSD_Path &path) const;
76  bool containsAncestor(const HUSD_Path &path) const;
77  bool containsPathOrDescendant(const UT_StringRef &path) const;
78  bool containsPathOrDescendant(const HUSD_Path &path) const;
79  bool containsDescendant(const HUSD_Path &path) const;
80  void clear();
81  void insert(const HUSD_PathSet &other);
82  bool insert(const HUSD_Path &path);
83  bool insert(const UT_StringRef &path);
84  void insert(const UT_StringArray &paths);
85  void erase(const HUSD_PathSet &other);
86  bool erase(const HUSD_Path &path);
87  bool erase(const UT_StringRef &path);
88  void erase(const UT_StringArray &paths);
89  void swap(HUSD_PathSet &other);
90 
91  // Remove all paths where an ancestor of the path is also in the set.
92  void removeDescendants();
93  // Remove all paths where a descendant of the path is also in the set.
94  void removeAncestors();
95 
96  PXR_NS::XUSD_PathSet &sdfPathSet()
97  { return *myPathSet; }
98  const PXR_NS::XUSD_PathSet &sdfPathSet() const
99  { return *myPathSet; }
100 
101  // Return a python object holding a set of SdfPath python objects.
102  void *getPythonPathList() const;
103  // Fill this path set from a python tuple of SdfPath python objects.
104  bool setPythonPaths(void *primpaths);
105 
106  // Fill a UT_StringArray or UT_StringSet with the paths in the SdfPathSet.
107  void getPathsAsStrings(UT_StringArray &paths) const;
108  void getPathsAsStrings(UT_StringSet &paths) const;
109  // Return the string representation of the first path in the set.
110  UT_StringHolder getFirstPathAsString() const;
111 
112  size_t getMemoryUsage() const;
113 
115  public:
116  iterator();
117  iterator(void *internal_iterator);
118  iterator(const iterator &src);
119  iterator(iterator &&src);
120  ~iterator();
121 
122  bool operator==(const iterator &other) const;
123  bool operator!=(const iterator &other) const;
124 
125  HUSD_Path operator*() const;
126  iterator &operator++();
127  iterator &operator=(const iterator &src);
128  iterator &operator=(iterator &&src);
129 
130  private:
131  void *myInternalIterator;
132  friend class HUSD_PathSet;
133  };
134 
135  iterator begin() const;
136  iterator end() const;
137 
138  friend HUSD_API std::ostream &operator<<(std::ostream &os, const HUSD_PathSet &pathset);
139 
140 private:
141  PXR_NS::XUSD_PathSet *myPathSet;
142 };
143 
144 HUSD_API std::ostream &operator<<(std::ostream &os, const HUSD_PathSet &pathset);
145 
146 #endif
147 
const PXR_NS::XUSD_PathSet & sdfPathSet() const
Definition: HUSD_PathSet.h:98
HUSD_API std::ostream & operator<<(std::ostream &os, const HUSD_PathSet &pathset)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
#define HUSD_API
Definition: HUSD_API.h:32
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7172
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3436
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
GLuint GLuint end
Definition: glcorearb.h:475
IMATH_HOSTDEVICE constexpr Color4< T > operator*(S a, const Color4< T > &v) IMATH_NOEXCEPT
Reverse multiplication: S * Color4.
Definition: ImathColor.h:732
GLsizeiptr size
Definition: glcorearb.h:664
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
LeafData & operator=(const LeafData &)=delete
PXR_NS::XUSD_PathSet & sdfPathSet()
Definition: HUSD_PathSet.h:96
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
bool OIIO_UTIL_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
GLenum src
Definition: glcorearb.h:1793
PcpNodeRef_ChildrenIterator begin(const PcpNodeRef::child_const_range &r)
Support for range-based for loops for PcpNodeRef children ranges.
Definition: node.h:558