24 #ifndef INCLUDE_AR_RESOLVER_CONTEXT
25 #error This file should not be included directly. Include resolverContext.h instead
28 #ifndef PXR_USD_AR_RESOLVER_CONTEXT_V1_H
29 #define PXR_USD_AR_RESOLVER_CONTEXT_V1_H
34 #include "pxr/usd/ar/api.h"
39 #include <type_traits>
42 PXR_NAMESPACE_OPEN_SCOPE
52 static const bool value =
false;
56 template <
class Context>
102 template <
class Context,
103 typename std::enable_if<ArIsContextObject<Context>::value>
106 : _context(new _Typed<Context>(context))
119 template <
class Context>
120 const Context*
Get()
const
122 return _context && _context->IsHolding(
typeid(Context)) ?
123 &_GetTyped<Context>(*_context)._context : NULL;
129 return _context ? _context->GetDebugString() : std::string();
136 if (_context && rhs._context) {
137 return (_context->IsHolding(rhs._context->GetTypeid())
138 && _context->Equals(*rhs._context));
140 return (!_context && !rhs._context);
145 return !(*
this == rhs);
150 if (_context && rhs._context) {
151 if (_context->IsHolding(rhs._context->GetTypeid())) {
152 return _context->LessThan(*rhs._context);
154 return (std::string(_context->GetTypeid().name()) <
155 std::string(rhs._context->GetTypeid().name()));
157 else if (_context && !rhs._context) {
160 else if (!_context && rhs._context) {
171 return context._context ? context._context->Hash() : 0;
177 template <
class Context>
struct _Typed;
179 template <
class Context>
180 static const _Typed<Context>& _GetTyped(
const _Untyped& untyped)
182 return static_cast<const _Typed<Context>&
>(untyped);
190 bool IsHolding(
const std::type_info& ti)
const
195 virtual const std::type_info& GetTypeid()
const = 0;
196 virtual bool LessThan(
const _Untyped& rhs)
const = 0;
197 virtual bool Equals(
const _Untyped& rhs)
const = 0;
198 virtual size_t Hash()
const = 0;
202 template <
class Context>
203 struct _Typed :
public _Untyped
205 virtual ~_Typed() { }
207 _Typed(
const Context& context) : _context(context)
211 virtual const std::type_info& GetTypeid()
const
213 return typeid(Context);
216 virtual bool LessThan(
const _Untyped& rhs)
const
218 return _context < _GetTyped<Context>(rhs)._context;
221 virtual bool Equals(
const _Untyped& rhs)
const
223 return _context == _GetTyped<Context>(rhs)._context;
226 virtual size_t Hash()
const
239 std::shared_ptr<_Untyped> _context;
245 std::string Ar_GetDebugString(
const std::type_info&,
void const*);
247 template <
class Context>
250 return Ar_GetDebugString(
typeid(Context),
251 static_cast<void const*>(&context));
254 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.
std::string ArGetDebugString(const Context &context)
Default implementation for providing debug info on the contained context.
ArResolverContext()
Construct an empty asset resolver context.
bool IsEmpty() const
Returns whether this context object is empty.
Metafunction to determine whether the templated object type is a valid context object.
ArResolverContext(const Context &context)
Construct a resolver context using the context object context.
An asset resolver context allows clients to provide additional data to the resolver for use during re...
const Context * Get() const
Return pointer to the context object held in this asset resolver context if the context is holding an...
std::string GetDebugString() const
Returns a debug string representing the contained context.
bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
Safely compare std::type_info structures.