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"
52PXR_NAMESPACE_OPEN_SCOPE
62 static const bool value =
false;
66template <
class Context>
73template <
class ...Objects>
struct Ar_AllValidForContext;
75template <
class Object,
class ...Other>
76struct Ar_AllValidForContext<Object, Other...>
78 static const bool value =
79 (std::is_same<Object, ArResolverContext>::value ||
81 Ar_AllValidForContext<Other...>::value;
85struct 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;
263 virtual std::string GetDebugString()
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
301 virtual std::string GetDebugString()
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;
336std::string Ar_GetDebugString(
const std::type_info&,
void const*);
338template <
class Context>
341 return Ar_GetDebugString(
typeid(Context),
342 static_cast<void const*
>(&context));
345PXR_NAMESPACE_CLOSE_SCOPE
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.
AR_API std::string GetDebugString() const
Returns a debug string representing the contained context objects.
AR_API ArResolverContext(const std::vector< ArResolverContext > &ctxs)
Construct a resolver context using the ArResolverContexts in ctxs.
bool IsEmpty() const
Returns whether this resolver context is empty.
ArResolverContext()
Construct an empty asset resolver context.
friend size_t hash_value(const ArResolverContext &context)
Returns hash value for this asset resolver context.
A user-extensible hashing mechanism for use with runtime hash tables.
Convenience class for accessing the Python Global Interpreter Lock.
Boost Python object wrapper.
std::string ArGetDebugString(const Context &context)
Default implementation for providing debug info on the contained context.
Safely compare C++ RTTI type structures.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.
Metafunction to determine whether the templated object type is a valid context object.