24#ifndef PXR_USD_SDF_DECLARE_HANDLES_H
25#define PXR_USD_SDF_DECLARE_HANDLES_H
30#include "pxr/usd/sdf/api.h"
34#include "pxr/base/tf/weakPtrFacade.h"
41#include <boost/intrusive_ptr.hpp>
43PXR_NAMESPACE_OPEN_SCOPE
53typedef boost::intrusive_ptr<Sdf_Identity> Sdf_IdentityRefPtr;
67 typedef typename std::remove_const<SpecType>::type NonConstSpecType;
72 explicit SdfHandle(
const Sdf_IdentityRefPtr&
id) : _spec(
id) { }
73 SdfHandle(
const SpecType& spec) : _spec(spec) { }
80 const_cast<NonConstSpecType&
>(_spec) = x._spec;
87 const_cast<NonConstSpecType&
>(_spec) = x._spec;
95 if (ARCH_UNLIKELY(_spec.IsDormant())) {
100 return const_cast<SpecType*
>(&_spec);
103 const SpecType & GetSpec()
const
110 const_cast<SpecType&
>(_spec) = SpecType();
114 typedef SpecType This::*UnspecifiedBoolType;
119 operator UnspecifiedBoolType()
const
121 return _spec.IsDormant() ? 0 : &This::_spec;
127 return _spec.IsDormant();
134 return _spec == other._spec;
140 return !(lhs == rhs);
148 return _spec < other._spec;
176 inline SpecType *get_pointer(
const SdfHandle &x) {
177 return ARCH_UNLIKELY(x._spec.IsDormant()) ?
178 nullptr :
const_cast<SpecType*
>(&x._spec);
183 template <
class U>
friend class SdfHandle;
186PXR_NAMESPACE_CLOSE_SCOPE
190using PXR_NS::get_pointer;
194PXR_NAMESPACE_OPEN_SCOPE
200 typedef std::vector<Handle> Vector;
201 typedef std::vector<ConstHandle> ConstVector;
208 typedef std::vector<Handle> Vector;
209 typedef std::vector<ConstHandle> ConstVector;
225SdfCreateNonConstHandle(T
const *p)
227 return SdfCreateHandle(
const_cast<T *
>(p));
230struct Sdf_CastAccess {
231 template<
class DST,
class SRC>
232 static DST CastSpec(
const SRC& spec) {
239 const SdfSpec& srcSpec,
const std::type_info& destType);
242Sdf_CanCastToTypeCheckSchema(
243 const SdfSpec& srcSpec,
const std::type_info& destType);
245template <
class DST,
class SRC>
246struct Sdf_SpecTypesAreDirectlyRelated
247 : std::integral_constant<bool,
248 std::is_base_of<DST, SRC>::value ||
249 std::is_base_of<SRC, DST>::value>
262template <
typename DST,
typename SRC>
267 typedef typename DST::SpecType Spec;
270 if (Sdf_CanCastToType(x.GetSpec(),
typeid(Spec))) {
271 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
277template <
typename DST,
typename SRC>
289template <
typename DST,
typename SRC>
294 typedef typename DST::SpecType Spec;
296 static_assert(Sdf_SpecTypesAreDirectlyRelated<Spec, SRC>::value,
297 "Spec and SRC must be directly related.");
299 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
307 return TfStatic_cast<T>(x);
314template <
typename DST,
typename SRC>
319 typedef typename DST::SpecType Spec;
322 if (Sdf_CanCastToTypeCheckSchema(x.GetSpec(),
typeid(Spec))) {
323 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
332template <
typename DST,
typename SRC>
337 typedef typename DST::SpecType Spec;
339 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
343template <
typename DST_SPEC,
typename SRC_SPEC>
348 return Sdf_CastAccess::CastSpec<DST_SPEC,SRC_SPEC>(x);
352typedef std::vector<TfRefPtr<SdfLayer> > SdfLayerRefPtrVector;
353typedef std::set<SdfHandleTo<SdfLayer>::Handle> SdfLayerHandleSet;
355#define SDF_DECLARE_HANDLES(cls) \
356 typedef SdfHandleTo<class cls>::Handle cls##Handle; \
357 typedef SdfHandleTo<class cls>::ConstHandle cls##ConstHandle; \
358 typedef SdfHandleTo<class cls>::Vector cls##HandleVector; \
359 typedef SdfHandleTo<class cls>::ConstVector cls##ConstHandleVector
361PXR_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.