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" 39 #include <type_traits> 41 #include <boost/intrusive_ptr.hpp> 42 #include <boost/operators.hpp> 44 PXR_NAMESPACE_OPEN_SCOPE
54 typedef boost::intrusive_ptr<Sdf_Identity> Sdf_IdentityRefPtr;
63 class SdfHandle :
private boost::totally_ordered<SdfHandle<T> > {
68 typedef typename std::remove_const<SpecType>::type NonConstSpecType;
73 explicit SdfHandle(
const Sdf_IdentityRefPtr&
id) : _spec(
id) { }
74 SdfHandle(
const SpecType& spec) : _spec(spec) { }
81 const_cast<NonConstSpecType&>(_spec) = x._spec;
88 const_cast<NonConstSpecType&>(_spec) = x._spec;
96 if (ARCH_UNLIKELY(_spec.IsDormant())) {
101 return const_cast<SpecType*>(&_spec);
104 const SpecType & GetSpec()
const 111 const_cast<SpecType&>(_spec) = SpecType();
114 #if !defined(doxygen) 115 typedef SpecType This::*UnspecifiedBoolType;
120 operator UnspecifiedBoolType()
const 122 return _spec.IsDormant() ? 0 : &This::_spec;
128 return _spec.IsDormant();
135 return _spec == other._spec;
143 return _spec < other._spec;
153 inline SpecType *get_pointer(
const SdfHandle &x) {
154 return ARCH_UNLIKELY(x._spec.IsDormant()) ?
155 nullptr : const_cast<SpecType*>(&x._spec);
160 template <
class U>
friend class SdfHandle;
163 PXR_NAMESPACE_CLOSE_SCOPE
167 using PXR_NS::get_pointer;
171 PXR_NAMESPACE_OPEN_SCOPE
177 typedef std::vector<Handle> Vector;
178 typedef std::vector<ConstHandle> ConstVector;
185 typedef std::vector<Handle> Vector;
186 typedef std::vector<ConstHandle> ConstVector;
189 template <
typename T>
191 SdfCreateHandle(T *p)
197 SDF_API SdfHandleTo<SdfLayer>::Handle
200 template <
typename T>
202 SdfCreateNonConstHandle(T
const *p)
204 return SdfCreateHandle(const_cast<T *>(p));
207 struct Sdf_CastAccess {
208 template<
class DST,
class SRC>
209 static DST CastSpec(
const SRC& spec) {
216 const SdfSpec& srcSpec,
const std::type_info& destType);
219 Sdf_CanCastToTypeCheckSchema(
220 const SdfSpec& srcSpec,
const std::type_info& destType);
222 template <
class DST,
class SRC>
223 struct Sdf_SpecTypesAreDirectlyRelated
224 : std::integral_constant<bool,
225 std::is_base_of<DST, SRC>::value ||
226 std::is_base_of<SRC, DST>::value>
239 template <
typename DST,
typename SRC>
244 typedef typename DST::SpecType Spec;
247 if (Sdf_CanCastToType(x.GetSpec(),
typeid(Spec))) {
248 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
254 template <
typename DST,
typename SRC>
266 template <
typename DST,
typename SRC>
271 typedef typename DST::SpecType Spec;
273 static_assert(Sdf_SpecTypesAreDirectlyRelated<Spec, SRC>::value,
274 "Spec and SRC must be directly related.");
276 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
279 template <
typename T>
284 return TfStatic_cast<T>(x);
291 template <
typename DST,
typename SRC>
296 typedef typename DST::SpecType Spec;
299 if (Sdf_CanCastToTypeCheckSchema(x.GetSpec(),
typeid(Spec))) {
300 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
309 template <
typename DST,
typename SRC>
314 typedef typename DST::SpecType Spec;
316 return Handle(Sdf_CastAccess::CastSpec<Spec,SRC>(x.GetSpec()));
320 template <
typename DST_SPEC,
typename SRC_SPEC>
325 return Sdf_CastAccess::CastSpec<DST_SPEC,SRC_SPEC>(x);
329 typedef std::vector<TfRefPtr<SdfLayer> > SdfLayerRefPtrVector;
330 typedef std::set<SdfHandleTo<SdfLayer>::Handle> SdfLayerHandleSet;
332 #define SDF_DECLARE_HANDLES(cls) \ 333 typedef SdfHandleTo<class cls>::Handle cls##Handle; \ 334 typedef SdfHandleTo<class cls>::ConstHandle cls##ConstHandle; \ 335 typedef SdfHandleTo<class cls>::Vector cls##HandleVector; \ 336 typedef SdfHandleTo<class cls>::ConstVector cls##ConstHandleVector 338 PXR_NAMESPACE_CLOSE_SCOPE
340 #endif // PXR_USD_SDF_DECLARE_HANDLES_H A scene description container that can combine with other such containers to form simple component as...
bool operator==(const SdfHandle< U > &other) const
Compares handles for equality.
TO TfSafeDynamic_cast(FROM *ptr)
Safely perform a dynamic cast.
Standard pointer typedefs.
SdfHandle< typename DST::SpecType > TfStatic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
ARCH_API std::string ArchGetDemangled(const std::string &typeName)
Return demangled RTTI-generated type name.
Base class for all Sdf spec classes.
bool operator!() const
Returns false in a boolean context if the object is valid, true otherwise.
Low-level utilities for informing users of various internal and external diagnostic conditions.
Demangle C++ typenames generated by the typeid() facility.
SdfHandle is a smart ptr that calls IsDormant() on the pointed-to object as an extra expiration check...
Pointer storage with deletion detection.
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>.
#define TF_FATAL_ERROR(fmt, args)
Issue a fatal error and end the program.
SpecType * operator->() const
Dereference.
Reference-counted smart pointer utility class.
friend size_t hash_value(const This &x)
Hash.
SdfHandle< typename DST::SpecType > SdfSpecStatic_cast(const SdfHandle< SRC > &x)
Convert SdfHandle<SRC> x to an SdfHandle<DST>.
bool operator<(const SdfHandle< U > &other) const
Arranges handles in an arbitrary strict weak ordering.