24 #ifndef PXR_USD_AR_RESOLVER_CONTEXT_H 25 #define PXR_USD_AR_RESOLVER_CONTEXT_H 30 #include "pxr/usd/ar/api.h" 31 #include "pxr/usd/ar/ar.h" 36 #ifdef PXR_PYTHON_SUPPORT_ENABLED 40 #include "pxr/base/tf/pyLock.h" 43 #include "pxr/base/tf/pyObjWrapper.h" 48 #include <type_traits> 52 PXR_NAMESPACE_OPEN_SCOPE
62 static const bool value =
false;
66 template <
class Context>
73 template <
class ...Objects>
struct Ar_AllValidForContext;
75 template <
class Object,
class ...Other>
76 struct Ar_AllValidForContext<Object, Other...>
78 static const bool value =
79 (std::is_same<Object, ArResolverContext>::value ||
81 Ar_AllValidForContext<Other...>::value;
85 struct Ar_AllValidForContext<>
87 static const bool value =
true;
149 typename std::enable_if<Ar_AllValidForContext<Objects...>::value>::type*
153 _AddObjects(objs...);
171 return _contexts.empty();
177 template <
class ContextObj>
178 const ContextObj*
Get()
const 180 for (
const auto& context : _contexts) {
181 if (context->IsHolding(
typeid(ContextObj))) {
182 return &_GetTyped<ContextObj>(*context)._context;
199 return !(*
this == rhs);
210 return TfHash()(context._contexts);
216 template <
class Context>
struct _Typed;
223 template <
class Object,
class ...Other>
224 void _AddObjects(
const Object& obj,
const Other&... other)
227 _AddObjects(other...);
233 template <
class Object>
234 void _Add(
const Object& obj)
236 _Add(std::shared_ptr<_Untyped>(
new _Typed<Object>(obj)));
240 void _Add(std::shared_ptr<_Untyped>&& context);
242 template <
class Context>
243 static const _Typed<Context>& _GetTyped(
const _Untyped& untyped)
245 return static_cast<const _Typed<Context>&
>(untyped);
253 bool IsHolding(
const std::type_info& ti)
const 258 virtual _Untyped* Clone()
const = 0;
259 virtual const std::type_info& GetTypeid()
const = 0;
260 virtual bool LessThan(
const _Untyped& rhs)
const = 0;
261 virtual bool Equals(
const _Untyped& rhs)
const = 0;
262 virtual size_t Hash()
const = 0;
267 template <
class Context>
268 struct _Typed :
public _Untyped
270 virtual ~_Typed() { }
272 _Typed(
const Context& context) : _context(context)
276 virtual _Untyped* Clone()
const 278 return new _Typed<Context>(_context);
281 virtual const std::type_info& GetTypeid()
const 283 return typeid(Context);
286 virtual bool LessThan(
const _Untyped& rhs)
const 288 return _context < _GetTyped<Context>(rhs)._context;
291 virtual bool Equals(
const _Untyped& rhs)
const 293 return _context == _GetTyped<Context>(rhs)._context;
296 virtual size_t Hash()
const 308 #ifdef PXR_PYTHON_SUPPORT_ENABLED 310 return boost::python::object(_context);
319 template <
class HashState>
320 friend void TfHashAppend(
321 HashState& h,
const std::shared_ptr<_Untyped>& context)
323 h.Append(context->Hash());
326 #ifdef PXR_PYTHON_SUPPORT_ENABLED 327 friend class Ar_ResolverContextPythonAccess;
330 std::vector<std::shared_ptr<_Untyped>> _contexts;
336 std::string Ar_GetDebugString(
const std::type_info&,
void const*);
338 template <
class Context>
341 return Ar_GetDebugString(
typeid(Context),
342 static_cast<void const*>(&context));
345 PXR_NAMESPACE_CLOSE_SCOPE
friend size_t hash_value(const ArResolverContext &context)
Returns hash value for this asset resolver context.
Safely compare C++ RTTI type structures.
AR_API std::string GetDebugString() const
Returns a debug string representing the contained context objects.
A user-extensible hashing mechanism for use with runtime hash tables.
Convenience class for accessing the Python Global Interpreter Lock.
ArResolverContext()
Construct an empty asset resolver context.
std::string ArGetDebugString(const Context &context)
Default implementation for providing debug info on the contained context.
bool IsEmpty() const
Returns whether this resolver context is empty.
Boost Python object wrapper.
Metafunction to determine whether the templated object type is a valid context object.
An asset resolver context allows clients to provide additional data to the resolver for use during re...
ArResolverContext(const Objects &... objs)
Construct a resolver context using the given objects objs.
const ContextObj * Get() const
Returns pointer to the context object of the given type held in this resolver context.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.