7#ifndef PXR_USD_SDF_DECLARE_HANDLES_H
8#define PXR_USD_SDF_DECLARE_HANDLES_H
13#include "pxr/usd/sdf/api.h"
16#include "pxr/base/tf/delegatedCountPtr.h"
18#include "pxr/base/tf/weakPtrFacade.h"
26PXR_NAMESPACE_OPEN_SCOPE
50 typedef typename std::remove_const<SpecType>::type NonConstSpecType;
56 SdfHandle(
const SpecType& spec) : _spec(spec) { }
63 const_cast<NonConstSpecType&
>(_spec) = x._spec;
70 const_cast<NonConstSpecType&
>(_spec) = x._spec;
78 if (ARCH_UNLIKELY(_spec.IsDormant())) {
83 return const_cast<SpecType*
>(&_spec);
86 const SpecType & GetSpec()
const
93 const_cast<SpecType&
>(_spec) = SpecType();
97 typedef SpecType This::*UnspecifiedBoolType;
102 operator UnspecifiedBoolType()
const
104 return _spec.IsDormant() ? 0 : &This::_spec;
110 return _spec.IsDormant();
117 return _spec == other._spec;
123 return !(lhs == rhs);
131 return _spec < other._spec;
159 inline SpecType *get_pointer(
const SdfHandle &x) {
160 return ARCH_UNLIKELY(x._spec.IsDormant()) ?
161 nullptr :
const_cast<SpecType*
>(&x._spec);
166 template <
class U>
friend class SdfHandle;
173 typedef std::vector<Handle> Vector;
174 typedef std::vector<ConstHandle> ConstVector;
181 typedef std::vector<Handle> Vector;
182 typedef std::vector<ConstHandle> ConstVector;
198SdfCreateNonConstHandle(T
const *p)
200 return SdfCreateHandle(
const_cast<T *
>(p));
203struct Sdf_CastAccess {
204 template<
class DST,
class SRC>
205 static DST CastSpec(
const SRC& spec) {
212 const SdfSpec& srcSpec,
const std::type_info& destType);
215Sdf_CanCastToTypeCheckSchema(
216 const SdfSpec& srcSpec,
const std::type_info& destType);
218template <
class DST,
class SRC>
219struct Sdf_SpecTypesAreDirectlyRelated
220 : std::integral_constant<bool,
221 std::is_base_of<DST, SRC>::value ||
222 std::is_base_of<SRC, DST>::value>
235template <
typename DST,
typename SRC>
240 typedef typename DST::SpecType Spec;
243 if (Sdf_CanCastToType(x.GetSpec(),
typeid(Spec))) {
244 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
250template <
typename DST,
typename SRC>
262template <
typename DST,
typename SRC>
267 typedef typename DST::SpecType Spec;
269 static_assert(Sdf_SpecTypesAreDirectlyRelated<Spec, SRC>::value,
270 "Spec and SRC must be directly related.");
272 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
280 return TfStatic_cast<T>(x);
287template <
typename DST,
typename SRC>
292 typedef typename DST::SpecType Spec;
295 if (Sdf_CanCastToTypeCheckSchema(x.GetSpec(),
typeid(Spec))) {
296 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
305template <
typename DST,
typename SRC>
310 typedef typename DST::SpecType Spec;
312 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
316template <
typename DST_SPEC,
typename SRC_SPEC>
321 return Sdf_CastAccess::CastSpec<DST_SPEC,SRC_SPEC>(x);
325typedef std::vector<TfRefPtr<SdfLayer> > SdfLayerRefPtrVector;
326typedef std::set<SdfHandleTo<SdfLayer>::Handle> SdfLayerHandleSet;
328#define SDF_DECLARE_HANDLES(cls) \
329 typedef SdfHandleTo<class cls>::Handle cls##Handle; \
330 typedef SdfHandleTo<class cls>::ConstHandle cls##ConstHandle; \
331 typedef SdfHandleTo<class cls>::Vector cls##HandleVector; \
332 typedef SdfHandleTo<class cls>::ConstVector cls##ConstHandleVector
334PXR_NAMESPACE_CLOSE_SCOPE
Low-level utilities for informing users of various internal and external diagnostic conditions.
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
friend bool operator>=(const SdfHandle &lhs, const SdfHandle &rhs)
bool operator<(const SdfHandle< U > &other) const
Arranges handles in an arbitrary strict weak ordering.
bool operator!() const
Returns false in a boolean context if the object is valid, true otherwise.
friend size_t hash_value(const This &x)
Hash.
SpecType * operator->() const
Dereference.
friend bool operator<=(const SdfHandle &lhs, const SdfHandle &rhs)
friend bool operator!=(const SdfHandle &lhs, const SdfHandle &rhs)
friend bool operator>(const SdfHandle &lhs, const SdfHandle &rhs)
bool operator==(const SdfHandle< U > &other) const
Compares handles for equality.
A scene description container that can combine with other such containers to form simple component as...
Base class for all Sdf spec classes.
Reference-counted smart pointer utility class.
Pointer storage with deletion detection.
SdfHandle< typename DST::SpecType > TfStatic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
SdfHandle< typename DST::SpecType > TfDynamic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
SdfHandle< typename DST::SpecType > SdfSpecDynamic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
SdfHandle< typename DST::SpecType > SdfSpecStatic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
Standard pointer typedefs.
Demangle C++ typenames generated by the typeid() facility.
std::string ArchGetDemangled()
Return demangled RTTI generated-type name.
#define TF_FATAL_ERROR(fmt, args)
Issue a fatal error and end the program.
TO TfSafeDynamic_cast(FROM *ptr)
Safely perform a dynamic cast.