7#ifndef PXR_USD_USD_PRIM_FLAGS_H
8#define PXR_USD_USD_PRIM_FLAGS_H
59#include "pxr/usd/usd/api.h"
66PXR_NAMESPACE_OPEN_SCOPE
77 Usd_PrimComponentFlag,
80 Usd_PrimHasDefiningSpecifierFlag,
84 Usd_PrimHasPayloadFlag,
87 Usd_PrimPrototypeFlag,
88 Usd_PrimInstanceProxyFlag,
89 Usd_PrimPseudoRootFlag,
94typedef std::bitset<Usd_PrimNumFlags> Usd_PrimFlagBits;
100 Usd_Term(Usd_PrimFlags flag) : flag(flag), negated(false) {}
101 Usd_Term(Usd_PrimFlags flag,
bool negated) : flag(flag), negated(negated) {}
102 Usd_Term operator!()
const {
return Usd_Term(flag, !negated); }
103 bool operator==(Usd_Term other)
const {
104 return flag == other.flag && negated == other.negated;
106 bool operator!=(Usd_Term other)
const {
107 return !(*
this == other);
114operator!(Usd_PrimFlags flag) {
115 return Usd_Term(flag,
true);
119class Usd_PrimFlagsPredicate
123 typedef bool result_type;
126 Usd_PrimFlagsPredicate() : _negate(false) {}
128 Usd_PrimFlagsPredicate(Usd_PrimFlags flag)
131 _values[flag] =
true;
135 Usd_PrimFlagsPredicate(Usd_Term term)
137 _mask[term.flag] = 1;
138 _values[term.flag] = !term.negated;
143 static Usd_PrimFlagsPredicate Tautology() {
144 return Usd_PrimFlagsPredicate();
149 static Usd_PrimFlagsPredicate Contradiction() {
150 return Usd_PrimFlagsPredicate()._Negate();
156 Usd_PrimFlagsPredicate &TraverseInstanceProxies(
bool traverse) {
158 _mask[Usd_PrimInstanceProxyFlag] = 0;
159 _values[Usd_PrimInstanceProxyFlag] = 1;
162 _mask[Usd_PrimInstanceProxyFlag] = 1;
163 _values[Usd_PrimInstanceProxyFlag] = 0;
170 bool IncludeInstanceProxiesInTraversal()
const {
171 return !_mask[Usd_PrimInstanceProxyFlag] &&
172 _values[Usd_PrimInstanceProxyFlag];
177 bool operator()(
const class UsdPrim &prim)
const;
182 bool _IsTautology()
const {
return *
this == Tautology(); }
185 void _MakeTautology() { *
this = Tautology(); }
188 bool _IsContradiction()
const {
return *
this == Contradiction(); }
191 void _MakeContradiction() { *
this = Contradiction(); }
194 Usd_PrimFlagsPredicate &_Negate() {
200 Usd_PrimFlagsPredicate _GetNegated()
const {
201 return Usd_PrimFlagsPredicate(*this)._Negate();
205 Usd_PrimFlagBits _mask;
208 Usd_PrimFlagBits _values;
213 template <
class PrimPtr>
214 bool _Eval(
const PrimPtr &prim,
bool isInstanceProxy)
const {
217 const Usd_PrimFlagBits primFlags = Usd_PrimFlagBits(prim->_GetFlags())
218 .set(Usd_PrimInstanceProxyFlag, isInstanceProxy);
222 return ((primFlags & _mask) == (_values & _mask)) ^ _negate;
227 template <
class PrimPtr>
229 Usd_EvalPredicate(
const Usd_PrimFlagsPredicate &pred,
const PrimPtr &prim,
230 bool isInstanceProxy) {
231 return pred._Eval(prim, isInstanceProxy);
237 template <
class PrimPtr>
239 Usd_EvalPredicate(
const Usd_PrimFlagsPredicate &pred,
const PrimPtr &prim,
240 const SdfPath &proxyPrimPath) {
241 return pred._Eval(prim, Usd_IsInstanceProxy(prim, proxyPrimPath));
246 operator==(
const Usd_PrimFlagsPredicate &lhs,
247 const Usd_PrimFlagsPredicate &rhs) {
248 return lhs._mask == rhs._mask &&
249 lhs._values == rhs._values &&
250 lhs._negate == rhs._negate;
254 operator!=(
const Usd_PrimFlagsPredicate &lhs,
255 const Usd_PrimFlagsPredicate &rhs) {
256 return !(lhs == rhs);
260 friend size_t hash_value(
const Usd_PrimFlagsPredicate &p) {
262 p._mask.to_ulong(), p._values.to_ulong(), p._negate
282class Usd_PrimFlagsConjunction :
public Usd_PrimFlagsPredicate {
285 Usd_PrimFlagsConjunction() {};
288 explicit Usd_PrimFlagsConjunction(Usd_Term term) {
293 Usd_PrimFlagsConjunction &operator&=(Usd_Term term) {
295 if (ARCH_UNLIKELY(_IsContradiction()))
299 if (!_mask[term.flag]) {
300 _mask[term.flag] = 1;
301 _values[term.flag] = !term.negated;
302 }
else if (_values[term.flag] != !term.negated) {
306 _MakeContradiction();
329 class Usd_PrimFlagsDisjunction operator!() const;
334 friend class Usd_PrimFlagsDisjunction;
335 Usd_PrimFlagsConjunction(
const Usd_PrimFlagsPredicate &base) :
336 Usd_PrimFlagsPredicate(base) {}
339 friend Usd_PrimFlagsConjunction
340 operator&&(Usd_Term lhs, Usd_Term rhs);
343 friend Usd_PrimFlagsConjunction
344 operator&&(
const Usd_PrimFlagsConjunction &conjunction, Usd_Term rhs);
347 friend Usd_PrimFlagsConjunction
348 operator&&(Usd_Term lhs,
const Usd_PrimFlagsConjunction &conjunction);
351inline Usd_PrimFlagsConjunction
352operator&&(Usd_Term lhs, Usd_Term rhs) {
355 Usd_PrimFlagsConjunction tmp;
356 return (tmp && lhs) && rhs;
359inline Usd_PrimFlagsConjunction
360operator&&(
const Usd_PrimFlagsConjunction &conjunction, Usd_Term rhs) {
361 return Usd_PrimFlagsConjunction(conjunction) &= rhs;
364inline Usd_PrimFlagsConjunction
365operator&&(Usd_Term lhs,
const Usd_PrimFlagsConjunction &conjunction) {
366 return Usd_PrimFlagsConjunction(conjunction) &= lhs;
369inline Usd_PrimFlagsConjunction
370operator&&(Usd_PrimFlags lhs, Usd_PrimFlags rhs) {
371 return Usd_Term(lhs) && Usd_Term(rhs);
385class Usd_PrimFlagsDisjunction :
public Usd_PrimFlagsPredicate {
388 Usd_PrimFlagsDisjunction() { _Negate(); };
391 explicit Usd_PrimFlagsDisjunction(Usd_Term term) {
397 Usd_PrimFlagsDisjunction &operator|=(Usd_Term term) {
399 if (ARCH_UNLIKELY(_IsTautology()))
403 if (!_mask[term.flag]) {
404 _mask[term.flag] = 1;
405 _values[term.flag] = term.negated;
406 }
else if (_values[term.flag] != term.negated) {
433 class Usd_PrimFlagsConjunction operator!() const;
438 friend class Usd_PrimFlagsConjunction;
439 Usd_PrimFlagsDisjunction(
const Usd_PrimFlagsPredicate &base) :
440 Usd_PrimFlagsPredicate(base) {}
443 friend Usd_PrimFlagsDisjunction operator||(Usd_Term lhs, Usd_Term rhs);
446 friend Usd_PrimFlagsDisjunction
447 operator||(
const Usd_PrimFlagsDisjunction &disjunction, Usd_Term rhs);
450 friend Usd_PrimFlagsDisjunction
451 operator||(Usd_Term lhs,
const Usd_PrimFlagsDisjunction &disjunction);
454inline Usd_PrimFlagsDisjunction
455operator||(Usd_Term lhs, Usd_Term rhs) {
456 return (Usd_PrimFlagsDisjunction() || lhs) || rhs;
459inline Usd_PrimFlagsDisjunction
460operator||(
const Usd_PrimFlagsDisjunction &disjunction, Usd_Term rhs) {
461 return Usd_PrimFlagsDisjunction(disjunction) |= rhs;
464inline Usd_PrimFlagsDisjunction
465operator||(Usd_Term lhs,
const Usd_PrimFlagsDisjunction &disjunction) {
466 return Usd_PrimFlagsDisjunction(disjunction) |= lhs;
469inline Usd_PrimFlagsDisjunction
470operator||(Usd_PrimFlags lhs, Usd_PrimFlags rhs) {
471 return Usd_Term(lhs) || Usd_Term(rhs);
522 = Usd_PrimHasDefiningSpecifierFlag;
559inline Usd_PrimFlagsPredicate
562 return predicate.TraverseInstanceProxies(
true);
569inline Usd_PrimFlagsPredicate
575PXR_NAMESPACE_CLOSE_SCOPE
A path value used to locate objects in layers or scenegraphs.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
size_t hash_value(const half h)
Overload hash_value for half.
unspecified UsdPrimIsGroup
Tests UsdPrim::IsGroup()
unspecified UsdPrimIsActive
Tests UsdPrim::IsActive()
unspecified UsdPrimIsDefined
Tests UsdPrim::IsDefined()
unspecified UsdPrimIsInstance
Tests UsdPrim::IsInstance()
unspecified UsdPrimIsLoaded
Tests UsdPrim::IsLoaded()
unspecified UsdPrimDefaultPredicate
The default predicate used for prim traversals in methods like UsdPrim::GetChildren,...
unspecified UsdPrimIsAbstract
Tests UsdPrim::IsAbstract()
unspecified UsdPrimIsModel
Tests UsdPrim::IsModel()
unspecified UsdPrimHasDefiningSpecifier
Tests UsdPrim::HasDefiningSpecifier()
Usd_PrimFlagsPredicate UsdTraverseInstanceProxies()
This is an overloaded member function, provided for convenience. It differs from the above function o...
unspecified UsdPrimAllPrimsPredicate
Predicate that includes all prims.