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 
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 
86  void erase(const HUSD_PathSet &other);
87  bool erase(const HUSD_Path &path);
88  bool erase(const UT_StringRef &path);
89  void erase(const UT_StringArray &paths);
90 
91  bool eraseWithDescendants(const HUSD_Path &path);
92  bool eraseWithDescendants(const UT_StringRef &path);
93  bool getDescendants(const HUSD_Path &path,
94  HUSD_PathSet &descendants) const;
95 
96  void clear();
97  void swap(HUSD_PathSet &other);
98 
99  // Remove all paths where an ancestor of the path is also in the set.
100  void removeDescendants();
101  // Remove all paths where a descendant of the path is also in the set.
102  void removeAncestors();
103 
104  PXR_NS::XUSD_PathSet &sdfPathSet()
105  { return *myPathSet; }
106  const PXR_NS::XUSD_PathSet &sdfPathSet() const
107  { return *myPathSet; }
108 
109  // Return a python object holding a set of SdfPath python objects.
110  void *getPythonPathList() const;
111  // Fill this path set from a python tuple of SdfPath python objects.
112  // Will throw an exception if the provided python object can't be
113  // converted to the data types we want.
114  void setPythonPaths(void *primpaths);
115 
116  // Fill a UT_StringArray or UT_StringSet with the paths in the SdfPathSet.
117  void getPathsAsStrings(UT_StringArray &paths) const;
118  void getPathsAsStrings(UT_StringSet &paths) const;
119  // Return the string representation of the first path in the set.
120  UT_StringHolder getFirstPathAsString() const;
121 
122  size_t getMemoryUsage() const;
123 
125  public:
126  iterator();
127  iterator(void *internal_iterator);
128  iterator(const iterator &src);
129  iterator(iterator &&src);
130  ~iterator();
131 
132  bool operator==(const iterator &other) const;
133  bool operator!=(const iterator &other) const;
134 
135  HUSD_Path operator*() const;
136  iterator &operator++();
137  iterator &operator=(const iterator &src);
138  iterator &operator=(iterator &&src);
139 
140  private:
141  void *myInternalIterator;
142  friend class HUSD_PathSet;
143  };
144 
145  iterator begin() const;
146  iterator end() const;
147  iterator find(const HUSD_Path &path) const;
148 
149  friend HUSD_API std::ostream &operator<<(std::ostream &os, const HUSD_PathSet &pathset);
150 
151 private:
152  PXR_NS::XUSD_PathSet *myPathSet;
153 };
154 
155 HUSD_API std::ostream &operator<<(std::ostream &os, const HUSD_PathSet &pathset);
156 
157 #endif
158 
const PXR_NS::XUSD_PathSet & sdfPathSet() const
Definition: HUSD_PathSet.h:106
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:31
void swap(T &lhs, T &rhs)
Definition: pugixml.cpp:7440
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2138
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3556
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:1425
LeafData & operator=(const LeafData &)=delete
PXR_NS::XUSD_PathSet & sdfPathSet()
Definition: HUSD_PathSet.h:104
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
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:566