7#ifndef PXR_USD_AR_RESOLVER_CONTEXT_H
8#define PXR_USD_AR_RESOLVER_CONTEXT_H
13#include "pxr/usd/ar/api.h"
14#include "pxr/usd/ar/ar.h"
19#ifdef PXR_PYTHON_SUPPORT_ENABLED
23#include "pxr/base/tf/pyLock.h"
26#include "pxr/base/tf/pyObjWrapper.h"
35PXR_NAMESPACE_OPEN_SCOPE
45 static const bool value =
false;
49template <
class Context>
56template <
class ...Objects>
struct Ar_AllValidForContext;
58template <
class Object,
class ...Other>
59struct Ar_AllValidForContext<Object, Other...>
61 static const bool value =
62 (std::is_same<Object, ArResolverContext>::value ||
64 Ar_AllValidForContext<Other...>::value;
68struct Ar_AllValidForContext<>
70 static const bool value =
true;
132 typename std::enable_if<Ar_AllValidForContext<Objects...>::value>::type*
136 _AddObjects(objs...);
154 return _contexts.empty();
160 template <
class ContextObj>
161 const ContextObj*
Get()
const
163 for (
const auto& context : _contexts) {
164 if (context->IsHolding(
typeid(ContextObj))) {
165 return &_GetTyped<ContextObj>(*context)._context;
182 return !(*
this == rhs);
193 return TfHash()(context._contexts);
199 template <
class Context>
struct _Typed;
206 template <
class Object,
class ...Other>
207 void _AddObjects(
const Object& obj,
const Other&... other)
210 _AddObjects(other...);
216 template <
class Object>
217 void _Add(
const Object& obj)
219 _Add(std::shared_ptr<_Untyped>(
new _Typed<Object>(obj)));
223 void _Add(std::shared_ptr<_Untyped>&& context);
225 template <
class Context>
226 static const _Typed<Context>& _GetTyped(
const _Untyped& untyped)
228 return static_cast<const _Typed<Context>&
>(untyped);
236 bool IsHolding(
const std::type_info& ti)
const
241 virtual _Untyped* Clone()
const = 0;
242 virtual const std::type_info& GetTypeid()
const = 0;
243 virtual bool LessThan(
const _Untyped& rhs)
const = 0;
244 virtual bool Equals(
const _Untyped& rhs)
const = 0;
245 virtual size_t Hash()
const = 0;
246 virtual std::string GetDebugString()
const = 0;
250 template <
class Context>
251 struct _Typed :
public _Untyped
253 virtual ~_Typed() { }
255 _Typed(
const Context& context) : _context(context)
259 virtual _Untyped* Clone()
const
261 return new _Typed<Context>(_context);
264 virtual const std::type_info& GetTypeid()
const
266 return typeid(Context);
269 virtual bool LessThan(
const _Untyped& rhs)
const
271 return _context < _GetTyped<Context>(rhs)._context;
274 virtual bool Equals(
const _Untyped& rhs)
const
276 return _context == _GetTyped<Context>(rhs)._context;
279 virtual size_t Hash()
const
284 virtual std::string GetDebugString()
const
291 #ifdef PXR_PYTHON_SUPPORT_ENABLED
293 return pxr_boost::python::object(_context);
302 template <
class HashState>
303 friend void TfHashAppend(
304 HashState& h,
const std::shared_ptr<_Untyped>& context)
306 h.Append(context->Hash());
309#ifdef PXR_PYTHON_SUPPORT_ENABLED
310 friend class Ar_ResolverContextPythonAccess;
313 std::vector<std::shared_ptr<_Untyped>> _contexts;
319std::string Ar_GetDebugString(
const std::type_info&,
void const*);
321template <
class Context>
324 return Ar_GetDebugString(
typeid(Context),
325 static_cast<void const*
>(&context));
328PXR_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.