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 
30 class XUSD_PathSet;
32 
33 class UT_WorkBuffer;
34 class HUSD_Path;
35 
36 /// This class is a "safe" wrapper around an XUSD_PathSet (which is itself a
37 /// wrapper around an SdfPathSet). This class provides a bunch of convenient
38 /// signatures for operating with HUSD_Path and UT_StringRef objects.
39 ///
40 /// The iterator implementation is fairly lacking, and only really useful
41 /// for simple walking through the set because of the need to hide the
42 /// SdfPathSet class and it's iterator class. So HUSD_PathSet::iterator
43 /// uses a void * that points to an SdfPathSet::iterator, but it allocates
44 /// that iterator with new(). So some nice APIs like "iterator erase(iterator)"
45 /// would be very inefficient with HUSD_PathSet::iterator, and so are not
46 /// implemented.
47 
49 {
50 public:
51  HUSD_PathSet();
53  HUSD_PathSet(const PXR_NS::XUSD_PathSet &src);
54  explicit HUSD_PathSet(std::initializer_list<HUSD_Path> init);
55  ~HUSD_PathSet();
56 
57  static const HUSD_PathSet &getEmptyPathSet();
58 
59  const HUSD_PathSet &operator=(const HUSD_PathSet &src);
60  bool operator==(const HUSD_PathSet &other) const;
61  bool operator!=(const HUSD_PathSet &other) const;
62  const HUSD_PathSet &operator=(const PXR_NS::XUSD_PathSet &src);
63  bool operator==(const PXR_NS::XUSD_PathSet
64  &other) const;
65  bool operator!=(const PXR_NS::XUSD_PathSet
66  &other) const;
67 
68  bool empty() const;
69  size_t size() const;
70  bool contains(const UT_StringRef &path) const;
71  bool contains(const HUSD_Path &path) const;
72  bool contains(const HUSD_PathSet &paths) const;
73  bool containsPathOrAncestor(const UT_StringRef &path) const;
74  bool containsPathOrAncestor(const HUSD_Path &path) const;
75  bool containsAncestor(const HUSD_Path &path) const;
76  bool containsPathOrDescendant(const UT_StringRef &path) const;
77  bool containsPathOrDescendant(const HUSD_Path &path) const;
78  bool containsDescendant(const HUSD_Path &path) const;
79  void clear();
80  void insert(const HUSD_PathSet &other);
81  bool insert(const HUSD_Path &path);
82  bool insert(const UT_StringRef &path);
83  void insert(const UT_StringArray &paths);
84  void erase(const HUSD_PathSet &other);
85  bool erase(const HUSD_Path &path);
86  bool erase(const UT_StringRef &path);
87  void erase(const UT_StringArray &paths);
88  void swap(HUSD_PathSet &other);
89 
90  // Remove all paths where an ancestor of the path is also in the set.
91  void removeDescendants();
92  // Remove all paths where a descendant of the path is also in the set.
93  void removeAncestors();
94 
95  PXR_NS::XUSD_PathSet &sdfPathSet()
96  { return *myPathSet; }
97  const PXR_NS::XUSD_PathSet &sdfPathSet() const
98  { return *myPathSet; }
99 
100  // Return a python object holding a set of SdfPath python objects.
101  void *getPythonPathList() const;
102  // Fill this path set from a python tuple of SdfPath python objects.
103  bool setPythonPaths(void *primpaths);
104 
105  // Fill a UT_StringArray or UT_StringSet with the paths in the SdfPathSet.
106  void getPathsAsStrings(UT_StringArray &paths) const;
107  void getPathsAsStrings(UT_StringSet &paths) const;
108  // Return the string representation of the first path in the set.
109  UT_StringHolder getFirstPathAsString() const;
110 
111  size_t getMemoryUsage() const;
112 
114  public:
115  iterator();
116  iterator(void *internal_iterator);
117  iterator(const iterator &src);
118  iterator(iterator &&src);
119  ~iterator();
120 
121  bool operator==(const iterator &other) const;
122  bool operator!=(const iterator &other) const;
123 
124  HUSD_Path operator*() const;
125  iterator &operator++();
126  iterator &operator=(const iterator &src);
127  iterator &operator=(iterator &&src);
128 
129  private:
130  void *myInternalIterator;
131  friend class HUSD_PathSet;
132  };
133 
134  iterator begin() const;
135  iterator end() const;
136 
137 private:
138  PXR_NS::XUSD_PathSet *myPathSet;
139 };
140 
141 #endif
142 
const PXR_NS::XUSD_PathSet & sdfPathSet() const
Definition: HUSD_PathSet.h:97
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:1441
PXR_NS::XUSD_PathSet & sdfPathSet()
Definition: HUSD_PathSet.h:95
#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:483