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