HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
stageLoadRules.h
Go to the documentation of this file.
1 //
2 // Copyright 2019 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 
8 #ifndef PXR_USD_USD_STAGE_LOAD_RULES_H
9 #define PXR_USD_USD_STAGE_LOAD_RULES_H
10 
11 /// \file usd/stageLoadRules.h
12 
13 #include "pxr/pxr.h"
14 #include "pxr/usd/usd/api.h"
15 #include "pxr/usd/usd/common.h"
16 #include "pxr/usd/sdf/path.h"
17 
18 #include <iosfwd>
19 #include <vector>
20 
22 
23 /// \class UsdStageLoadRules
24 ///
25 /// This class represents rules that govern payload inclusion on UsdStages.
26 ///
27 /// Rules are represented as pairs of SdfPath and a Rule enum value, one of
28 /// AllRule, OnlyRule, and NoneRule. To understand how rules apply to
29 /// particular paths, see UsdStageLoadRules::GetEffectiveRuleForPath().
30 ///
31 /// Convenience methods for manipulating rules by typical 'Load' and 'Unload'
32 /// operations are provided in UsdStageLoadRules::LoadWithoutDescendants(),
33 /// UsdStageLoadRules::LoadWithDescendants(), UsdStageLoadRules::Unload().
34 ///
35 /// For finer-grained rule crafting, see AddRule().
36 ///
37 /// Remove redundant rules that do not change the effective load state with
38 /// UsdStageLoadRules::Minimize().
40 {
41 public:
42  /// \enum Rule
43  ///
44  /// These values are paired with paths to govern payload inclusion on
45  /// UsdStages.
46  enum Rule {
47  /// Include payloads on the specified prim and all descendants.
49  /// Include payloads on the specified prim but no descendants.
51  /// Exclude payloads on the specified prim and all descendants.
53  };
54 
55  /// Construct rules that load all payloads.
56  UsdStageLoadRules() = default;
57 
58  /// Return rules that load all payloads. This is equivalent to
59  /// default-constructed UsdStageLoadRules.
60  static inline UsdStageLoadRules LoadAll() {
61  return UsdStageLoadRules();
62  }
63 
64  /// Return rules that load no payloads.
65  USD_API
66  static UsdStageLoadRules LoadNone();
67 
68  UsdStageLoadRules(UsdStageLoadRules const &) = default;
70  UsdStageLoadRules &operator=(UsdStageLoadRules const &) = default;
72 
73  /// Add a rule indicating that \p path, all its ancestors, and all its
74  /// descendants shall be loaded.
75  ///
76  /// Any previous rules created by calling LoadWithoutDescendants() or
77  /// Unload() on this path or descendant paths are replaced by this rule.
78  /// For example, calling LoadWithoutDescendants('/World/sets/kitchen')
79  /// followed by LoadWithDescendants('/World/sets') will effectively remove
80  /// the rule created in the first call. See AddRule() for more direct
81  /// manipulation.
82  USD_API
83  void LoadWithDescendants(SdfPath const &path);
84 
85  /// Add a rule indicating that \p path and all its ancestors but none of its
86  /// descendants shall be loaded.
87  ///
88  /// Any previous rules created by calling LoadWithDescendants() or Unload()
89  /// on this path or descendant paths are replaced or restricted by this
90  /// rule. For example, calling LoadWithDescendants('/World/sets') followed
91  /// by LoadWithoutDescendants('/World/sets/kitchen') will cause everything
92  /// under '/World/sets' to load except for those things under
93  /// '/World/sets/kitchen'. See AddRule() for more direct manipulation.
94  USD_API
95  void LoadWithoutDescendants(SdfPath const &path);
96 
97  /// Add a rule indicating that \p path and all its descendants shall be
98  /// unloaded.
99  ///
100  /// Any previous rules created by calling LoadWithDescendants() or
101  /// LoadWithoutDescendants() on this path or descendant paths are replaced
102  /// or restricted by this rule. For example, calling
103  /// LoadWithDescendants('/World/sets') followed by
104  /// Unload('/World/sets/kitchen') will cause everything under '/World/sets'
105  /// to load, except for '/World/sets/kitchen' and everything under it.
106  USD_API
107  void Unload(SdfPath const &path);
108 
109  /// Add rules as if Unload() was called for each element of \p unloadSet
110  /// followed by calls to either LoadWithDescendants() (if \p policy is
111  /// UsdLoadPolicy::LoadWithDescendants) or LoadWithoutDescendants() (if
112  /// \p policy is UsdLoadPolicy::LoadWithoutDescendants) for each element of
113  /// \p loadSet.
114  USD_API
115  void LoadAndUnload(const SdfPathSet &loadSet,
116  const SdfPathSet &unloadSet, UsdLoadPolicy policy);
117 
118  /// Add a literal rule. If there's already a rule for \p path, replace it.
119  USD_API
120  void AddRule(SdfPath const &path, Rule rule);
121 
122  /// Set literal rules, must be sorted by SdfPath::operator<.
123  USD_API
124  void SetRules(std::vector<std::pair<SdfPath, Rule>> const &rules);
125 
126  /// Set literal rules, must be sorted by SdfPath::operator<.
127  inline void SetRules(std::vector<std::pair<SdfPath, Rule>> &&rules) {
128  _rules = std::move(rules);
129  }
130 
131  /// Remove any redundant rules to make the set of rules as small as possible
132  /// without changing behavior.
133  USD_API
134  void Minimize();
135 
136  /// Return true if the given \p path is considered loaded by these rules, or
137  /// false if it is considered unloaded. This is equivalent to
138  /// GetEffectiveRuleForPath(path) != NoneRule.
139  USD_API
140  bool IsLoaded(SdfPath const &path) const;
141 
142  /// Return true if the given \p path and all descendants are considered
143  /// loaded by these rules; false otherwise.
144  USD_API
145  bool IsLoadedWithAllDescendants(SdfPath const &path) const;
146 
147  /// Return true if the given \p path and is considered loaded, but none of
148  /// its descendants are considered loaded by these rules; false otherwise.
149  USD_API
150  bool IsLoadedWithNoDescendants(SdfPath const &path) const;
151 
152  /// Return the "effective" rule for the given \p path. For example, if the
153  /// closest ancestral rule of \p path is an \p AllRule, return \p AllRule.
154  /// If the closest ancestral rule of \p path is for \p path itself and it is
155  /// an \p OnlyRule, return \p OnlyRule. Otherwise if there is a closest
156  /// descendant rule to \p path this is an \p OnlyRule or an \p AllRule,
157  /// return \p OnlyRule. Otherwise return \p NoneRule.
158  USD_API
160 
161  /// Return all the rules as a vector.
162  inline std::vector<std::pair<SdfPath, Rule>> const &GetRules() const {
163  return _rules;
164  }
165 
166  /// Return true if \p other has exactly the same set of rules as this. Note
167  /// that this means rules that are functionally equivalent may compare
168  /// inequal. If this is not desired, ensure both sets of rules are reduced
169  /// by Minimize() first.
170  USD_API
171  bool operator==(UsdStageLoadRules const &other) const;
172 
173  /// Return false if \p other has exactly the same set of rules as this. See
174  /// operator==().
175  inline bool operator!=(UsdStageLoadRules const &other) const {
176  return !(*this == other);
177  }
178 
179  /// Swap the contents of these rules with \p other.
180  inline void swap(UsdStageLoadRules &other) {
181  _rules.swap(other._rules);
182  }
183 
184 private:
185  friend USD_API std::ostream &
186  operator<<(std::ostream &, std::pair<SdfPath, Rule> const &);
187 
188  friend USD_API std::ostream &
189  operator<<(std::ostream &, UsdStageLoadRules const &);
190 
191  friend USD_API
192  size_t hash_value(UsdStageLoadRules const &);
193 
194  USD_API
195  std::vector<std::pair<SdfPath, Rule> >::const_iterator
196  _LowerBound(SdfPath const &path) const;
197 
198  USD_API
199  std::vector<std::pair<SdfPath, Rule> >::iterator
200  _LowerBound(SdfPath const &path);
201 
202  std::vector<std::pair<SdfPath, Rule>> _rules;
203 
204 };
205 
206 /// Swap the contents of rules \p l and \p r.
208 {
209  l.swap(r);
210 }
211 
212 /// Stream a text representation of a UsdStageLoadRules object.
213 USD_API
214 std::ostream &operator<<(std::ostream &, UsdStageLoadRules const &);
215 
216 /// Stream a text representation of a pair of SdfPath and
217 /// UsdStageLoadRules::Rule.
218 USD_API
219 std::ostream &operator<<(std::ostream &,
220  std::pair<SdfPath, UsdStageLoadRules::Rule> const &);
221 
222 /// Return the hash code for a UsdStageLoadRules object.
223 USD_API
224 size_t hash_value(UsdStageLoadRules const &);
225 
226 
228 
229 #endif // PXR_USD_USD_STAGE_LOAD_RULES_H
void swap(ArAssetInfo &lhs, ArAssetInfo &rhs)
Definition: assetInfo.h:57
UsdLoadPolicy
Definition: common.h:99
#define USD_API
Definition: api.h:23
hboost::math::policies::policy< hboost::math::policies::domain_error< hboost::math::policies::ignore_error >, hboost::math::policies::pole_error< hboost::math::policies::ignore_error >, hboost::math::policies::overflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::underflow_error< hboost::math::policies::ignore_error >, hboost::math::policies::denorm_error< hboost::math::policies::ignore_error >, hboost::math::policies::rounding_error< hboost::math::policies::ignore_error >, hboost::math::policies::evaluation_error< hboost::math::policies::ignore_error >, hboost::math::policies::indeterminate_result_error< hboost::math::policies::ignore_error > > policy
Definition: SYS_MathCbrt.h:35
USD_API void LoadAndUnload(const SdfPathSet &loadSet, const SdfPathSet &unloadSet, UsdLoadPolicy policy)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
USD_API void Unload(SdfPath const &path)
USD_API std::ostream & operator<<(std::ostream &, UsdStageLoadRules const &)
Stream a text representation of a UsdStageLoadRules object.
USD_API void LoadWithDescendants(SdfPath const &path)
UsdStageLoadRules & operator=(UsdStageLoadRules const &)=default
friend USD_API std::ostream & operator<<(std::ostream &, std::pair< SdfPath, Rule > const &)
USD_API void LoadWithoutDescendants(SdfPath const &path)
friend USD_API size_t hash_value(UsdStageLoadRules const &)
Return the hash code for a UsdStageLoadRules object.
USD_API bool IsLoaded(SdfPath const &path) const
USD_API bool operator==(UsdStageLoadRules const &other) const
USD_API void SetRules(std::vector< std::pair< SdfPath, Rule >> const &rules)
Set literal rules, must be sorted by SdfPath::operator<.
std::vector< std::pair< SdfPath, Rule > > const & GetRules() const
Return all the rules as a vector.
static USD_API UsdStageLoadRules LoadNone()
Return rules that load no payloads.
Definition: path.h:273
UsdStageLoadRules()=default
Construct rules that load all payloads.
USD_API void AddRule(SdfPath const &path, Rule rule)
Add a literal rule. If there's already a rule for path, replace it.
Include payloads on the specified prim and all descendants.
std::set< class SdfPath > SdfPathSet
A set of SdfPaths.
Definition: path.h:192
void SetRules(std::vector< std::pair< SdfPath, Rule >> &&rules)
Set literal rules, must be sorted by SdfPath::operator<.
USD_API bool IsLoadedWithAllDescendants(SdfPath const &path) const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
USD_API void Minimize()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void swap(UsdStageLoadRules &other)
Swap the contents of these rules with other.
Exclude payloads on the specified prim and all descendants.
Include payloads on the specified prim but no descendants.
USD_API bool IsLoadedWithNoDescendants(SdfPath const &path) const
GLboolean r
Definition: glcorearb.h:1222
static UsdStageLoadRules LoadAll()
bool operator!=(UsdStageLoadRules const &other) const
USD_API Rule GetEffectiveRuleForPath(SdfPath const &path) const
USD_API size_t hash_value(UsdStageLoadRules const &)
Return the hash code for a UsdStageLoadRules object.