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;
169PXR_NAMESPACE_CLOSE_SCOPE
173using PXR_NS::get_pointer;
177PXR_NAMESPACE_OPEN_SCOPE
183 typedef std::vector<Handle> Vector;
184 typedef std::vector<ConstHandle> ConstVector;
191 typedef std::vector<Handle> Vector;
192 typedef std::vector<ConstHandle> ConstVector;
208SdfCreateNonConstHandle(T
const *p)
210 return SdfCreateHandle(
const_cast<T *
>(p));
213struct Sdf_CastAccess {
214 template<
class DST,
class SRC>
215 static DST CastSpec(
const SRC& spec) {
222 const SdfSpec& srcSpec,
const std::type_info& destType);
225Sdf_CanCastToTypeCheckSchema(
226 const SdfSpec& srcSpec,
const std::type_info& destType);
228template <
class DST,
class SRC>
229struct Sdf_SpecTypesAreDirectlyRelated
230 : std::integral_constant<bool,
231 std::is_base_of<DST, SRC>::value ||
232 std::is_base_of<SRC, DST>::value>
245template <
typename DST,
typename SRC>
250 typedef typename DST::SpecType Spec;
253 if (Sdf_CanCastToType(x.GetSpec(),
typeid(Spec))) {
254 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
260template <
typename DST,
typename SRC>
272template <
typename DST,
typename SRC>
277 typedef typename DST::SpecType Spec;
279 static_assert(Sdf_SpecTypesAreDirectlyRelated<Spec, SRC>::value,
280 "Spec and SRC must be directly related.");
282 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
290 return TfStatic_cast<T>(x);
297template <
typename DST,
typename SRC>
302 typedef typename DST::SpecType Spec;
305 if (Sdf_CanCastToTypeCheckSchema(x.GetSpec(),
typeid(Spec))) {
306 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
315template <
typename DST,
typename SRC>
320 typedef typename DST::SpecType Spec;
322 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
326template <
typename DST_SPEC,
typename SRC_SPEC>
331 return Sdf_CastAccess::CastSpec<DST_SPEC,SRC_SPEC>(x);
335typedef std::vector<TfRefPtr<SdfLayer> > SdfLayerRefPtrVector;
336typedef std::set<SdfHandleTo<SdfLayer>::Handle> SdfLayerHandleSet;
338#define SDF_DECLARE_HANDLES(cls) \
339 typedef SdfHandleTo<class cls>::Handle cls##Handle; \
340 typedef SdfHandleTo<class cls>::ConstHandle cls##ConstHandle; \
341 typedef SdfHandleTo<class cls>::Vector cls##HandleVector; \
342 typedef SdfHandleTo<class cls>::ConstVector cls##ConstHandleVector
344PXR_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.