All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
collectionMembershipQuery.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef USD_COLLECTIONMEMBERSHIPQUERY_H
25 #define USD_COLLECTIONMEMBERSHIPQUERY_H
26 
28 
29 #include "pxr/base/tf/declarePtrs.h"
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdf/path.h"
32 #include "pxr/usd/usd/common.h"
33 #include "pxr/usd/usd/primFlags.h"
34 
35 #include <unordered_map>
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 // -------------------------------------------------------------------------- //
40 // UsdCollectionMembershipQuery //
41 // -------------------------------------------------------------------------- //
50 {
51 public:
61  using PathExpansionRuleMap = std::unordered_map<SdfPath,
62  TfToken, SdfPath::Hash>;
63 
67 
72  const PathExpansionRuleMap& pathExpansionRuleMap);
73 
76  PathExpansionRuleMap&& pathExpansionRuleMap);
77 
100  USD_API
101  bool IsPathIncluded(const SdfPath &path,
102  TfToken *expansionRule=nullptr) const;
103 
117  USD_API
118  bool IsPathIncluded(const SdfPath &path,
119  const TfToken &parentExpansionRule,
120  TfToken *expansionRule=nullptr) const;
121 
124  bool HasExcludes() const {
125  return _hasExcludes;
126  }
127 
129  bool operator==(UsdCollectionMembershipQuery const& rhs) const {
130  return _hasExcludes == rhs._hasExcludes &&
131  _pathExpansionRuleMap == rhs._pathExpansionRuleMap;
132  }
133 
135  bool operator!=(UsdCollectionMembershipQuery const& rhs) const {
136  return !(*this == rhs);
137  }
138 
140  struct Hash {
141  USD_API
142  size_t operator()(UsdCollectionMembershipQuery const& query) const;
143  };
144 
146  inline size_t GetHash() const {
147  return Hash()(*this);
148  }
149 
154  return _pathExpansionRuleMap;
155  }
156 
157 private:
158  PathExpansionRuleMap _pathExpansionRuleMap;
159 
160  // A cached flag indicating whether _pathExpansionRuleMap contains
161  // any exclude rules.
162  bool _hasExcludes=false;
163 };
164 
170 USD_API
171 std::set<UsdObject> UsdComputeIncludedObjectsFromCollection(
172  const UsdCollectionMembershipQuery &query,
173  const UsdStageWeakPtr &stage,
174  const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate);
175 
181 USD_API
183  const UsdCollectionMembershipQuery &query,
184  const UsdStageWeakPtr &stage,
185  const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate);
186 
187 PXR_NAMESPACE_CLOSE_SCOPE
188 
189 #endif
std::unordered_map< SdfPath, TfToken, SdfPath::Hash > PathExpansionRuleMap
Holds an unordered map describing membership of paths in this collection and the associated expansion...
unspecified UsdPrimDefaultPredicate
The default predicate used for prim traversals in methods like UsdPrim::GetChildren, UsdStage::Traverse, and by UsdPrimRange.
USD_API std::set< UsdObject > UsdComputeIncludedObjectsFromCollection(const UsdCollectionMembershipQuery &query, const UsdStageWeakPtr &stage, const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate)
Returns all the usd objects that satisfy the predicate, pred in the collection represented by the Usd...
UsdCollectionMembershipQuery()
Default Constructor, creates an empty UsdCollectionMembershipQuery object.
const PathExpansionRuleMap & GetAsPathExpansionRuleMap() const
Returns a raw map of the paths included or excluded in the collection along with the expansion rules ...
USD_API bool IsPathIncluded(const SdfPath &path, TfToken *expansionRule=nullptr) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Represents a flattened view of a collection.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
size_t GetHash() const
Hash function.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:287
bool HasExcludes() const
Returns true if the collection excludes one or more paths below an included path. ...
bool operator==(UsdCollectionMembershipQuery const &rhs) const
Equality operator.
bool operator!=(UsdCollectionMembershipQuery const &rhs) const
Inequality operator.
USD_API SdfPathSet UsdComputeIncludedPathsFromCollection(const UsdCollectionMembershipQuery &query, const UsdStageWeakPtr &stage, const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate)
Returns all the paths that satisfy the predicate, pred in the collection represented by the UsdCollec...