24 #ifndef PXR_USD_AR_RESOLVER_CONTEXT_H
25 #define PXR_USD_AR_RESOLVER_CONTEXT_H
35 #include <type_traits>
48 static const bool value =
false;
52 template <
class Context>
98 template <
class Context,
102 : _context(new _Typed<Context>(context))
115 template <
class Context>
116 const Context*
Get()
const
118 return _context && _context->IsHolding(
typeid(Context)) ?
119 &_GetTyped<Context>(*_context)._context : NULL;
125 return _context ? _context->GetDebugString() :
std::string();
132 if (_context && rhs._context) {
133 return (_context->IsHolding(rhs._context->GetTypeid())
134 && _context->Equals(*rhs._context));
136 return (!_context && !rhs._context);
141 return !(*
this == rhs);
146 if (_context && rhs._context) {
147 if (_context->IsHolding(rhs._context->GetTypeid())) {
148 return _context->LessThan(*rhs._context);
150 return (
std::string(_context->GetTypeid().name()) <
153 else if (_context && !rhs._context) {
156 else if (!_context && rhs._context) {
167 return context._context ? context._context->Hash() : 0;
173 template <
class Context>
struct _Typed;
175 template <
class Context>
176 static const _Typed<Context>& _GetTyped(
const _Untyped& untyped)
178 return static_cast<const _Typed<Context>&
>(untyped);
186 bool IsHolding(
const std::type_info& ti)
const
191 virtual const std::type_info& GetTypeid()
const = 0;
192 virtual bool LessThan(
const _Untyped& rhs)
const = 0;
193 virtual bool Equals(
const _Untyped& rhs)
const = 0;
194 virtual size_t Hash()
const = 0;
198 template <
class Context>
199 struct _Typed :
public _Untyped
201 virtual ~_Typed() { }
203 _Typed(
const Context&
context) : _context(context)
207 virtual const std::type_info& GetTypeid()
const
209 return typeid(Context);
212 virtual bool LessThan(
const _Untyped& rhs)
const
214 return _context < _GetTyped<Context>(rhs)._context;
217 virtual bool Equals(
const _Untyped& rhs)
const
219 return _context == _GetTyped<Context>(rhs)._context;
222 virtual size_t Hash()
const
235 std::shared_ptr<_Untyped> _context;
243 template <
class Context>
247 static_cast<void const*>(&context));
252 #endif // PXR_USD_AR_RESOLVER_CONTEXT_H
friend size_t hash_value(const ArResolverContext &context)
Returns hash value for this asset resolver context.
bool operator==(const ArResolverContext &rhs) const
bool operator!=(const ArResolverContext &rhs) const
AR_API std::string Ar_GetDebugString(const std::type_info &, void const *)
ArResolverContext(const Context &context)
size_t OIIO_API Hash(const char *s, size_t len)
const Context * Get() const
bool IsEmpty() const
Returns whether this context object is empty.
std::string ArGetDebugString(const Context &context)
Default implementation for providing debug info on the contained context.
ArResolverContext()
Construct an empty asset resolver context.
std::string GetDebugString() const
Returns a debug string representing the contained context.
GLuint GLuint GLsizei GLenum type
GLsizei const GLchar *const * string
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
PXR_NAMESPACE_OPEN_SCOPE bool TfSafeTypeCompare(const std::type_info &t1, const std::type_info &t2)
GLsizei const GLfloat * value
bool operator<(const ArResolverContext &rhs) const