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 PXR_USD_USD_COLLECTION_MEMBERSHIP_QUERY_H
25 #define PXR_USD_USD_COLLECTION_MEMBERSHIP_QUERY_H
26 
28 
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 
66  UsdCollectionMembershipQuery() = default;
67 
72  const PathExpansionRuleMap& pathExpansionRuleMap,
73  const SdfPathSet& includedCollections);
74 
77  PathExpansionRuleMap&& pathExpansionRuleMap,
78  SdfPathSet&& includedCollections);
79 
102  USD_API
103  bool IsPathIncluded(const SdfPath &path,
104  TfToken *expansionRule=nullptr) const;
105 
119  USD_API
120  bool IsPathIncluded(const SdfPath &path,
121  const TfToken &parentExpansionRule,
122  TfToken *expansionRule=nullptr) const;
123 
126  bool HasExcludes() const {
127  return _hasExcludes;
128  }
129 
131  bool operator==(UsdCollectionMembershipQuery const& rhs) const {
132  return _hasExcludes == rhs._hasExcludes &&
133  _pathExpansionRuleMap == rhs._pathExpansionRuleMap &&
134  _includedCollections == rhs._includedCollections;
135  }
136 
138  bool operator!=(UsdCollectionMembershipQuery const& rhs) const {
139  return !(*this == rhs);
140  }
141 
143  struct Hash {
144  USD_API
145  size_t operator()(UsdCollectionMembershipQuery const& query) const;
146  };
147 
149  inline size_t GetHash() const {
150  return Hash()(*this);
151  }
152 
157  return _pathExpansionRuleMap;
158  }
159 
166  const SdfPathSet& GetIncludedCollections() const {
167  return _includedCollections;
168  }
169 
170 private:
171  PathExpansionRuleMap _pathExpansionRuleMap;
172 
173  SdfPathSet _includedCollections;
174 
175  // A cached flag indicating whether _pathExpansionRuleMap contains
176  // any exclude rules.
177  bool _hasExcludes=false;
178 };
179 
185 USD_API
186 std::set<UsdObject> UsdComputeIncludedObjectsFromCollection(
187  const UsdCollectionMembershipQuery &query,
188  const UsdStageWeakPtr &stage,
189  const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate);
190 
196 USD_API
198  const UsdCollectionMembershipQuery &query,
199  const UsdStageWeakPtr &stage,
200  const Usd_PrimFlagsPredicate &pred=UsdPrimDefaultPredicate);
201 
202 PXR_NAMESPACE_CLOSE_SCOPE
203 
204 #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,...
Standard pointer typedefs.
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...
const PathExpansionRuleMap & GetAsPathExpansionRuleMap() const
Returns a raw map of the paths included or excluded in the collection along with the expansion rules ...
Represents a flattened view of a collection.
UsdCollectionMembershipQuery()=default
Default Constructor, creates an empty UsdCollectionMembershipQuery object.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
size_t GetHash() const
Hash function.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
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...
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.
const SdfPathSet & GetIncludedCollections() const
Returns a set of paths for all collections that were included in the collection from which this UsdCo...
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...